TMF: Add the concept of host id to a trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
index 0af9a3a0a192784e7d7c75d7b72488f6acee9180..1e680af5c2ec704dfd0473e3e8430556937e48fd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2011, 2012 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -9,25 +9,23 @@
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Updated as per TMF Trace Model 1.0
- *   Alexandre Montplaisir - Added State Systems support
- *   Patrick Tasse - Added coincidental cohesion APIs
- *   Francois Chouinard - Added Iterator support
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
 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;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 
 /**
  * The event stream structure in TMF. In its basic form, a trace has:
@@ -60,13 +58,6 @@ import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
  *     event = trace.getNext(context);
  * }
  * </pre>
- * <b>Example 1b</b>: Process a whole trace using an iterator
- * <pre>
- * Iterator&lt;ITmfEvent&gt; it = trace.iterator();
- * while (it.hasNext()) {
- *     processEvent(it.next());
- * }
- * </pre>
  * <b>Example 2</b>: Process 50 events starting from the 1000th event
  * <pre>
  * int nbEventsRead = 0;
@@ -114,8 +105,8 @@ import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
  * }
  * </pre>
  *
+ * @version 1.0
  * @author Francois Chouinard
- * @version 2.0
  *
  * @see ITmfContext
  * @see ITmfEvent
@@ -150,7 +141,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param type the trace event type
      * @throws TmfTraceException If we couldn't open the trace
      */
-    public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException;
+    void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException;
 
     /**
      * Validate that the trace is of the correct type.
@@ -158,9 +149,10 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param project the eclipse project
      * @param path the trace path
      *
-     * @return true if trace is valid
+     * @return an IStatus object with validation result. Use severity OK to indicate success.
+     * @since 2.0
      */
-    public boolean validate(IProject project, String path);
+    IStatus validate(IProject project, String path);
 
     // ------------------------------------------------------------------------
     // Basic getters
