Class SlingRequestProgressTracker

  • All Implemented Interfaces:
    org.apache.sling.api.request.RequestProgressTracker

    public class SlingRequestProgressTracker
    extends Object
    implements org.apache.sling.api.request.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 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:
        getMessages in interface org.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:
        dump in interface org.apache.sling.api.request.RequestProgressTracker
      • log

        public void log​(String message)
        Creates an entry with the given message.
        Specified by:
        log in interface org.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:
        log in interface org.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:
        startTimer in interface org.apache.sling.api.request.RequestProgressTracker
      • logTimer

        public void logTimer​(String name)
        Log a timer entry, including start, end and elapsed time.
        Specified by:
        logTimer in interface org.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:
        logTimer in interface org.apache.sling.api.request.RequestProgressTracker
      • done

        public void done()
        Specified by:
        done in interface org.apache.sling.api.request.RequestProgressTracker
      • getDuration

        public long getDuration()