Rationalize ITmfTrace.initTrace()
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / experiment / TmfExperiment.java
index b7197a3034454364d148909975335675d28a2a33..9a4c1b7b0c8a2f37790ce6e6c37bd8d7b43f59df 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.tmf.core.experiment;
 import java.util.Collections;
 import java.util.Vector;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -36,7 +37,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
@@ -80,7 +80,10 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
     // Flag to initialize only once
     private boolean fInitialized = false;
 
-    // The experiment resource
+    // The experiment bookmarks file
+    private IFile fBookmarksFile;
+
+    // The properties resource
     private IResource fResource;
 
     // ------------------------------------------------------------------------
@@ -93,25 +96,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
     }
 
     @Override
-    public void initTrace(String name, String path, Class<T> eventType) {
-    }
-
-    @Override
-    public void initTrace(String name, String path, Class<T> eventType, boolean indexTrace) {
-        if (indexTrace) {
-            initializeStreamingMonitor();
-        }
-    }
-
-    @Override
-    public void initTrace(String name, String path, Class<T> eventType, int cacheSize) {
-    }
-
-    @Override
-    public void initTrace(String name, String path, Class<T> eventType, int cacheSize, boolean indexTrace) {
-        if (indexTrace) {
-            initializeStreamingMonitor();
-        }
+    public void initTrace(String name, String path, Class<T> eventType, int pageSize) {
     }
 
     /**
@@ -134,10 +119,9 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         fTimeRange = TmfTimeRange.NULL_RANGE;
 
         if (preIndexExperiment) {
-            indexExperiment(true);
+            indexExperiment(true, 0, TmfTimeRange.ETERNITY);
             updateTimeRange();
         }
-
     }
 
     protected TmfExperiment(String id, Class<T> type) {
@@ -163,34 +147,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         this(type, id, traces, TmfTimestamp.ZERO, indexPageSize);
     }
 
-    /**
-     * Copy constructor
-     * 
-     * @param other
-     */
-    @SuppressWarnings("unchecked")
-    public TmfExperiment(TmfExperiment<T> other) {
-        super(other.getName() + "(clone)", other.fType); //$NON-NLS-1$
-
-        fEpoch = other.fEpoch;
-        fIndexPageSize = other.fIndexPageSize;
-
-        fTraces = new ITmfTrace[other.fTraces.length];
-        for (int trace = 0; trace < other.fTraces.length; trace++) {
-            fTraces[trace] = other.fTraces[trace].copy();
-        }
-
-        fNbEvents = other.fNbEvents;
-        fTimeRange = other.fTimeRange;
-    }
-
-    @Override
-    public TmfExperiment<T> copy() {
-        TmfExperiment<T> experiment = new TmfExperiment<T>(this);
-        TmfSignalManager.deregister(experiment);
-        return experiment;
-    }
-
     /**
      * Clears the experiment
      */
@@ -276,8 +232,8 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
      * Returns the rank of the first event with the requested timestamp. If none, returns the index of the next event
      * (if any).
      * 
-     * @param timestamp
-     * @return
+     * @param timestamp the event timestamp
+     * @return the corresponding event rank
      */
     @Override
     public long getRank(ITmfTimestamp timestamp) {
@@ -288,8 +244,8 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
     /**
      * Returns the timestamp of the event at the requested index. If none, returns null.
      * 
-     * @param index
-     * @return
+     * @param index the event index (rank)
+     * @return the corresponding event timestamp
      */
     public ITmfTimestamp getTimestamp(int index) {
         TmfExperimentContext context = seekEvent(index);
@@ -396,7 +352,9 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
             rank += traceRank;
 
             // Set the trace location and read the corresponding event
-            expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone();
+            /* The (TmfContext) cast should be safe since we created 'context'
+             * ourselves higher up. */
+            expLocation.getLocation().locations[i] = ((TmfContext) context.getContexts()[i]).getLocation().clone();
             context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]);
         }
 
@@ -532,13 +490,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         return null;
     }
 
