tmf/lttng: Fix newly-introduced Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
index 82421f5d621906729b29ce774ef5c76cbe30a540..ea18b442fd081056e97b60f3b34293dd22f89a34 100644 (file)
@@ -25,6 +25,9 @@ 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.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
 
 /**
  * Abstract implementation of ITmfTrace.
@@ -53,7 +56,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
@@ -79,10 +82,13 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
     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;
 
     // ------------------------------------------------------------------------
     // Construction
@@ -103,9 +109,9 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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 {
+    protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException {
         this(resource, type, path, cacheSize, 0);
     }
 
@@ -118,9 +124,9 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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);
     }
 
@@ -132,11 +138,12 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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);
     }
 
@@ -147,13 +154,13 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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;
@@ -168,8 +175,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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();
@@ -189,8 +195,7 @@ 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
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    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);
     }
@@ -202,10 +207,9 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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$
         }
@@ -219,12 +223,14 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
         }
         if (fParser == null) {
             if (this instanceof ITmfEventParser) {
-                fParser = (ITmfEventParser<T>) this;
+                fParser = (ITmfEventParser) this;
             } else {
                 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
             }
         }
         super.init(traceName, type);
+
+        buildStatistics();
     }
 
     /**
@@ -247,15 +253,36 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
         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) );
+    }
+
     /**
      * Clears the trace
      */
     @Override
     public synchronized void dispose() {
-        // Clean up the index if applicable
+        /* Clean up the index if applicable */
         if (getIndexer() != null) {
             getIndexer().dispose();
         }
+
+        /* Clean up the statistics */
+        if (fStatistics != null) {
+            fStatistics.dispose();
+        }
         super.dispose();
     }
 
@@ -267,9 +294,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)
@@ -307,17 +333,37 @@ 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 ITmfStateSystem getStateSystem() {
+        /*
+         * By default, no state system is used. Sub-classes can specify their
+         * own behaviour.
+         */
+        return null;
+    }
+
     // ------------------------------------------------------------------------
     // ITmfTrace - Trace characteristics getters
     // ------------------------------------------------------------------------
@@ -343,7 +389,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      */
     @Override
     public ITmfTimestamp getStartTime() {
-        return fStartTime.clone();
+        return fStartTime;
     }
 
     /* (non-Javadoc)
@@ -351,7 +397,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      */
     @Override
     public ITmfTimestamp getEndTime() {
-        return fEndTime.clone();
+        return fEndTime;
     }
 
     // ------------------------------------------------------------------------
@@ -383,8 +429,8 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @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();
     }
 
     /**
@@ -393,7 +439,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @param startTime the new first event timestamp
      */
     protected void setStartTime(final ITmfTimestamp startTime) {
-        fStartTime = startTime.clone();
+        fStartTime = startTime;
     }
 
     /**
@@ -402,7 +448,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @param endTime the new last event timestamp
      */
     protected void setEndTime(final ITmfTimestamp endTime) {
-        fEndTime = endTime.clone();
+        fEndTime = endTime;
     }
 
     /**
@@ -419,7 +465,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      *
      * @param indexer the trace indexer
      */
-    protected void setIndexer(final ITmfTraceIndexer<ITmfTrace<ITmfEvent>> indexer) {
+    protected void setIndexer(final ITmfTraceIndexer indexer) {
         fIndexer = indexer;
     }
 
@@ -428,7 +474,7 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      *
      * @param parser the new trace parser
      */
-    protected void setParser(final ITmfEventParser<T> parser) {
+    protected void setParser(final ITmfEventParser parser) {
         fParser = parser;
     }
 
@@ -444,7 +490,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;
         }
@@ -471,7 +517,7 @@ 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;
         }
@@ -483,16 +529,18 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
         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.dispose();
             context = nextEventContext.clone();
             event = getNext(nextEventContext);
         }
+        nextEventContext.dispose();
         if (event == null) {
             context.setLocation(null);
             context.setRank(ITmfContext.UNKNOWN_RANK);
         }
         return context;
     }
-    
+
     // ------------------------------------------------------------------------
     // ITmfTrace - Read operations (returning an actual event)
     // ------------------------------------------------------------------------
@@ -501,9 +549,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());
@@ -531,17 +579,19 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      */
     protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
         if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
-            fStartTime = timestamp.clone();
+            fStartTime = timestamp;
         }
         if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
-            fEndTime = timestamp.clone();
+            fEndTime = timestamp;
         }
         if (context.hasValidRank()) {
             long rank = context.getRank();
             if (fNbEvents <= rank) {
                 fNbEvents = rank + 1;
             }
-            fIndexer.updateIndex(context, timestamp);
+            if (fIndexer != null) {
+                fIndexer.updateIndex(context, timestamp);
+            }
         }
     }
 
@@ -553,13 +603,13 @@ public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T>
      * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest)
      */
     @Override
-    protected ITmfContext armRequest(final ITmfDataRequest<T> request) {
-        if ((request instanceof ITmfEventRequest<?>)
-            && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime())
+    protected ITmfContext armRequest(final ITmfDataRequest request) {
+        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;
 
         }
This page took 0.035109 seconds and 5 git commands to generate.