Class SlingRequestProgressTracker
- java.lang.Object
-
- org.apache.sling.engine.impl.request.SlingRequestProgressTracker
-
- All Implemented Interfaces:
org.apache.sling.api.request.RequestProgressTracker
public class SlingRequestProgressTracker extends Object implements org.apache.sling.api.request.RequestProgressTracker
TheSlingRequestProgressTrackerclass provides the functionality to track the progress of request processing. Instances of this class are provided through theSlingHttpServletRequest.getRequestProgressTracker()method.The following functionality is provided:
- Track the progress of request processing through the
log(String)andlog(String, Object...)methods. - Ability to measure and track processing times of parts of request
processing through the
startTimer(String)andlogTimer(String)methods. - Dumping the recording messages through the
dump(PrintWriter)method. - 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
logmethods. 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 thestartTimer(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 laststarted. ThelogTimer(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 givenPrintWriter. Each entry is written on a single line consisting of the following fields:- The number of milliseconds since the last
reset()(or creation) of this timer. - The absolute time of the timer in parenthesis.
- The entry message
-
-
Constructor Summary
Constructors Constructor Description SlingRequestProgressTracker()Creates a new request progress tracker.SlingRequestProgressTracker(javax.servlet.http.HttpServletRequest request)Creates a new request progress tracker and logs initial messages about the supplied request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddone()voiddump(PrintWriter writer)Dumps the process timer entries to the given writer, one entry per line.longgetDuration()Iterator<String>getMessages()voidlog(String message)Creates an entry with the given message.voidlog(String format, Object... args)Creates an entry with the given entry tag and messagevoidlogTimer(String name)Log a timer entry, including start, end and elapsed time.voidlogTimer(String name, String format, Object... args)Log a timer entry, including start, end and elapsed time.voidreset()Resets this timer by removing all current entries and timers and adds an initial timer entryvoidstartTimer(String name)Starts a named timer.
-
-
-
Constructor Detail
-
SlingRequestProgressTracker
public SlingRequestProgressTracker()
Creates a new request progress tracker.
-
SlingRequestProgressTracker
public SlingRequestProgressTracker(javax.servlet.http.HttpServletRequest request)
Creates a new request progress tracker and logs initial messages about the supplied request.- Parameters:
request- the request
-
-
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()
- Specified by:
getMessagesin interfaceorg.apache.sling.api.request.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:
dumpin interfaceorg.apache.sling.api.request.RequestProgressTracker
-
log
public void log(String message)
Creates an entry with the given message.- Specified by:
login interfaceorg.apache.sling.api.request.RequestProgressTracker
-
log
public void log(String format, Object... args)
Creates an entry with the given entry tag and message- Specified by:
login interfaceorg.apache.sling.api.request.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:
startTimerin interfaceorg.apache.sling.api.request.RequestProgressTracker
-
logTimer
public void logTimer(String name)
Log a timer entry, including start, end and elapsed time.- Specified by:
logTimerin interfaceorg.apache.sling.api.request.RequestProgressTracker
-
logTimer
public void logTimer(String name, String format, Object... args)
Log a timer entry, including start, end and elapsed time.- Specified by:
logTimerin interfaceorg.apache.sling.api.request.RequestProgressTracker
-
done
public void done()
- Specified by:
donein interfaceorg.apache.sling.api.request.RequestProgressTracker
-
getDuration
public long getDuration()
-
-