tmf: Fix regression in event requests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
index 9b1ec6397bbaecae3d0fe64c02ced22427e25e49..ecee99cd7ce6001dd8d4cff183144485db80845c 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Updated as per TMF Trace Model 1.0
 package org.eclipse.linuxtools.tmf.core.trace;
 
 import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
@@ -25,6 +29,14 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
 
 /**
  * Abstract implementation of ITmfTrace.
@@ -45,7 +57,7 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
  * The concrete class can either specify its own indexer or use the provided
  * TmfCheckpointIndexer (default). In this case, the trace cache size will be
  * used as checkpoint interval.
- * 
+ *
  * @version 1.0
  * @author Francois Chouinard
  *
@@ -53,7 +65,7 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
  * @see ITmfTraceIndexer
  * @see ITmfEventParser
  */
-public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
+public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -72,17 +84,36 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     private long fNbEvents = 0;
 
     // The time span of the event stream
-    private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
+    private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
     private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
 
     // The trace streaming interval (0 = no streaming)
     private long fStreamingInterval = 0;
 
     // The trace indexer
-    private ITmfTraceIndexer<ITmfTrace<ITmfEvent>> fIndexer;
+    private ITmfTraceIndexer fIndexer;
 
     // The trace parser
-    private ITmfEventParser<T> fParser;
+    private ITmfEventParser fParser;
+
+    // The trace's statistics
+    private ITmfStatistics fStatistics;
+
+    // The current selected time
+    private ITmfTimestamp fCurrentTime = TmfTimestamp.ZERO;
+
+    // The current selected range
+    private TmfTimeRange fCurrentRange = TmfTimeRange.NULL_RANGE;
+
+    /**
+     * The collection of state systems that are registered with this trace. Each
+     * sub-class can decide to add its (one or many) state system to this map
+     * during their {@link #buildStateSystem()}.
+     *
+     * @since 2.0
+     */
+    protected final Map<String, ITmfStateSystem> fStateSystems =
+            new HashMap<String, ITmfStateSystem>();
 
     // ------------------------------------------------------------------------
     // Construction
@@ -91,71 +122,70 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     /**
      * The default, parameterless, constructor
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     public TmfTrace() {
         super();
-        fIndexer = new TmfCheckpointIndexer(this);
     }
 
     /**
      * The standard constructor (non-live trace). Applicable when the trace
-     * implements its own parser and if at checkpoint-based index is OK. 
-     * 
+     * implements its own parser and if at checkpoint-based index is OK.
+     *
      * @param resource the resource associated to the trace
      * @param type the trace event type
      * @param path the trace path
      * @param cacheSize the trace cache size
-     * @throws TmfTraceException
+     * @throws TmfTraceException If something failed during the opening
      */
-    protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize) throws TmfTraceException {
-        this(resource, type, path, cacheSize, 0, null);
+    protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException {
+        this(resource, type, path, cacheSize, 0);
     }
 
     /**
      * The standard constructor (live trace). Applicable when the trace
      * implements its own parser and if at checkpoint-based index is OK.
-     * 
+     *
      * @param resource the resource associated to the trace
      * @param type the trace event type
      * @param path the trace path
      * @param cacheSize the trace cache size
      * @param interval the trace streaming interval
-     * @throws TmfTraceException
+     * @throws TmfTraceException If something failed during the opening
      */
-    protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
+    protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
         this(resource, type, path, cacheSize, interval, null);
     }
 
     /**
      * The 'non-default indexer' constructor. Allows to provide a trace
      * specific indexer.
-     * 
+     *
      * @param resource the resource associated to the trace
      * @param type the trace event type
      * @param path the trace path
      * @param cacheSize the trace cache size
+     * @param interval the trace streaming interval
      * @param indexer the trace indexer
-     * @throws TmfTraceException
+     * @throws TmfTraceException If something failed during the opening
      */