-    /**
-     * Scan the next events from all traces and return the next one in chronological order.
-     * 
-     * @param context
-     * @return
-     */
-
 //     private void dumpContext(TmfExperimentContext context, boolean isBefore) {
 
 //             TmfContext context0 = context.getContexts()[0];
@@ -556,8 +507,15 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
 //             Tracer.trace(result.toString());
 //     }
 
+    /**
+     * Scan the next events from all traces and return the next one in chronological order.
+     * 
+     * @param context the trace context
+     * @return the next event
+     */
+    @SuppressWarnings("unchecked")
     @Override
-    public synchronized ITmfEvent getNextEvent(TmfContext context) {
+    public synchronized ITmfEvent getNextEvent(ITmfContext context) {
 
         // Validate the context
         if (!(context instanceof TmfExperimentContext)) {
@@ -576,7 +534,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         // If an event was consumed previously, get the next one from that trace
         int lastTrace = expContext.getLastTrace();
         if (lastTrace != TmfExperimentContext.NO_TRACE) {
-            TmfContext traceContext = expContext.getContexts()[lastTrace];
+            ITmfContext traceContext = expContext.getContexts()[lastTrace];
             expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext);
             expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
         }
@@ -610,10 +568,10 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         if (trace != TmfExperimentContext.NO_TRACE) {
             updateIndex(expContext, timestamp);
 
-            TmfContext traceContext = expContext.getContexts()[trace];
+            ITmfContext traceContext = expContext.getContexts()[trace];
             TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
 //             expLocation.getLocation()[trace] = traceContext.getLocation().clone();
-            expLocation.getLocation().locations[trace] = traceContext.getLocation().clone();
+            expLocation.getLocation().locations[trace] = (ITmfLocation<? extends Comparable<?>>) traceContext.getLocation().clone();
 
 //             updateIndex(expContext, timestamp);
 
@@ -655,7 +613,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
      * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
      */
     @Override
-    public ITmfEvent parseEvent(TmfContext context) {
+    public ITmfEvent parseEvent(ITmfContext context) {
 
         // Validate the context
         if (!(context instanceof TmfExperimentContext)) {
@@ -672,7 +630,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         // If an event was consumed previously, get the next one from that trace
         int lastTrace = expContext.getLastTrace();
         if (lastTrace != TmfExperimentContext.NO_TRACE) {
-            TmfContext traceContext = expContext.getContexts()[lastTrace];
+            ITmfContext traceContext = expContext.getContexts()[lastTrace];
             expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext);
             expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
             fExperimentContext = (TmfExperimentContext) context;
@@ -826,8 +784,11 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
         }
     }
 
-    protected void indexExperiment(boolean waitForCompletion) {
-        indexExperiment(waitForCompletion, 0, TmfTimeRange.ETERNITY);
+    @Override
+    public void indexTrace(boolean waitForCompletion) {
+        if (waitForCompletion) {
+            initializeStreamingMonitor();
+        }
     }
 
     @SuppressWarnings("unchecked")
@@ -1016,17 +977,33 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> impl
     }
 
     /**
-     * Set the resource to be used for bookmarks on this experiment
-     * @param resource the bookmarks resource
+     * Set the file to be used for bookmarks on this experiment
+     * @param file the bookmarks file
      */
+    public void setBookmarksFile(IFile file) {
+        fBookmarksFile = file;
+    }
+
+    /**
+     * Get the file used for bookmarks on this experiment
+     * @return the bookmarks file or null if none is set
+     */
+    public IFile getBookmarksFile() {
+        return fBookmarksFile;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#setResource(org.eclipse.core.resources.IResource)
+     */
+    @Override
     public void setResource(IResource resource) {
         fResource = resource;
     }
 
-    /**
-     * Get the resource used for bookmarks on this experiment
-     * @return the bookmarks resource or null if none is set
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
      */
+    @Override
     public IResource getResource() {
         return fResource;
     }
This page took 0.02649 seconds and 5 git commands to generate.