You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/10/29 15:56:39 UTC

svn commit: r589651 - /incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java

Author: fmeschbe
Date: Mon Oct 29 07:56:38 2007
New Revision: 589651

URL: http://svn.apache.org/viewvc?rev=589651&view=rev
Log:
SLING-28 Make the RequestProgressTracker an interface delegating the actual implementation to the Sling API implementation

Modified:
    incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java

Modified: incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java?rev=589651&r1=589650&r2=589651&view=diff
==============================================================================
--- incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java (original)
+++ incubator/sling/trunk/sling-api/src/main/java/org/apache/sling/api/request/RequestProgressTracker.java Mon Oct 29 07:56:38 2007
@@ -19,10 +19,7 @@
 package org.apache.sling.api.request;
 
 import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.Iterator;
 
 /**
  * The <code>RequestProgressTracker</code> class provides the functionality to
@@ -34,22 +31,22 @@
  * The following functionality is provided:
  * <ol>
  * <li>Track the progress of request processing through the
- * {@link #log(String)} and {@link #log(String, String)} methods.
+ * {@link #log(String)} and {@link #log(String, Object...)} methods.
  * <li>Ability to measure and track processing times of parts of request
- * processing through the {@link #startTimer(String)} and
- * {@link #checkTimer(String)} methods.
- * <li>Dumping the recording messages through the
- * {@link #dumpText(PrintWriter)} method.
- * <li>Resetting the tracker through the {@link #reset()} method.
+ * processing through the {@link #startTimer(String)},
+ * {@link #logTimer(String)} ahd {@link #logTimer(String, String, Object...)}
+ * methods.
+ * <li>Dumping the recording messages through the {@link #dump(PrintWriter)}
+ * method.
+ * <li>Return the log messages through the {@link #getMessages()} method.
  * </ol>
  * <p>
  * <b>Tracking Request Processing</b>
  * <p>
  * As the request being processed, certain steps may be tracked by calling
  * either of the <code>log</code> methods. A tracking entry consists of a time
- * stamp managed by this class, a tracking message noting the actual step being
- * tracked and an optional tracking tag. The value of the tracking tag depends
- * on the application and defaults to {@link #TAG_CHECK} if not specified.
+ * stamp managed by this class and a tracking message noting the actual step
+ * being tracked.
  * <p>
  * <b>Timing Processing Steps</b>
  * </p>
@@ -58,186 +55,67 @@
  * a map of named timers. Each timer is started (initialized or reset) by
  * calling the {@link #startTimer(String)} method. This method just records the
  * starting time of the named timer and adds a tracking entry with the timer
- * name as the message and the tracking tag {@link #TAG_START}.
+ * name as the message.
  * <p>
  * To record the number of milliseconds ellapsed since a timer has been started,
- * the {@link #checkTimer(String)} method may be called. This method logs s
- * tracking entry with the tracking tag {@link #TAG_CHECK} and a message
+ * the {@link #logTimer(String)} or {@link #logTimer(String, String, Object...)}
+ * method may be called. This method logs a tracking entry with a message
  * consisting of the name of the timer and the number of milliseconds ellapsed
  * since the timer was last {@link #startTimer(String) started}. The
- * {@link #checkTimer(String)} method may be called multiple times to record
+ * <code>logTimer</code> methods may be called multiple times to record
  * several timed steps.
  * <p>
  * Calling the {@link #startTimer(String)} method with the name of timer which
  * already exists, resets the start time of the named timer to the current
  * system time.
  * <p>
- * <b>Dumping Tracking Entries</b>
+ * <b>Retrieving Tracking Entries</b>
  * <p>
- * The {@link #dumpText(PrintWriter)} methods adds a tracking entry with tag
- * {@link #TAG_CHECK} and writes all tracking entries to the given
- * <code>PrintWriter</code>. Each entry is written on a single line
- * consisting of the following fields:
- * <ol>
- * <li>The number of milliseconds since the last {@link #reset()} (or creation)
- * of this timer.
- * <li>The absolute time of the timer in parenthesis.
- * <li>The timer tag enclosed in stars (*)
- * <li>The entry message
- * </ol>
+ * The {@link #dump(PrintWriter)} method may be used to write the tracking
+ * entries to the given <code>PrintWriter</code> to for example log them in a
+ * HTML comment. Alternatively the tracking entries may be retrieved as an
+ * iterator of messages through the {@link #getMessages()} method. The
+ * formatting of the tracking entries is implementation specific.
  */