@@ -169,48 +161,65 @@ public interface ITmfTrace extends ITmfDataProvider {
     /**
      * @return the trace event type
      */
-    public Class<? extends ITmfEvent> getEventType();
+    Class<? extends ITmfEvent> getEventType();
 
     /**
      * @return the associated trace resource
      */
-    public IResource getResource();
+    IResource getResource();
 
     /**
      * @return the trace path
      */
-    public String getPath();
+    String getPath();
 
     /**
      * @return the trace cache size
      */
-    public int getCacheSize();
+    int getCacheSize();
 
     /**
      * @return The statistics provider for this trace
      * @since 2.0
      */
-    public ITmfStatistics getStatistics();
+    ITmfStatistics getStatistics();
+
+    /**
+     * Return the map of state systems associated with this trace.
+     *
+     * This view should be read-only (implementations should use
+     * {@link Collections#unmodifiableMap}).
+     *
+     * @return The map of state systems
+     * @since 2.0
+     */
+    Map<String, ITmfStateSystem> getStateSystems();
 
     /**
-     * Retrieve a state system that belongs to this trace
+     * If a state system is not build by the trace itself, it's possible to
+     * register it if it comes from another source. It will then be accessible
+     * with {@link #getStateSystems} normally.
      *
      * @param id
-     *            The ID of the state system to retrieve.
-     * @return The state system that is associated with this trace and ID, or
-     *         'null' if such a match doesn't exist.
+     *            The unique ID to assign to this state system. In case of
+     *            conflicting ID's, the new one will overwrite the previous one
+     *            (default Map behavior).
+     * @param ss
+     *            The already-built state system
      * @since 2.0
      */
-    public ITmfStateSystem getStateSystem(String id);
+    void registerStateSystem(String id, ITmfStateSystem ss);
 
     /**
-     * Return the list of existing state systems registered with this trace.
+     * Index the trace. Depending on the trace type, this could be done at the
+     * constructor or initTrace phase too, so this could be implemented as a
+     * no-op.
      *
-     * @return A Collection view of the available state systems. The collection
-     *         could be empty, but should not be null.
+     * @param waitForCompletion
+     *            Should we block the caller until indexing is finished, or not.
      * @since 2.0
      */
-    public Collection<String> listStateSystems();
+    void indexTrace(boolean waitForCompletion);
 
     // ------------------------------------------------------------------------
     // Trace characteristics getters
@@ -219,27 +228,30 @@ public interface ITmfTrace extends ITmfDataProvider {
     /**
      * @return the number of events in the trace
      */
-    public long getNbEvents();
+    long getNbEvents();
 
     /**
      * @return the trace time range
+     * @since 2.0
      */
-    public TmfTimeRange getTimeRange();
+    TmfTimeRange getTimeRange();
 
     /**
      * @return the timestamp of the first trace event
+     * @since 2.0
      */
-    public ITmfTimestamp getStartTime();
+    ITmfTimestamp getStartTime();
 
     /**
      * @return the timestamp of the last trace event
+     * @since 2.0
      */
-    public ITmfTimestamp getEndTime();
+    ITmfTimestamp getEndTime();
 
     /**
      * @return the streaming interval in ms (0 if not a streaming trace)
      */
-    public long getStreamingInterval();
+    long getStreamingInterval();
 
     // ------------------------------------------------------------------------
     // Trace positioning getters
@@ -248,7 +260,7 @@ public interface ITmfTrace extends ITmfDataProvider {
     /**
      * @return the current trace location
      */
-    public ITmfLocation getCurrentLocation();
+    ITmfLocation getCurrentLocation();
 
     /**
      * Returns the ratio (proportion) corresponding to the specified location.
@@ -256,7 +268,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param location a trace specific location
      * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
      */
-    public double getLocationRatio(ITmfLocation location);
+    double getLocationRatio(ITmfLocation location);
 
     // ------------------------------------------------------------------------
     // SeekEvent operations (returning a trace context)
@@ -274,7 +286,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param location the trace specific location
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(ITmfLocation location);
+    ITmfContext seekEvent(ITmfLocation location);
 
     /**
      * Position the trace at the 'rank'th event in the trace.
@@ -288,7 +300,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param rank the event rank
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(long rank);
+    ITmfContext seekEvent(long rank);
 
     /**
      * Position the trace at the first event with the specified timestamp. If
@@ -303,8 +315,9 @@ public interface ITmfTrace extends ITmfDataProvider {
      *
      * @param timestamp the timestamp of desired event
      * @return a context which can later be used to read the corresponding event
+     * @since 2.0
      */
-    public ITmfContext seekEvent(ITmfTimestamp timestamp);
+    ITmfContext seekEvent(ITmfTimestamp timestamp);
 
     /**
      * Position the trace at the event located at the specified ratio in the
@@ -317,57 +330,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @param ratio the proportional 'rank' in the trace
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(double ratio);
-
-    // ------------------------------------------------------------------------
-    // Iterator support
-    // ------------------------------------------------------------------------
-
-    /**
-     * Returns an iterator suitable to read a trace from the start
-     *
-     * @return a trace iterator
-     */
-    public Iterator<ITmfEvent> iterator();
-
-    /**
-     * Returns an iterator suitable to read a trace from the requested location
-     *
-     * @param location the first event location in the trace
-     * @return a trace iterator
-     */
-    public Iterator<ITmfEvent> iterator(ITmfLocation location);
-
-    /**
-     * Returns an iterator suitable to read a trace from the requested rank
-     *
-     * @param rank the first event rank
-     * @return a trace iterator
-     */
-    public Iterator<ITmfEvent> iterator(long rank);
-
-    /**
-     * Returns an iterator suitable to read a trace from the requested timestamp
-     *
-     * @param timestamp the first event timestamp
-     * @return a trace iterator
-     */
-    public Iterator<ITmfEvent> iterator(ITmfTimestamp timestamp);
-
-    /**
-     * Returns an iterator suitable to read a trace from the requested 'ratio'
-     *
-     * @param ratio  the first event 'ratio' (see seekEvent(double))
-     * @return a trace iterator
-     */
-    public Iterator<ITmfEvent> iterator(double ratio);
-
-    // ------------------------------------------------------------------------
-    // Coincidental cohesion APIs: current time and range are TMF UI concepts
-    // and have nothing to do with this core API. It can probably be argued
-    // that this is also pathological coupling.
-    // TODO: Stop hacking, start designing.
-    // ------------------------------------------------------------------------
+    ITmfContext seekEvent(double ratio);
 
     /**
      * Returns the initial range offset
@@ -375,21 +338,19 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @return the initial range offset
      * @since 2.0
      */
-    public ITmfTimestamp getInitialRangeOffset();
+    ITmfTimestamp getInitialRangeOffset();
 
     /**
-     * Return the current selected time.
+     * Returns the ID of the host this trace is from. The host ID is not
+     * necessarily the hostname, but should be a unique identifier for the
+     * machine on which the trace was taken. It can be used to determine if two
+     * traces were taken on the exact same machine (timestamp are already
+     * synchronized, resources with same id are the same if taken at the same
+     * time, etc).
      *
-     * @return the current time stamp
-     * @since 2.0
+     * @return The host id of this trace
+     * @since 3.0
      */
-    public ITmfTimestamp getCurrentTime();
+   String getHostId();
 
-    /**
-     * Return the current selected range.
-     *
-     * @return the current time range
-     * @since 2.0
-     */
-    public TmfTimeRange getCurrentRange();
 }
This page took 0.030049 seconds and 5 git commands to generate.