- Renamed a few classes in accordance with the model
authorFrancois Chouinard <fchouinard@gmail.com>
Thu, 27 Aug 2009 15:59:08 +0000 (15:59 +0000)
committerFrancois Chouinard <fchouinard@gmail.com>
Thu, 27 Aug 2009 15:59:08 +0000 (15:59 +0000)
- Augmented TmfDataRequest to support failure (not completed)
- Added dummy TmfExperiment, TmfTransform and TmfData

15 files changed:
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/request/TmfDataRequestTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/request/TmfRequestHandlerStub.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventStreamStub.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfComponent.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfTransform.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfViewer.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfData.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/ITmfRequestHandler.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/AbstractTmfEventStream.java [deleted file]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java

index 353d799f63f2309eb9f7b626dc856aaf7ba55a55..bbdcdc40b71c395681c54cb3a38dbde1f5aa333e 100644 (file)
@@ -102,7 +102,7 @@ public class TmfDataRequestTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -133,7 +133,7 @@ public class TmfDataRequestTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -165,7 +165,7 @@ public class TmfDataRequestTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -197,7 +197,7 @@ public class TmfDataRequestTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -231,7 +231,7 @@ public class TmfDataRequestTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
index d15aaa7ffea38f288864549972a3dc089d1a7045..f1e2c7cee01e7c74708fb2ddba5146967d47ab7a 100644 (file)
@@ -112,7 +112,7 @@ public class TmfTraceTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -142,7 +142,7 @@ public class TmfTraceTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
@@ -238,7 +238,7 @@ public class TmfTraceTest {
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
         final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
             @Override
-            public void handlePartialResult() {
+            public void handleData() {
                TmfEvent[] events = getData();
                 for (TmfEvent e : events) {
                     requestedEvents.add(e);
index 180caefb0212233988df57512974df2c99f0df5d..33f2f49deb92a164abf14409793b6066cbfe97d9 100644 (file)
@@ -76,7 +76,7 @@ public class TmfRequestHandlerStub implements ITmfRequestHandler<TmfEvent> {
                        TmfEvent[] result = new TmfEvent[events.size()];
                        events.toArray(result);
                        request.setData(result);
-                        request.handlePartialResult();
+                        request.handleData();
                         events.removeAllElements();
                     }
                     event = fStream.getNextEvent(context);
@@ -85,7 +85,7 @@ public class TmfRequestHandlerStub implements ITmfRequestHandler<TmfEvent> {
                events.toArray(result);
 
                request.setData(result);
-                request.handlePartialResult();
+                request.handleData();
                 request.done();
             }
         };
index c9d75271597fa16e78d7033982503b25c435bc31..041ec5df66aee25a5f27f48439b31350c5669c84 100644 (file)
@@ -17,7 +17,7 @@ import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.util.Map;
 
-import org.eclipse.linuxtools.tmf.stream.AbstractTmfEventStream;
+import org.eclipse.linuxtools.tmf.stream.TmfEventStream;
 import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
 
 /**
@@ -25,7 +25,7 @@ import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
  * <p>
  * TODO: Implement me. Please.
  */
-public class TmfEventStreamStub extends AbstractTmfEventStream {
+public class TmfEventStreamStub extends TmfEventStream {
 
     // ========================================================================
     // Attributes
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfComponent.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfComponent.java
new file mode 100644 (file)
index 0000000..70e3a3c
--- /dev/null
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfComponent</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfComponent {
+
+}
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfTransform.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfTransform.java
new file mode 100644 (file)
index 0000000..73c83bc
--- /dev/null
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfTransform</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfTransform extends TmfComponent {
+
+       /**
+        * 
+        */
+       public void transformData() {
+       }
+}
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfViewer.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfViewer.java
new file mode 100644 (file)
index 0000000..d4ddc7a
--- /dev/null
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfViewer</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfViewer extends TmfComponent {
+
+}
index 1576c01170b6de52c6bfe1e03c6a80a9368ad198..b63d9bdeafbadfc1e5bbd454f32c9ef8bf83ea77 100644 (file)
@@ -17,9 +17,9 @@ package org.eclipse.linuxtools.tmf.event;
  * <p>
  * This is just an empty base class for the data meant to navigate in the
  * framework.
+ * <p>
+ * TODO: Implement me. Please.
  */
 public abstract class TmfData {
 
-       public abstract boolean isNullRef();
-
 }
index a60790f7e4a0390e16509d74fdeb1244bc5729be..4c9e0efebfa7ed333e81c420629a261a871aea57 100644 (file)
@@ -26,7 +26,7 @@ package org.eclipse.linuxtools.tmf.event;
  * used as e.g. a location marker in the event stream to distinguish between
  * otherwise identical events.
  */
-public class TmfEvent {
+public class TmfEvent extends TmfData {
 
     // ========================================================================
     // Attributes
index 5026983316ca2acf010d0f14a5c4079cfd4e8c67..2121336f4f483a870018fe58db1153d85a7a1993 100644 (file)
@@ -25,7 +25,7 @@ public interface ITmfRequestHandler<T> {
      * request is completed (e.g. for a specific range of events) or it
      * can choose to process the events asynchronously (e.g. for streaming).
      * 
-     * @param waitForCompletion Suspend the client thread until the request completes or is cancelled 
+     * @param waitForCompletion Suspend the client thread until the request completes 
      */
     public void processRequest(TmfDataRequest<T> request, boolean waitForCompletion);
 
index 75c8576ad5982d7ae7514063e9a97ad31c811b80..86a40277629bc741c99e6bd3d870721f03eaa302 100644 (file)
@@ -38,13 +38,24 @@ import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
  * Typical usage:
  *<pre><code><i>TmfTimeWindow range = new TmfTimewindow(...);
  *TmfDataRequest&lt;DataType[]&gt; request = new TmfDataRequest&lt;DataType[]&gt;(range, 0, NB_EVENTS, BLOCK_SIZE) {
- *    &#64;Override
- *    public void handlePartialResult() {
+ *    public void handleData() {
  *         DataType[] data = request.getData();
  *         for (DataType e : data) {
  *             // do something
  *         }
  *    }
+ *    public void handleSuccess() {
+ *         // do something
+ *         }
+ *    }
+ *    public void handleFailure() {
+ *         // do something
+ *         }
+ *    }
+ *    public void handleCancel() {
+ *         // do something
+ *         }
+ *    }
  *};
  *fProcessor.process(request, true);
  *</i></code></pre>
@@ -53,6 +64,8 @@ import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
  * The main issue is the slicing of the result in blocks and continuous
  * streams. This would require using a thread executor and to carefully
  * look at setData() and getData().
+ * 
+ * TODO: Implement request failures (codes, etc...)
  */
 public class TmfDataRequest<V> {
 
@@ -70,7 +83,7 @@ public class TmfDataRequest<V> {
     // Attributes
     // ========================================================================
 
-    private final TmfTimeRange fRange;     // The requested events timestamp range
+    private final TmfTimeRange fRange;      // The requested events timestamp range
     private final int  fIndex;              // The event index to get
     private final long fOffset;             // The synchronization offset to apply
     private final int  fNbRequestedItems;   // The number of items to read (-1 == the whole range)
@@ -78,6 +91,7 @@ public class TmfDataRequest<V> {
 
     private Object lock = new Object();
     private boolean fRequestCompleted = false;
+    private boolean fRequestFailed    = false;
     private boolean fRequestCanceled  = false;
 
     private V[] fData; // Data object
@@ -174,6 +188,13 @@ public class TmfDataRequest<V> {
         return fRequestCompleted;
     }
 
+    /**
+     * @return indicates if the request is canceled
+     */
+    public boolean isFailed() {
+        return fRequestFailed;
+    }
+
     /**
      * @return indicates if the request is canceled
      */
@@ -202,7 +223,8 @@ public class TmfDataRequest<V> {
     }
     
     /**
-     * handlePartialResult()
+     * Handle a block of incoming data. This method is called every time
+     * a block of data becomes available.
      * 
      * - Data items are received in the order they appear in the stream.
      * - Called by the request processor, in its execution thread, every time a
@@ -215,10 +237,36 @@ public class TmfDataRequest<V> {
      *
      * @param events - an array of events
      */
-    public void handlePartialResult() {
+    public void handleData() {
     }
 
+    /**
+     * Handle the completion of the request. It is called when there is no more
+     * data available either because:
+     * - the request completed normally
+     * - the request failed
+     * - the request was canceled
+     * 
+     * As a convenience, handleXXXX methods are provided. They are meant to be
+     * overridden by the application if it needs to handle these conditions. 
+     */
     public void handleCompleted() {
+       if (fRequestFailed) { 
+               handleFailure();
+       }
+       else if (fRequestCanceled) {
+               handleCancel();
+       }
+       handleSuccess();
+    }
+
+    public void handleSuccess() {
+    }
+
+    public void handleFailure() {
+    }
+
+    public void handleCancel() {
     }
 
     /**
@@ -239,7 +287,7 @@ public class TmfDataRequest<V> {
     }
 
     /**
-     * Complete the request. Called by the request processor upon completion.
+     * Called by the request processor upon completion.
      */
     public void done() {
         synchronized(lock) {
@@ -250,13 +298,22 @@ public class TmfDataRequest<V> {
     }
 
     /**
-     * Cancel the request.
+     * Called by the request processor upon failure.
+     */
+    public void fail() {
+        synchronized(lock) {
+            fRequestFailed = true;
+            done();
+        }
+    }
+
+    /**
+     * Called by the request processor upon cancellation.
      */
     public void cancel() {
         synchronized(lock) {
             fRequestCanceled = true;
-            fRequestCompleted = true;
-            lock.notify();
+            done();
         }
     }
 
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/AbstractTmfEventStream.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/AbstractTmfEventStream.java
deleted file mode 100644 (file)
index d211bb4..0000000
+++ /dev/null
@@ -1,361 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Vector;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;
-
-/**
- * <b><u>AbstractTmfEventStream</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public abstract class AbstractTmfEventStream implements ITmfEventStream {
-
-    // ========================================================================
-    // Constants
-    // ========================================================================
-
-    // The default number of events to cache
-    public static final int DEFAULT_CACHE_SIZE = 1000;
-
-    // ========================================================================
-    // Attributes
-    // ========================================================================
-
-    // The stream name
-    private final String fName;
-
-    // The stream parser
-    private final ITmfEventParser fParser;
-
-    // The cache size
-    private final int fCacheSize;
-
-    // The set of event stream checkpoints (for random access)
-    private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
-
-    // The number of events collected
-    private int fNbEvents = 0;
-
-    // The time span of the event stream
-    private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
-
-    // The listeners
-    private Set<TmfTrace> fListeners = new HashSet<TmfTrace>();
-
-    // ========================================================================
-    // Constructors
-    // ========================================================================
-
-    /**
-     * @param filename
-     * @param parser
-     * @param cacheSize
-     * @throws FileNotFoundException
-     */
-    protected AbstractTmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
-       fName = filename;
-        fParser = parser;
-        fCacheSize = cacheSize;
-    }
-
-    /**
-     * @param filename
-     * @param parser
-     * @throws FileNotFoundException
-     */
-    protected AbstractTmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
-       this(filename, parser, DEFAULT_CACHE_SIZE);
-    }
-
-    // ========================================================================
-    // Accessors
-    // ========================================================================
-
-    /**
-     * @return
-     */
-    public int getCacheSize() {
-        return fCacheSize;
-    }
-
-    /**
-     * @return
-     */
-    public String getName() {
-        return fName;
-    }
-
-    /**
-     * @return
-     */
-    public synchronized int getNbEvents() {
-        return fNbEvents;
-    }
-
-    /**
-     * @return
-     */
-    public synchronized TmfTimeRange getTimeRange() {
-        return fTimeRange;
-    }
-
-    // ========================================================================
-    // Operators
-    // ========================================================================
-
-    public StreamContext seekEvent(TmfTimestamp timestamp) {
-
-        // First, find the right checkpoint
-       int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
-
-        // In the very likely event that the checkpoint was not found, bsearch
-        // returns its negated would-be location (not an offset...). From that
-        // index, we can then position the stream and get the event.
-        if (index < 0) {
-            index = Math.max(0, -(index + 2));
-        }
-
-        // Position the stream at the checkpoint
-        Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
-        StreamContext nextEventContext;
-        synchronized(this) {
-               nextEventContext = seekLocation(location);
-        }
-        StreamContext currentEventContext = new StreamContext(nextEventContext.location);
-
-        // And get the event
-        TmfEvent event = getNextEvent(nextEventContext);
-        while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
-               currentEventContext.location = nextEventContext.location;
-               event = getNextEvent(nextEventContext);
-        }
-
-        return currentEventContext;
-    }
-
-    public StreamContext seekEvent(int position) {
-
-        // Position the stream at the previous checkpoint
-        int index = position / fCacheSize;
-        Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
-        StreamContext nextEventContext;
-        synchronized(this) {
-               nextEventContext = seekLocation(location);
-        }
-        StreamContext currentEventContext = new StreamContext(nextEventContext.location);
-
-        // And locate the event (if it exists)
-        int current = index * fCacheSize;
-        TmfEvent event = getNextEvent(nextEventContext);
-        while (event != null && current < position) {
-               currentEventContext.location = nextEventContext.location;
-               event = getNextEvent(nextEventContext);
-            current++;
-        }
-
-        return currentEventContext;
-    }
-
-    public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
-
-       // Position the stream and update the context object
-       StreamContext ctx = seekEvent(timestamp);
-       context.location = ctx.location; 
-
-        return getNextEvent(context);
-    }
-
-    public TmfEvent getEvent(StreamContext context, int position) {
-
-       // Position the stream and update the context object
-       StreamContext ctx = seekEvent(position);
-       context.location = ctx.location; 
-
-        return getNextEvent(context);
-    }
-
-    public synchronized TmfEvent getNextEvent(StreamContext context) {
-        try {
-               seekLocation(context.location);
-               TmfEvent event = fParser.getNextEvent(this);
-               context.location = getCurrentLocation();
-               return event;
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-       public synchronized void addListener(TmfTrace listener) {
-               fListeners.add(listener);
-       }
-
-       public synchronized void removeListener(TmfTrace listener) {
-               fListeners.remove(listener);
-       }
-
-       private synchronized void notifyListeners() {
-               for (TmfTrace listener : fListeners) {
-                       listener.handleEvent(new TmfStreamUpdateEvent(this));
-               }
-       }
-   
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
-     */
-    public void indexStream(boolean waitForCompletion) {
-       IndexingJob job = new IndexingJob(fName);
-       job.schedule();
-        if (waitForCompletion) {
-            try {
-                               job.join();
-                       } catch (InterruptedException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }
-        }
-    }
-
-    private class IndexingJob extends Job {
-
-               public IndexingJob(String name) {
-                       super(name);
-               }
-
-               /* (non-Javadoc)
-                * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
-                */
-               @Override
-               protected IStatus run(IProgressMonitor monitor) {
-
-            int nbEvents = 0;
-            TmfTimestamp startTime = new TmfTimestamp();
-            TmfTimestamp lastTime  = new TmfTimestamp();
-
-            monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
-
-            try {
-                StreamContext nextEventContext;
-                synchronized(this) {
-                       nextEventContext = seekLocation(null);
-                }
-                StreamContext currentEventContext = new StreamContext(nextEventContext.location);
-                TmfEvent event = getNextEvent(nextEventContext);
-                if (event != null) {
-                       startTime = event.getTimestamp();
-                       lastTime  = event.getTimestamp();
-                }
-
-                while (event != null) {
-                    lastTime = event.getTimestamp();
-                    if ((nbEvents++ % fCacheSize) == 0) {
-                        TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
-                        synchronized(this) {
-                               fCheckpoints.add(bookmark);
-                               fNbEvents = nbEvents;
-                            fTimeRange = new TmfTimeRange(startTime, lastTime);
-                        }
-                        notifyListeners();
-                        monitor.worked(1);
-                        // Check monitor *after* fCheckpoints has been updated
-                        if (monitor.isCanceled()) {
-                               return Status.CANCEL_STATUS;
-                        }
-                    }
-
-                       currentEventContext.location = nextEventContext.location;
-                                       event = getNextEvent(nextEventContext);
-                }
-            }
-            finally {
-                synchronized(this) {
-                       fNbEvents = nbEvents;
-                       fTimeRange = new TmfTimeRange(startTime, lastTime);
-                }
-                notifyListeners();
-                monitor.done();
-            }
-
-                       return Status.OK_STATUS;
-               }
-    }
-
-    public void indexStream(final String filename) {
-
-//        ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
-//        try {
-//            dialog.run(true, true, new IRunnableWithProgress() {
-//                @Override
-//                public void run(IProgressMonitor monitor)
-//                        throws InvocationTargetException, InterruptedException {
-//                    monitor.beginTask("Indexing " + filename,
-//                            IProgressMonitor.UNKNOWN);
-//
-//                    try {
-//                        seekLocation(null);
-//                        TmfTimestamp startTime = new TmfTimestamp();
-//                        TmfTimestamp lastTime = new TmfTimestamp();
-//                        Object location = getCurrentLocation();
-//
-//                        TmfEvent event = getNextEvent();
-//                        if (event != null) {
-//                            startTime = event.getTimestamp();
-//                            while (event != null) {
-//                                lastTime = event.getTimestamp();
-//                                if ((fNbEvents++ % fCacheSize) == 0) {
-//                                    if (monitor.isCanceled()) {
-//                                        throw new CancellationException();
-//                                    }
-//                                    TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(
-//                                            lastTime, location);
-//                                    fCheckpoints.add(bookmark);
-//                                    monitor.worked(1);
-//                                }
-//                                location = getCurrentLocation();
-//                                event = getNextEvent();
-//                            }
-//                            fTimeRange = new TmfTimeRange(startTime, lastTime);
-//                        }
-//                        seekLocation(null);
-//                    } catch (IOException e) {
-//                    } finally {
-//                        monitor.done();
-//                    }
-//                }
-//
-//            });
-//        } catch (InvocationTargetException e1) {
-//            // TODO Auto-generated catch block
-//            e1.printStackTrace();
-//        } catch (InterruptedException e1) {
-//            // TODO Auto-generated catch block
-//            e1.printStackTrace();
-//        }
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/stream/TmfEventStream.java
new file mode 100644 (file)
index 0000000..925eddb
--- /dev/null
@@ -0,0 +1,308 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
+
+/**
+ * <b><u>TmfEventStream</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfEventStream implements ITmfEventStream {
+
+    // ========================================================================
+    // Constants
+    // ========================================================================
+
+    // The default number of events to cache
+    public static final int DEFAULT_CACHE_SIZE = 1000;
+
+    // ========================================================================
+    // Attributes
+    // ========================================================================
+
+    // The stream name
+    private final String fName;
+
+    // The stream parser
+    private final ITmfEventParser fParser;
+
+    // The cache size
+    private final int fCacheSize;
+
+    // The set of event stream checkpoints (for random access)
+    private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
+
+    // The number of events collected
+    private int fNbEvents = 0;
+
+    // The time span of the event stream
+    private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
+
+    // The listeners
+    private Set<TmfTrace> fListeners = new HashSet<TmfTrace>();
+
+    // ========================================================================
+    // Constructors
+    // ========================================================================
+
+    /**
+     * @param filename
+     * @param parser
+     * @param cacheSize
+     * @throws FileNotFoundException
+     */
+    protected TmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
+       fName = filename;
+        fParser = parser;
+        fCacheSize = cacheSize;
+    }
+
+    /**
+     * @param filename
+     * @param parser
+     * @throws FileNotFoundException
+     */
+    protected TmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
+       this(filename, parser, DEFAULT_CACHE_SIZE);
+    }
+
+    // ========================================================================
+    // Accessors
+    // ========================================================================
+
+    /**
+     * @return
+     */
+    public int getCacheSize() {
+        return fCacheSize;
+    }
+
+    /**
+     * @return
+     */
+    public String getName() {
+        return fName;
+    }
+
+    /**
+     * @return
+     */
+    public synchronized int getNbEvents() {
+        return fNbEvents;
+    }
+
+    /**
+     * @return
+     */
+    public synchronized TmfTimeRange getTimeRange() {
+        return fTimeRange;
+    }
+
+    // ========================================================================
+    // Operators
+    // ========================================================================
+
+    public StreamContext seekEvent(TmfTimestamp timestamp) {
+
+        // First, find the right checkpoint
+       int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
+
+        // In the very likely event that the checkpoint was not found, bsearch
+        // returns its negated would-be location (not an offset...). From that
+        // index, we can then position the stream and get the event.
+        if (index < 0) {
+            index = Math.max(0, -(index + 2));
+        }
+
+        // Position the stream at the checkpoint
+        Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+        StreamContext nextEventContext;
+        synchronized(this) {
+               nextEventContext = seekLocation(location);
+        }
+        StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+        // And get the event
+        TmfEvent event = getNextEvent(nextEventContext);
+        while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
+               currentEventContext.location = nextEventContext.location;
+               event = getNextEvent(nextEventContext);
+        }
+
+        return currentEventContext;
+    }
+
+    public StreamContext seekEvent(int position) {
+
+        // Position the stream at the previous checkpoint
+        int index = position / fCacheSize;
+        Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+        StreamContext nextEventContext;
+        synchronized(this) {
+               nextEventContext = seekLocation(location);
+        }
+        StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+        // And locate the event (if it exists)
+        int current = index * fCacheSize;
+        TmfEvent event = getNextEvent(nextEventContext);
+        while (event != null && current < position) {
+               currentEventContext.location = nextEventContext.location;
+               event = getNextEvent(nextEventContext);
+            current++;
+        }
+
+        return currentEventContext;
+    }
+
+    public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
+
+       // Position the stream and update the context object
+       StreamContext ctx = seekEvent(timestamp);
+       context.location = ctx.location; 
+
+        return getNextEvent(context);
+    }
+
+    public TmfEvent getEvent(StreamContext context, int position) {
+
+       // Position the stream and update the context object
+       StreamContext ctx = seekEvent(position);
+       context.location = ctx.location; 
+
+        return getNextEvent(context);
+    }
+
+    public synchronized TmfEvent getNextEvent(StreamContext context) {
+        try {
+               seekLocation(context.location);
+               TmfEvent event = fParser.getNextEvent(this);
+               context.location = getCurrentLocation();
+               return event;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+       public synchronized void addListener(TmfTrace listener) {
+               fListeners.add(listener);
+       }
+
+       public synchronized void removeListener(TmfTrace listener) {
+               fListeners.remove(listener);
+       }
+
+       private synchronized void notifyListeners() {
+               for (TmfTrace listener : fListeners) {
+                       listener.handleEvent(new TmfStreamUpdateEvent(this));
+               }
+       }
+   
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
+     */
+    public void indexStream(boolean waitForCompletion) {
+       IndexingJob job = new IndexingJob(fName);
+       job.schedule();
+        if (waitForCompletion) {
+            try {
+                               job.join();
+                       } catch (InterruptedException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+        }
+    }
+
+    private class IndexingJob extends Job {
+
+               public IndexingJob(String name) {
+                       super(name);
+               }
+
+               /* (non-Javadoc)
+                * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+                */
+               @Override
+               protected IStatus run(IProgressMonitor monitor) {
+
+            int nbEvents = 0;
+            TmfTimestamp startTime = new TmfTimestamp();
+            TmfTimestamp lastTime  = new TmfTimestamp();
+
+            monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
+
+            try {
+                StreamContext nextEventContext;
+                synchronized(this) {
+                       nextEventContext = seekLocation(null);
+                }
+                StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+                TmfEvent event = getNextEvent(nextEventContext);
+                if (event != null) {
+                       startTime = event.getTimestamp();
+                       lastTime  = event.getTimestamp();
+                }
+
+                while (event != null) {
+                    lastTime = event.getTimestamp();
+                    if ((nbEvents++ % fCacheSize) == 0) {
+                        TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
+                        synchronized(this) {
+                               fCheckpoints.add(bookmark);
+                               fNbEvents = nbEvents;
+                            fTimeRange = new TmfTimeRange(startTime, lastTime);
+                        }
+                        notifyListeners();
+                        monitor.worked(1);
+                        // Check monitor *after* fCheckpoints has been updated
+                        if (monitor.isCanceled()) {
+                               return Status.CANCEL_STATUS;
+                        }
+                    }
+
+                       currentEventContext.location = nextEventContext.location;
+                                       event = getNextEvent(nextEventContext);
+                }
+            }
+            finally {
+                synchronized(this) {
+                       fNbEvents = nbEvents;
+                       fTimeRange = new TmfTimeRange(startTime, lastTime);
+                }
+                notifyListeners();
+                monitor.done();
+            }
+
+                       return Status.OK_STATUS;
+               }
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java
new file mode 100644 (file)
index 0000000..7512ca0
--- /dev/null
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+
+/**
+ * <b><u>TmfExperiment</u></b>
+ * <p>
+ * TmfExperiment presents a time-ordered, unified view of a set of 
+ * TmfTraces that are part of a tracing experiment. 
+ * <p>
+ * TODO: Implement me. PLease.
+ */
+public class TmfExperiment implements ITmfRequestHandler<TmfEvent> {
+
+    // ========================================================================
+    // Attributes
+    // ========================================================================
+
+    // ========================================================================
+    // Constructors/Destructors
+    // ========================================================================
+
+    public TmfExperiment() {
+    }
+
+    // ========================================================================
+    // Accessors
+    // ========================================================================
+
+    // ========================================================================
+    // Operators
+    // ========================================================================
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
+     */
+    public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+    }
+
+    // ========================================================================
+    // Helper functions
+    // ========================================================================
+
+}
index 298b7bbd243564714696bb13c87f22800d0fa3a3..89a65d6cb22102b3bed82a52e14065e2917bb403 100644 (file)
@@ -26,9 +26,9 @@ import org.eclipse.linuxtools.tmf.stream.TmfStreamUpdateEvent;
 import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
 
 /**
- * <b><u>TmfEventLog</u></b>
+ * <b><u>TmfTrace</u></b>
  * <p>
- * TmfEventLog represents a time-ordered set of events tied to a single event
+ * TmfTrace represents a time-ordered set of events tied to a single event
  * stream. It keeps track of the global information about the event log:
  * <ul>
  * <li> the epoch, a reference timestamp for the whole log (t0)
@@ -165,7 +165,7 @@ public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
                        TmfEvent[] result = new TmfEvent[events.size()];
                        events.toArray(result);
                        request.setData(result);
-                        request.handlePartialResult();
+                        request.handleData();
                         events.removeAllElements();
                     }
                     // To avoid an unnecessary read passed the last event requested 
@@ -176,7 +176,7 @@ public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
                events.toArray(result);
                request.setData(result);
 
-               request.handlePartialResult();
+               request.handleData();
                 request.done();
             }
         };
@@ -211,7 +211,7 @@ public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
                        TmfEvent[] result = new TmfEvent[events.size()];
                        events.toArray(result);
                        request.setData(result);
-                        request.handlePartialResult();
+                        request.handleData();
                         events.removeAllElements();
                     }
                     // To avoid an unnecessary read passed the last event requested 
@@ -222,7 +222,7 @@ public class TmfTrace implements ITmfRequestHandler<TmfEvent> {
                events.toArray(result);
 
                request.setData(result);
-                request.handlePartialResult();
+                request.handleData();
                 request.done();
             }
         };
This page took 0.041123 seconds and 5 git commands to generate.