-public class RequestProgressTracker {
-
-    /**
-     * The tracking tag used for starting messages in the {@link #reset()} and
-     * {@link #startTimer(String)} methods (value is "START").
-     */
-    public static final String TAG_START = "START";
+public interface RequestProgressTracker {
 
-    /**
-     * The default tracking tag used by the {@link #log(String)} and
-     * {@link #checkTimer(String)} methods (value is "CHECK").
-     */
-    public static final String TAG_CHECK = "CHECK";
-
-    /**
-     * The <em>printf</em> format to dump a tracking line.
-     *
-     * @see #dumpText(PrintWriter)
-     */
-    private static final String DUMP_FORMAT = "%1$7d (%2$tF %2$tT) *%3$5s* %4$s%n";
+    /** Creates an entry with the given message */
+    public void log(String message);
 
     /**
-     * The system time at creation of this instance or the last {@link #reset()}.
+     * Creates an entry with a message constructed from the given
+     * <code>MessageFormat</code> format evaluated using the given formatting
+     * arguments.
      */
-    private long processingStart;
+    public void log(String format, Object... args);
 
     /**
-     * The list of tracking entries.
+     * Starts a named timer. If a timer of the same name already exists, it is
+     * reset to the current time.
      */
-    private final List<TrackingEntry> entries = new ArrayList<TrackingEntry>();
+    public void startTimer(String name);
 
     /**
-     * Map of named timers indexed by timer name storing the sytsem time of
-     * start of the respective timer.
+     * Logs an entry with the message set to the name of the timer and the
+     * number of milliseconds ellapsed since the timer start.
      */
-    private final Map<String, Long> namedTimerEntries = new HashMap<String, Long>();
+    public void logTimer(String name);
 
     /**
-     * Creates a new request progress tracker.
+     * Logs an entry with the message constructed from the given
+     * <code>MessageFormat</code> pattern evaluated using the given arguments
+     * and the number of milliseconds ellapsed since the timer start.
      */
-    public RequestProgressTracker() {
-        reset();
-    }
+    public void logTimer(String name, String format, Object... args);
 
     /**
-     * Resets this timer by removing all current entries and timers and adds an
-     * initial timer entry
+     * Returns an <code>Iterator</code> of tracking entries.
      */
-    public void reset() {
-        // remove all entries
-        entries.clear();
-        namedTimerEntries.clear();
-
-        // enter start message
-        processingStart = System.currentTimeMillis();
-        log(processingStart, TAG_START, "Request Processing");
-    }
+    Iterator<String> getMessages();
 
     /**
      * 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.
      */
-    public void dumpText(PrintWriter writer) {
-        log("Dumping RequestProgressTracker Entries");
-
-        for (TrackingEntry entry : entries) {
-            long offset = entry.getTimeStamp() - processingStart;
+    public void dump(PrintWriter writer);
 
-            writer.printf(DUMP_FORMAT, offset, entry.getTimeStamp(),
-                entry.getTag(), entry.getMessage());
-        }
-    }
-
-    /** Creates an entry with the given message and entry tag {@link #TAG_CHECK} */
-    public void log(String message) {
-        entries.add(new TrackingEntry(TAG_CHECK, message));
-    }
-
-    /** Creates an entry with the given entry tag and message */
-    public void log(String tag, String message) {
-        entries.add(new TrackingEntry(tag, message));
-    }
-
-    /**
-     * Creates an entry with the given time, entry tag and message. This is a
-     * private method, as for users of this API time stamps are managed by this
-     * class. For internal uses the timestamp may be generated outside of this
-     * method.
-     */
-    private void log(long timeStamp, String tag, String message) {
-        entries.add(new TrackingEntry(timeStamp, tag, message));
-    }
-
-    /**
-     * Starts a named timer. If a timer of the same name already exists, it is
-     * reset to the current time.
-     */
-    public void startTimer(String name) {
-        long timer = System.currentTimeMillis();
-        namedTimerEntries.put(name, timer);
-
-        log(timer, TAG_START, name);
-    }
-
-    /**
-     * Logs an entry with entry tag {@link #TAG_CHECK} and the message set to
-     * the name of the timer and the number of milliseconds ellapsed since the
-     * timer start.
-     */
-    public void checkTimer(String name) {
-        if (namedTimerEntries.containsKey(name)) {
-            long timer = namedTimerEntries.get(name);
-            long currentTime = System.currentTimeMillis();
-            log(currentTime, TAG_CHECK, name + ", elapsed = "
-                + (currentTime - timer) + "ms");
-        }
-    }
-
-    /** Process tracker entry keeping timestamp, tag and message */
-    private static class TrackingEntry {
-
-        // creation time stamp
-        private final long timeStamp;
-
-        // tracking tag
-        private final String tag;
-
-        // tracking message
-        private final String message;
-
-        TrackingEntry(String tag, String message) {
-            this.timeStamp = System.currentTimeMillis();
-            this.tag = tag;
-            this.message = message;
-        }
-
-        TrackingEntry(long timeStamp, String tag, String message) {
-            this.timeStamp = timeStamp;
-            this.tag = tag;
-            this.message = message;
-        }
-
-        long getTimeStamp() {
-            return timeStamp;
-        }
-
-        String getTag() {
-            return tag;
-        }
-
-        String getMessage() {
-            return message;
-        }
-    }
 }