org.apache.sling.engine.impl.request
Class SlingRequestProgressTracker

java.lang.Object
  extended by org.apache.sling.engine.impl.request.SlingRequestProgressTracker
All Implemented Interfaces:
RequestProgressTracker

public class SlingRequestProgressTracker
extends Object
implements RequestProgressTracker

The SlingRequestProgressTracker class provides the functionality to track the progress of request processing. Instances of this class are provided through the SlingHttpServletRequest.getRequestProgressTracker() method.

The following functionality is provided:

  1. Track the progress of request processing through the log(String) and log(String, Object...) methods.
  2. Ability to measure and track processing times of parts of request processing through the startTimer(String) and logTimer(String) methods.
  3. Dumping the recording messages through the dump(PrintWriter) method.
  4. Resetting the tracker through the reset() method.

Tracking Request Processing

As the request being processed, certain steps may be tracked by calling either of the log methods. A tracking entry consists of a time stamp managed by this class, and a tracking message noting the actual step being tracked.

Timing Processing Steps

Certain steps during request processing may need to be timed in that the time required for processing should be recorded. Instances of this class maintain a map of named timers. Each timer is started (initialized or reset) by calling the startTimer(String) method. This method just records the starting time of the named timer.

To record the number of milliseconds ellapsed since a timer has been started, the logTimer(String) method may be called. This method logs the tracking entry with message consisting of the name of the timer and the number of milliseconds ellapsed since the timer was last started. The logTimer(String) method may be called multiple times to record several timed steps.

Additional information can be logged using the logTimer(String, String, Object...) method.

Calling the startTimer(String) method with the name of timer which already exists, resets the start time of the named timer to the current system time.

Dumping Tracking Entries

The dump(PrintWriter) methods writes all tracking entries to the given PrintWriter. Each entry is written on a single line consisting of the following fields:

  1. The number of milliseconds since the last reset() (or creation) of this timer.
  2. The absolute time of the timer in parenthesis.
  3. The entry message


Constructor Summary
SlingRequestProgressTracker()
          Creates a new request progress tracker.
 
Method Summary
 void done()
          Call this when done processing the request - all calls except the first one are ignored
 void dump(PrintWriter writer)
          Dumps the process timer entries to the given writer, one entry per line.
 Iterator<String> getMessages()
          Returns an Iterator of tracking entries.
 void log(String message)
          Creates an entry with the given message.
 void log(String format, Object... args)
          Creates an entry with the given entry tag and message
 void logTimer(String name)
          Log a timer entry, including start, end and elapsed time.
 void logTimer(String name, String format, Object... args)
          Log a timer entry, including start, end and elapsed time.
 void reset()
          Resets this timer by removing all current entries and timers and adds an initial timer entry
 void startTimer(String name)
          Starts a named timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlingRequestProgressTracker

public SlingRequestProgressTracker()
Creates a new request progress tracker.

Method Detail

reset

public void reset()
Resets this timer by removing all current entries and timers and adds an initial timer entry


getMessages

public Iterator<String> getMessages()
Description copied from interface: RequestProgressTracker
Returns an Iterator of tracking entries. If there are no messages null is returned.

Specified by:
getMessages in interface RequestProgressTracker
See Also:
RequestProgressTracker.getMessages()

dump

public void dump(PrintWriter writer)
Dumps the process timer entries to the given writer, one entry per line. See the class comments for the rough format of each message line.

Specified by:
dump in interface RequestProgressTracker

log

public void log(String message)
Creates an entry with the given message.

Specified by:
log in interface RequestProgressTracker

log

public void log(String format,
                Object... args)
Creates an entry with the given entry tag and message

Specified by:
log in interface RequestProgressTracker

startTimer

public void startTimer(String name)
Starts a named timer. If a timer of the same name already exists, it is reset to the current time.

Specified by:
startTimer in interface RequestProgressTracker

logTimer

public void logTimer(String name)
Log a timer entry, including start, end and elapsed time.

Specified by:
logTimer in interface RequestProgressTracker

logTimer

public void logTimer(String name,
                     String format,
                     Object... args)
Log a timer entry, including start, end and elapsed time.

Specified by:
logTimer in interface RequestProgressTracker

done

public void done()
Description copied from interface: RequestProgressTracker
Call this when done processing the request - all calls except the first one are ignored

Specified by:
done in interface RequestProgressTracker


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.