Refactor TmfTrace and dependencies - introduce ITmfTraceIndexer
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
index 40677c1a625f99bd76ee295040105714ba7d27e8..15666917f8a66a8b5c3c4bf91fb734efdb478631 100644 (file)
@@ -17,7 +17,7 @@ import java.io.FileNotFoundException;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
+import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
@@ -25,9 +25,60 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 /**
  * <b><u>ITmfTrace</u></b>
  * <p>
- * The basic event trace structure in TMF.
+ * The event stream structure in TMF. In its basic form, a trace has:
+ * <ul>
+ * <li> the associated Eclipse resource
+ * <li> the path to its location on the file system
+ * <li> the type of the events it contains
+ * <li> the number of events it contains
+ * <li> the time range (span) of the events it contains
+ * </ul>
+ * Concrete ITmfTrace classes have to provide a parameter-less constructor and
+ * an initialization method (initTace())if they are to be opened from the
+ * Project View. Also, a validation (validate()) method has to be provided to
+ * ensure that the trace is of the correct type.
+ * <p>
+ * A trace can be accessed simultaneously from multiple threads by various
+ * application components. To avoid obvious multi-threading issues, the trace
+ * uses an ITmfContext as a synchronization aid for its read operations.
+ * <p>
+ * A proper ITmfContext can be obtained by performing a seek operation on the
+ * trace. Seek operations can be performed for a particular event (by rank or
+ * timestamp) or for a plain trace location.
+ * <p>
+ * <b>Example 1</b>: Read a whole trace
+ * <pre>
+ * ITmfContext context = trace.seekLocationt(null);
+ * ITmfEvent event = trace.getEvent(context);
+ * while (event != null) {
+ *     // Do something ...
+ *     event = trace.getEvent(context);
+ * }
+ * </pre>
+ * <b>Example 2</b>: Process 50 events starting from the 1000th event
+ * <pre>
+ * int nbEventsRead = 0;
+ * ITmfContext context = trace.seekEvent(1000);
+ * ITmfEvent event = trace.getEvent(context);
+ * while (event != null && nbEventsRead < 50) {
+ *     nbEventsRead++;
+ *     // Do something ...
+ *     event = trace.getEvent(context);
+ * }
+ * </pre>
+ * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
+ * <pre>
+ * ITmfTimestamp startTime = ...;
+ * ITmfTimestamp endTime = ...;
+ * ITmfContext context = trace.seekEvent(startTime);
+ * ITmfEvent event = trace.getEvent(context);
+ * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
+ *     // Do something ...
+ *     event = trace.getEvent(context);
+ * }
+ * </pre>
  */