-    protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
-            final long interval, final ITmfTraceIndexer<?> indexer) throws TmfTraceException {
+    protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
+            final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException {
         this(resource, type, path, cacheSize, interval, indexer, null);
     }
 
     /**
-     * The full constructor where trace specific indexer/parser are provided. 
-     * 
+     * The full constructor where trace specific indexer/parser are provided.
+     *
      * @param resource the resource associated to the trace
      * @param type the trace event type
      * @param path the trace path
      * @param cacheSize the trace cache size
+     * @param interval the trace streaming interval
      * @param indexer the trace indexer
      * @param parser the trace event parser
-     * @throws TmfTraceException
+     * @throws TmfTraceException If something failed during the opening
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
-            final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<T> parser) throws TmfTraceException {
+    protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
+            final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException {
         super();
         fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
         fStreamingInterval = interval;
@@ -166,11 +196,11 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Copy constructor
-     * 
+     *
      * @param trace the original trace
+     * @throws TmfTraceException Should not happen usually
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public TmfTrace(final TmfTrace<T> trace) throws TmfTraceException {
+    public TmfTrace(final TmfTrace trace) throws TmfTraceException {
         super();
         if (trace == null) {
             throw new IllegalArgumentException();
@@ -190,21 +220,21 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class)
      */
     @Override
-    public void initTrace(final IResource resource, final String path, final Class<T> type) throws TmfTraceException {
+    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
+        fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
         initialize(resource, path, type);
     }
 
     /**
      * Initialize the trace common attributes and the base component.
-     * 
-     * @param resource the Eclipse resource (trace) 
+     *
+     * @param resource the Eclipse resource (trace)
      * @param path the trace path
      * @param type the trace event type
-     * 
-     * @throws TmfTraceException
+     *
+     * @throws TmfTraceException If something failed during the initialization
      */
-    @SuppressWarnings("unchecked")
-    protected void initialize(final IResource resource, final String path, final Class<T> type) throws TmfTraceException {
+    protected void initialize(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
         if (path == null) {
             throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
         }
@@ -213,12 +243,12 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
         String traceName = (resource != null) ? resource.getName() : null;
         // If no resource was provided, extract the display name the trace path
         if (traceName == null) {
-            final int sep = path.lastIndexOf(Path.SEPARATOR);
+            final int sep = path.lastIndexOf(IPath.SEPARATOR);
             traceName = (sep >= 0) ? path.substring(sep + 1) : path;
         }
         if (fParser == null) {
             if (this instanceof ITmfEventParser) {
-                fParser = (ITmfEventParser<T>) this;
+                fParser = (ITmfEventParser) this;
             } else {
                 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
             }
@@ -228,7 +258,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Indicates if the path points to an existing file/directory
-     * 
+     *
      * @param path the path to test
      * @return true if the file/directory exists
      */
@@ -239,11 +269,69 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Index the trace
-     * 
+     *
      * @param waitForCompletion index synchronously (true) or not (false)
      */
     protected void indexTrace(boolean waitForCompletion) {
-        getIndexer().buildIndex(waitForCompletion);
+        getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
+    }
+
+    /**
+     * The default implementation of TmfTrace uses a TmfStatistics back-end.
+     * Override this if you want to specify another type (or none at all).
+     *
+     * @throws TmfTraceException
+     *             If there was a problem setting up the statistics
+     * @since 2.0
+     */
+    protected void buildStatistics() throws TmfTraceException {
+        /*
+         * Initialize the statistics provider, but only if a Resource has been
+         * set (so we don't build it for experiments, for unit tests, etc.)
+         */
+        fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
+    }
+
+    /**
+     * Build the state system(s) associated with this trace type.
+     *
+     * Suppressing the warning, because the 'throws' will usually happen in
+     * sub-classes.
+     *
+     * @throws TmfTraceException
+     *             If there is a problem during the build
+     * @since 2.0
+     */
+    @SuppressWarnings("unused")
+    protected void buildStateSystem() throws TmfTraceException {
+        /*
+         * Nothing is done in the base implementation, please specify
+         * how/if to register a new state system in derived classes.
+         */
+        return;
+    }
+
+    /**
+     * Clears the trace
+     */
+    @Override
+    public synchronized void dispose() {
+        /* Clean up the index if applicable */
+        if (getIndexer() != null) {
+            getIndexer().dispose();
+        }
+
+        /* Clean up the statistics */
+        if (fStatistics != null) {
+            fStatistics.dispose();
+        }
+
+        /* Clean up the state systems */
+        for (ITmfStateSystem ss : fStateSystems.values()) {
+            ss.dispose();
+        }
+
+        super.dispose();
     }
 
     // ------------------------------------------------------------------------
@@ -254,9 +342,8 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
      */
     @Override
-    @SuppressWarnings("unchecked")
-    public Class<T> getEventType() {
-        return (Class<T>) super.getType();
+    public Class<ITmfEvent> getEventType() {
+        return (Class<ITmfEvent>) super.getType();
     }
 
     /* (non-Javadoc)
@@ -294,17 +381,41 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     /**
      * @return the trace indexer
      */
-    protected ITmfTraceIndexer<ITmfTrace<ITmfEvent>> getIndexer() {
+    protected ITmfTraceIndexer getIndexer() {
         return fIndexer;
     }
 
     /**
      * @return the trace parser
      */
-    protected ITmfEventParser<T> getParser() {
+    protected ITmfEventParser getParser() {
         return fParser;
     }
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    public ITmfStatistics getStatistics() {
+        return fStatistics;
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final ITmfStateSystem getStateSystem(String id) {
+        return fStateSystems.get(id);
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final Collection<String> listStateSystems() {
+        return fStateSystems.keySet();
+    }
+
     // ------------------------------------------------------------------------
     // ITmfTrace - Trace characteristics getters
     // ------------------------------------------------------------------------
@@ -330,7 +441,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      */
     @Override
     public ITmfTimestamp getStartTime() {
-        return fStartTime.clone();
+        return fStartTime;
     }
 
     /* (non-Javadoc)
@@ -338,16 +449,51 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      */
     @Override
     public ITmfTimestamp getEndTime() {
-        return fEndTime.clone();
+        return fEndTime;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentTime()
+     */
+    /**
+     * @since 2.0
+     */
+    @Override
+    public ITmfTimestamp getCurrentTime() {
+        return fCurrentTime;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentRange()
+     */
+    /**
+     * @since 2.0
+     */
+    @Override
+    public TmfTimeRange getCurrentRange() {
+        return fCurrentRange;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getInitialRangeOffset()
+     */
+    /**
+     * @since 2.0
+     */
+    @Override
+    public ITmfTimestamp getInitialRangeOffset() {
+        final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
+        return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
     }
 
     // ------------------------------------------------------------------------
-    // Convenience setters/getters
+    // Convenience setters
     // ------------------------------------------------------------------------
 
     /**
      * Set the trace cache size. Must be done at initialization time.
-     * 
+     *
      * @param cacheSize The trace cache size
      */
     protected void setCacheSize(final int cacheSize) {
@@ -357,7 +503,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     /**
      * Set the trace known number of events. This can be quite dynamic
      * during indexing or for live traces.
-     * 
+     *
      * @param nbEvents The number of events
      */
     protected synchronized void setNbEvents(final long nbEvents) {
@@ -366,35 +512,35 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Update the trace events time range
-     * 
+     *
      * @param range the new time range
      */
     protected void setTimeRange(final TmfTimeRange range) {
-        fStartTime = range.getStartTime().clone();
-        fEndTime = range.getEndTime().clone();
+        fStartTime = range.getStartTime();
+        fEndTime = range.getEndTime();
     }
 
     /**
      * Update the trace chronologically first event timestamp
-     * 
+     *
      * @param startTime the new first event timestamp
      */
     protected void setStartTime(final ITmfTimestamp startTime) {
-        fStartTime = startTime.clone();
+        fStartTime = startTime;
     }
 
     /**
      * Update the trace chronologically last event timestamp
-     * 
+     *
      * @param endTime the new last event timestamp
      */
     protected void setEndTime(final ITmfTimestamp endTime) {
-        fEndTime = endTime.clone();
+        fEndTime = endTime;
     }
 
     /**
      * Set the polling interval for live traces (default = 0 = no streaming).
-     * 
+     *
      * @param interval the new trace streaming interval
      */
     protected void setStreamingInterval(final long interval) {
@@ -403,19 +549,19 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Set the trace indexer. Must be done at initialization time.
-     * 
+     *
      * @param indexer the trace indexer
      */
-    protected void setIndexer(final ITmfTraceIndexer<ITmfTrace<ITmfEvent>> indexer) {
+    protected void setIndexer(final ITmfTraceIndexer indexer) {
         fIndexer = indexer;
     }
 
     /**
      * Set the trace parser. Must be done at initialization time.
-     * 
+     *
      * @param parser the new trace parser
      */
-    protected void setParser(final ITmfEventParser<T> parser) {
+    protected void setParser(final ITmfEventParser parser) {
         fParser = parser;
     }
 
@@ -431,7 +577,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
         // A rank <= 0 indicates to seek the first event
         if (rank <= 0) {
-            ITmfContext context = seekEvent((ITmfLocation<?>) null);
+            ITmfContext context = seekEvent((ITmfLocation) null);
             context.setRank(0);
             return context;
         }
@@ -443,7 +589,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
         long pos = context.getRank();
         if (pos < rank) {
             ITmfEvent event = getNext(context);
-            while (event != null && ++pos < rank) {
+            while ((event != null) && (++pos < rank)) {
                 event = getNext(context);
             }
         }
@@ -458,22 +604,23 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
         // A null timestamp indicates to seek the first event
         if (timestamp == null) {
-            ITmfContext context = seekEvent((ITmfLocation<?>) null);
+            ITmfContext context = seekEvent((ITmfLocation) null);
             context.setRank(0);
             return context;
         }
 
         // Position the trace at the checkpoint
-        final ITmfContext context = fIndexer.seekIndex(timestamp);
+        ITmfContext context = fIndexer.seekIndex(timestamp);
 
         // And locate the requested event context
         final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
         ITmfEvent event = getNext(nextEventContext);
         while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
-            context.setLocation(nextEventContext.getLocation().clone());
-            context.increaseRank();
+            context.dispose();
+            context = nextEventContext.clone();
             event = getNext(nextEventContext);
         }
+        nextEventContext.dispose();
         if (event == null) {
             context.setLocation(null);
             context.setRank(ITmfContext.UNKNOWN_RANK);
@@ -489,9 +636,9 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
      */
     @Override
-    public synchronized T getNext(final ITmfContext context) {
+    public synchronized ITmfEvent getNext(final ITmfContext context) {
         // parseEvent() does not update the context
-        final T event = fParser.parseEvent(context);
+        final ITmfEvent event = fParser.parseEvent(context);
         if (event != null) {
             updateAttributes(context, event.getTimestamp());
             context.setLocation(getCurrentLocation());
@@ -504,7 +651,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     /**
      * Hook for special event processing by the concrete class
      * (called by TmfTrace.getEvent())
-     * 
+     *
      * @param event the event
      */
     protected void processEvent(final ITmfEvent event) {
@@ -513,23 +660,32 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
 
     /**
      * Update the trace attributes
-     * 
+     *
      * @param context the current trace context
      * @param timestamp the corresponding timestamp
      */
     protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
-        if (fStartTime.compareTo(timestamp, false) > 0) {
+        if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
             fStartTime = timestamp;
         }
-        if (fEndTime.compareTo(timestamp, false) < 0) {
+        if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
             fEndTime = timestamp;
         }
+        if (fCurrentRange == TmfTimeRange.NULL_RANGE) {
+            fCurrentTime = timestamp;
+            ITmfTimestamp initialOffset = getInitialRangeOffset();
+            long endValue = timestamp.getValue() + initialOffset.normalize(0, timestamp.getScale()).getValue();
+            ITmfTimestamp endTimestamp = new TmfTimestamp(endValue, timestamp.getScale());
+            fCurrentRange = new TmfTimeRange(timestamp, endTimestamp);
+        }
         if (context.hasValidRank()) {
             long rank = context.getRank();
             if (fNbEvents <= rank) {
                 fNbEvents = rank + 1;
             }
-            fIndexer.updateIndex(context, timestamp);
+            if (fIndexer != null) {
+                fIndexer.updateIndex(context, timestamp);
+            }
         }
     }
 
@@ -537,35 +693,132 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     // TmfDataProvider
     // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest)
+    /**
+     * @since 2.0
      */
     @Override
-    public ITmfContext armRequest(final ITmfDataRequest<T> request) {
-        if (request instanceof ITmfEventRequest<?>
-            && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime())
-            && request.getIndex() == 0)
+    public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
+        if (executorIsShutdown()) {
+            return null;
+        }
+        if ((request instanceof ITmfEventRequest)
+            && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
+            && (request.getIndex() == 0))
         {
-            final ITmfContext context = seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime());
-            ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
+            final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
+            ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
             return context;
 
         }
         return seekEvent(request.getIndex());
     }
 
-//    /* (non-Javadoc)
-//     * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
-//     */
-//    @Override
-//    @SuppressWarnings("unchecked")
-//    public T getNext(final ITmfContext context) {
-//        if (context instanceof TmfContext) {
-//            return (T) readNextEvent(context);
-//        }
-//        return null;
-//    }
+    // ------------------------------------------------------------------------
+    // Signal handlers
+    // ------------------------------------------------------------------------
+
+    /**
+     * Handler for the Trace Opened signal
+     *
+     * @param signal
+     *            The incoming signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void traceOpened(TmfTraceOpenedSignal signal) {
+        ITmfTrace trace = signal.getTrace();
+        if (signal.getTrace() instanceof TmfExperiment) {
+            TmfExperiment experiment = (TmfExperiment) signal.getTrace();
+            for (ITmfTrace expTrace : experiment.getTraces()) {
+                if (expTrace == this) {
+                    trace = expTrace;
+                    break;
+                }
+            }
+        }
+        if (trace == this) {
+            /* the signal is for this trace or for an experiment containing this trace */
+            try {
+                buildStatistics();
+            } catch (TmfTraceException e) {
+                e.printStackTrace();
+            }
+            try {
+                buildStateSystem();
+            } catch (TmfTraceException e) {
+                e.printStackTrace();
+            }
+
+            /* Refresh the project, so it can pick up new files that got created. */
+            try {
+                if (fResource != null) {
+                    fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+                }
+            } catch (CoreException e) {
+                e.printStackTrace();
+            }
+        }
+        if (signal.getTrace() == this) {
+            /* the signal is for this trace or experiment */
+            if (getNbEvents() == 0) {
+                return;
+            }
+
+            final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
+            final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
+
+            // Broadcast in separate thread to prevent deadlock
+            new Thread() {
+                @Override
+                public void run() {
+                    broadcast(rangeUpdatedsignal);
+                }
+            }.start();
+            return;
+        }
+    }
 
+    /**
+     * Signal handler for the TmfTraceRangeUpdatedSignal signal
+     *
+     * @param signal The incoming signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
+        if (signal.getTrace() == this) {
+            getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
+        }
+    }
+
+    /**
+     * Signal handler for the TmfTimeSynchSignal signal
+     *
+     * @param signal The incoming signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void synchToTime(final TmfTimeSynchSignal signal) {
+        if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
+            fCurrentTime = signal.getCurrentTime();
+        }
+    }
+
+    /**
+     * Signal handler for the TmfRangeSynchSignal signal
+     *
+     * @param signal The incoming signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void synchToRange(final TmfRangeSynchSignal signal) {
+        if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
+            fCurrentTime = signal.getCurrentTime();
+        }
+        if (signal.getCurrentRange().getIntersection(getTimeRange()) != null) {
+            fCurrentRange = signal.getCurrentRange().getIntersection(getTimeRange());
+        }
+    }
 
     // ------------------------------------------------------------------------
     // toString
This page took 0.040865 seconds and 5 git commands to generate.