-public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable {
+public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
 
     // ------------------------------------------------------------------------
     // Initializers
@@ -35,14 +86,18 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
 
     /**
      * Initialize a newly instantiated "empty" trace object. This is used to
-     * parameterize an ITmfTrace instantiated with its parameterless constructor.
+     * properly parameterize an ITmfTrace instantiated with its parameterless
+     * constructor.
+     * 
+     * Typically, the parameterless constructor will provide the block size
+     * and its associated parser and indexer.
      * 
-     * @param name the trace name
+     * @param resource the trace resource
      * @param path the trace path
      * @param type the trace event type
      * @throws FileNotFoundException
      */
-    public void initTrace(String name, String path, Class<T> type) throws FileNotFoundException;
+    public void initTrace(IResource resource, String path, Class<T> type) throws FileNotFoundException;
 
     /**
      * Validate that the trace is of the correct type.
@@ -54,26 +109,33 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
      */
     public boolean validate(IProject project, String path);
 
-    /**
-     * Set the resource used for persistent properties on this trace
-     * 
-     * @param resource the properties resource
-     */
-    public void setResource(IResource resource);
-
     // ------------------------------------------------------------------------
     // Basic getters
     // ------------------------------------------------------------------------
 
+    /**
+     * @return the trace event type
+     */
+    public Class<T> getType();
+
+    /**
+     * @return the associated trace resource
+     */
+    public IResource getResource();
+
     /**
      * @return the trace path
      */
     public String getPath();
 
     /**
-     * @return the properties resource or null if none is set
+     * @return the trace cache size
      */
-    public IResource getResource();
+    public int getCacheSize();
+
+    // ------------------------------------------------------------------------
+    // Trace characteristics getters
+    // ------------------------------------------------------------------------
 
     /**
      * @return the number of events in the trace
@@ -95,36 +157,36 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
      */
     public ITmfTimestamp getEndTime();
 
-    /**
-     * @return the streaming interval in ms (0 if not streaming)
-     */
-    public long getStreamingInterval();
+    // ------------------------------------------------------------------------
+    // Trace positioning getters
+    // ------------------------------------------------------------------------
 
     /**
-     * @return the trace index page size
+     * @return the current trace location
      */
-    public int getIndexPageSize();
-
-    // ------------------------------------------------------------------------
-    // Indexing
-    // ------------------------------------------------------------------------
+    public ITmfLocation<?> getCurrentLocation();
 
     /**
-     * Start the trace indexing, optionally wait for the index to be fully
-     * built before returning.
+     * Returns the ratio (proportion) corresponding to the specified location.
      * 
-     * @param waitForCompletion true for synchronous indexing
+     * @param location a trace specific location
+     * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
      */
-    public void indexTrace(boolean waitForCompletion);
+    public double getLocationRatio(ITmfLocation<?> location);
 
     // ------------------------------------------------------------------------
-    // Seek operations
+    // Seek operations (returning a reading context)
     // ------------------------------------------------------------------------
 
     /**
      * Position the trace at the specified location. The null location
-     * is used to indicate that the first trace event.
-     * 
+     * is used to indicate that the first trace event is requested.
+     * <p>
+     * <ul>
+     * <li> a <b>null</b> location returns the context of the first event
+     * <li> an invalid location, including beyond the last event, returns a null context
+     * </ul>
+     * <p>
      * @param location the trace specific location (null for 1st event)
      * @return a context which can later be used to read the corresponding event
      */
@@ -133,10 +195,10 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
     /**
      * Position the trace at the event located at the specified ratio in the
      * trace file.
-     * 
+     * <p>
      * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
      * voluntarily vague. Typically, it would refer to the event proportional
-     * rank or timestamp in the trace file.
+     * rank (arguably more intuitive) or timestamp in the trace file.
      * 
      * @param ratio the proportional 'rank' in the trace
      * @return a context which can later be used to read the corresponding event
@@ -146,7 +208,13 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
     /**
      * Position the trace at the first event with the specified timestamp. If
      * there is no event with the requested timestamp, a context pointing to
-     * the chronologically next event is returned.
+     * the next chronological event is returned.
+     * <p>
+     * A null timestamp is interpreted as seeking for the first event of the
+     * trace.
+     * <p>
+     * If the requested timestamp is beyond the last trace event, the context
+     * returned will yield a null event if used in a subsequent read.
      * 
      * @param timestamp the timestamp of desired event
      * @return a context which can later be used to read the corresponding event
@@ -154,7 +222,10 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
     public ITmfContext seekEvent(ITmfTimestamp timestamp);
 
     /**
-     * Position the trace at the Nth event in the trace.
+     * Position the trace at the 'rank'th event in the trace.
+     * <p>
+     * If the requested rank is beyond the last trace event, the context
+     * returned will yield a null event if used in a subsequent read.
      * 
      * @param rank the event rank
      * @return a context which can later be used to read the corresponding event
@@ -162,15 +233,15 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
     public ITmfContext seekEvent(long rank);
 
     // ------------------------------------------------------------------------
-    // Read operations
+    // Read operations (returning an actual event)
     // ------------------------------------------------------------------------
 
     /**
      * Return the event pointed by the supplied context (or null if no event
      * left) and updates the context to point the next event.
      * 
-     * @param context the read context
-     * @return the next event in the stream
+     * @param context the read context (will be updated)
+     * @return the event pointed to by the context
      */
     public ITmfEvent getNextEvent(ITmfContext context);
 
@@ -183,40 +254,12 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfComponent, Cloneable
      */
     public ITmfEvent parseEvent(ITmfContext context);
 
-
     // ------------------------------------------------------------------------
-    // Location operations
     // ------------------------------------------------------------------------
 
     /**
-     * @return the current trace location
+     * @return the streaming interval in ms (0 if not a streaming trace)
      */
-    public ITmfLocation<?> getCurrentLocation();
-
-    /**
-     * Returns the ratio (proportion) corresponding to the specified location.
-     * 
-     * @param location a trace specific location
-     * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
-     */
-    public double getLocationRatio(ITmfLocation<?> location);
-
-    /**
-     * Returns the rank of the first event with the requested timestamp.
-     * If none, returns the index of the subsequent event (if any).
-     * 
-     * @param timestamp the requested event timestamp
-     * @return the corresponding event rank
-     */
-    public long getRank(ITmfTimestamp timestamp);
-
-    // ------------------------------------------------------------------------
-    // Cloneable
-    // ------------------------------------------------------------------------
-
-    /**
-     * @return a clone of the trace
-     */
-    public ITmfTrace<T> clone() throws CloneNotSupportedException;
+    public long getStreamingInterval();
 
 }
This page took 0.032462 seconds and 5 git commands to generate.