Refactor TmfRequest
authorFrancois Chouinard <fchouinard@gmail.com>
Tue, 8 Jan 2013 23:55:18 +0000 (18:55 -0500)
committerFrancois Chouinard <fchouinard@gmail.com>
Wed, 9 Jan 2013 00:14:12 +0000 (19:14 -0500)
Change-Id: I72480990880adae6036e5d5c74966f250a46a6c2
Signed-off-by: Francois Chouinard <fchouinard@gmail.com>
Reviewed-on: https://git.eclipse.org/r/9501
Tested-by: Hudson CI
56 files changed:
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfEventProviderTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfProviderManagerTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfBlockFilterTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedRequestTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfDataRequestTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventRequestTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventTypeFilterTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRangeFilterTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestExecutorTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfSyntheticEventProviderStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/request/TmfDataRequestStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/request/TmfEventRequestStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/request/TmfRequestStub.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEventParserStub.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/TmfCoreTracer.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/component/TmfEventThread.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedDataRequest.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedRequest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfRequestExecutor.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/ITmfDataProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/ITmfEventProvider.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfDataProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/ITmfDataRequest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/ITmfEventRequest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/ITmfRequest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfBlockFilter.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfDataRequest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfEventRequest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfEventTypeFilter.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRangeFilter.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRequest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/uml2sd/trace/TmfUml2SDTestTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/loader/TmfUml2SDSyncLoader.java

index 3854007fb1385e32f03d70d6c3beeb3771dfd2f0..77f8f2ad9b00beb574bfc0705100fcc3d1b349ba 100644 (file)
@@ -17,7 +17,7 @@ import java.util.Vector;
 import junit.framework.TestCase;
 
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
@@ -73,7 +73,7 @@ public class TmfEventProviderTest extends TestCase {
 
         // There should be 2 TmfEvent providers: a TmfTraceStub and a
         // TmfEventProviderStub
-        ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class);
+        ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class);
         assertEquals("getProviders", 2, eventProviders.length);
 
         eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
@@ -101,13 +101,13 @@ public class TmfEventProviderTest extends TestCase {
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         // Get the TmfSyntheticEventStub provider
-        ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class,
-                TmfEventProviderStub.class);
-        ITmfDataProvider provider = eventProviders[0];
+        ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
+        ITmfEventProvider provider = eventProviders[0];
 
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
         final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
             @Override
+            @SuppressWarnings("deprecation")
             public void handleData(ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
@@ -145,15 +145,15 @@ public class TmfEventProviderTest extends TestCase {
         final Vector<ITmfEvent> requestedEventsReq2 = new Vector<ITmfEvent>();
 
         // Get the TmfSyntheticEventStub provider
-        ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class,
-                TmfEventProviderStub.class);
-        ITmfDataProvider provider = eventProviders[0];
+        ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
+        ITmfEventProvider provider = eventProviders[0];
 
         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
 
         // Create first request
         final TmfEventRequest request1 = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
             @Override
+            @SuppressWarnings("deprecation")
             public void handleData(ITmfEvent event) {
                 super.handleData(event);
                 requestedEventsReq1.add(event);
@@ -181,6 +181,7 @@ public class TmfEventProviderTest extends TestCase {
         // Create second request
         final TmfEventRequest request2 = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
             @Override
+            @SuppressWarnings("deprecation")
             public void handleData(ITmfEvent event) {
                 super.handleData(event);
                 requestedEventsReq2.add(event);
@@ -248,13 +249,13 @@ public class TmfEventProviderTest extends TestCase {
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         // Get the event provider
-        ITmfDataProvider[] eventProviders = TmfProviderManager
-                .getProviders(TmfSyntheticEventStub.class);
-        ITmfDataProvider provider = eventProviders[0];
+        ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfSyntheticEventStub.class);
+        ITmfEventProvider provider = eventProviders[0];
 
         final TmfEventRequest request = new TmfEventRequest(TmfSyntheticEventStub.class, range,
                 nbEvents, blockSize) {
             @Override
+            @SuppressWarnings("deprecation")
             public void handleData(ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
@@ -365,7 +366,7 @@ public class TmfEventProviderTest extends TestCase {
 
         // There should be 2 TmfEvent providers: a TmfTraceStub and a
         // TmfEventProviderStub
-        ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class);
+        ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class);
         assertEquals("getProviders", 2, eventProviders.length);
 
         eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
index 4f9c425f1739e84c2cc5c1560838d68a4646cb68..fb32a3efa12650ccd4cc8fe82fef852f4e4796b9 100644 (file)
@@ -18,7 +18,7 @@ import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
 import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
 /**
@@ -26,7 +26,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
  * <p>
  * Test suite for the TmfProviderManager class.
  */
-@SuppressWarnings({ "nls" })
+@SuppressWarnings("nls")
 public class TmfProviderManagerTest extends TestCase {
 
        /**
@@ -54,8 +54,8 @@ public class TmfProviderManagerTest extends TestCase {
                public TestProvider1(Class<TmfEvent> type) {
                        super("TestProvider1", type);
                }
-               @Override
-               public ITmfContext armRequest(ITmfDataRequest request) {
+        @Override
+               public ITmfContext armRequest(ITmfRequest request) {
                        return null;
                }
                @Override
@@ -63,7 +63,7 @@ public class TmfProviderManagerTest extends TestCase {
                        return null;
                }
                @Override
-               public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
+               public boolean isCompleted(ITmfRequest request, ITmfEvent data, int nbRead) {
                        return false;
                }
        }
@@ -73,7 +73,7 @@ public class TmfProviderManagerTest extends TestCase {
                        super("TestProvider2", type);
                }
                @Override
-               public ITmfContext armRequest(ITmfDataRequest request) {
+               public ITmfContext armRequest(ITmfRequest request) {
                        return null;
                }
                @Override
@@ -81,7 +81,7 @@ public class TmfProviderManagerTest extends TestCase {
                        return null;
                }
                @Override
-               public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
+               public boolean isCompleted(ITmfRequest request, ITmfEvent data, int nbRead) {
                        return false;
                }
        }
@@ -98,7 +98,7 @@ public class TmfProviderManagerTest extends TestCase {
                        super("TestProvider3", type);
                }
                @Override
-               public ITmfContext armRequest(ITmfDataRequest request) {
+               public ITmfContext armRequest(ITmfRequest request) {
                        return null;
                }
                @Override
@@ -106,7 +106,7 @@ public class TmfProviderManagerTest extends TestCase {
                        return null;
                }
                @Override
-               public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
+               public boolean isCompleted(ITmfRequest request, ITmfEvent data, int nbRead) {
                        return false;
                }
        }
index c9adc374e2986ffccee1be851bea0f455081335c..9cb522ae0a96bcaf9ada694ea5e3ca115a477a76 100644 (file)
@@ -83,8 +83,8 @@ public class RequestBenchmark extends TmfEventRequest {
     }
 
     @Override
-    public void handleData(final ITmfEvent event) {
-        super.handleData(event);
+    public synchronized void handleEvent(final ITmfEvent event) {
+        super.handleEvent(event);
         nbEvent++;
 
     }
@@ -92,7 +92,7 @@ public class RequestBenchmark extends TmfEventRequest {
     static long prev;
     static long done = 0;
     @Override
-    public void handleCompleted() {
+    public synchronized void handleCompleted() {
         final long next = System.nanoTime();
         double val = next - prev;
         final int nbEvent2 = nbEvent;
index e6d2e3561d6c4faf6539e3ace823ce0c25228232..92c299c128edd877196bbbbd3e878de06ef6474d 100644 (file)
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
 package org.eclipse.linuxtools.tmf.core.tests.request;
 
 import junit.framework.Test;
@@ -8,7 +20,7 @@ import org.eclipse.linuxtools.internal.tmf.core.Activator;
 /**
  * <b><u>AllTests</u></b>
  * <p>
- * Implement me. Please.
+ * Test suite for the package o.e.l.tmf.core.request
  * <p>
  */
 @SuppressWarnings({ "nls" })
@@ -20,10 +32,13 @@ public class AllTests {
        public static Test suite() {
                TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".request"); //$NON-NLS-1$);
                //$JUnit-BEGIN$
+        suite.addTestSuite(TmfBlockFilterTest.class);
+        suite.addTestSuite(TmfRangeFilterTest.class);
+        suite.addTestSuite(TmfEventTypeFilterTest.class);
+        suite.addTestSuite(TmfRequestTest.class);
+        suite.addTestSuite(TmfCoalescedRequestTest.class);
                suite.addTestSuite(TmfDataRequestTest.class);
                suite.addTestSuite(TmfEventRequestTest.class);
-               suite.addTestSuite(TmfCoalescedDataRequestTest.class);
-               suite.addTestSuite(TmfCoalescedEventRequestTest.class);
                suite.addTestSuite(TmfRequestExecutorTest.class);
                //$JUnit-END$
                return suite;
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfBlockFilterTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfBlockFilterTest.java
new file mode 100644 (file)
index 0000000..5c2eadd
--- /dev/null
@@ -0,0 +1,245 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.request;
+
+import junit.framework.TestCase;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfBlockFilter;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfBlockFilterTest</u></b>
+ * <p>
+ * Test suite for the TmfBlockFilter class.
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfBlockFilterTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final long ALL_EVENTS = ITmfRequest.ALL_EVENTS;
+
+    // ------------------------------------------------------------------------
+       // Housekeeping
+       // ------------------------------------------------------------------------
+
+    /**
+     * @param name the test name
+     */
+       public TmfBlockFilterTest(String name) {
+               super(name);
+       }
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+    // ------------------------------------------------------------------------
+       // Constructors
+       // ------------------------------------------------------------------------
+
+       @Test
+       public void testTmfBlockFilter() {
+           TmfBlockFilter filter = TmfBlockFilter.ALL_EVENTS;
+        assertEquals("getStartIndex",           0, filter.getStartIndex());
+        assertEquals("getEndIndex",    ALL_EVENTS, filter.getEndIndex());
+        assertEquals("getNbRequested", ALL_EVENTS, filter.getNbRequested());
+
+        filter = new TmfBlockFilter(0, 1000);
+        assertEquals("getStartIndex",     0, filter.getStartIndex());
+        assertEquals("getEndIndex",    1000, filter.getEndIndex());
+        assertEquals("getNbRequested", 1000, filter.getNbRequested());
+
+        filter = new TmfBlockFilter(-1, 1000);
+        assertEquals("getStartIndex",     0, filter.getStartIndex());
+        assertEquals("getEndIndex",    1000, filter.getEndIndex());
+        assertEquals("getNbRequested", 1000, filter.getNbRequested());
+
+        filter = new TmfBlockFilter(0, -1);
+        assertEquals("getStartIndex",           0, filter.getStartIndex());
+        assertEquals("getEndIndex",    ALL_EVENTS, filter.getEndIndex());
+        assertEquals("getNbRequested", ALL_EVENTS, filter.getNbRequested());
+
+        filter = new TmfBlockFilter(1000, ALL_EVENTS);
+        assertEquals("getStartIndex",        1000, filter.getStartIndex());
+        assertEquals("getEndIndex",    ALL_EVENTS, filter.getEndIndex());
+        assertEquals("getNbRequested", ALL_EVENTS, filter.getNbRequested());
+       }
+
+    @Test
+    public void testTmfBlockFilterCopy() {
+        TmfBlockFilter filter1 = new TmfBlockFilter(0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(filter1);
+
+        assertEquals("getStartIndex",  filter1.getStartIndex(),  filter2.getStartIndex());
+        assertEquals("getEndIndex",    filter1.getEndIndex(),    filter2.getEndIndex());
+        assertEquals("getNbRequested", filter1.getNbRequested(), filter2.getNbRequested());
+    }
+
+    // ------------------------------------------------------------------------
+       // equals
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(10, 1000);
+
+        assertEquals("equals", filter1, filter1);
+        assertEquals("equals", filter2, filter2);
+
+        assertFalse("equals", filter1.equals(filter2));
+        assertFalse("equals", filter2.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter3 = new TmfBlockFilter(10, 1000);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter1);
+
+        assertFalse("equals", filter1.equals(filter3));
+        assertFalse("equals", filter3.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        TmfBlockFilter filter1 = new TmfBlockFilter(0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(0, 1000);
+        TmfBlockFilter filter3 = new TmfBlockFilter(0, 1000);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter3);
+        assertEquals("equals", filter3, filter1);
+    }
+
+    @Test
+    public void testEqualsNull() {
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(10, 1000);
+
+        assertFalse("equals", filter1.equals(null));
+        assertFalse("equals", filter2.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(10, 1000);
+
+        assertEquals("hashCode", filter1.hashCode(), filter1.hashCode());
+        assertEquals("hashCode", filter2.hashCode(), filter2.hashCode());
+        assertFalse("hashCode",  filter1.hashCode() == filter2.hashCode());
+    }
+
+       // ------------------------------------------------------------------------
+       // toString
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(10, 2000);
+
+        String expected0 = "TmfBlockFilter [fStartIndex=0, fEndIndex=" + Long.MAX_VALUE + ", fNbRequested=" + Long.MAX_VALUE + "]";
+        String expected1 = "TmfBlockFilter [fStartIndex=0, fEndIndex=1000, fNbRequested=1000]";
+        String expected2 = "TmfBlockFilter [fStartIndex=10, fEndIndex=2010, fNbRequested=2000]";
+
+        assertEquals("toString", expected0, TmfBlockFilter.ALL_EVENTS.toString());
+        assertEquals("toString", expected1, filter1.toString());
+        assertEquals("toString", expected2, filter2.toString());
+    }
+
+    // ------------------------------------------------------------------------
+    // matches
+    // ------------------------------------------------------------------------
+
+    /**
+     * The only test that really matters...
+     */
+    @Test
+    public void testMatches() {
+
+        TmfBlockFilter filter1 = new TmfBlockFilter( 0, 1000);
+        TmfBlockFilter filter2 = new TmfBlockFilter(10, 2000);
+
+        ITmfEvent event = new TmfEvent(null, 0, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 5, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 9, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 10, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 999, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 1000, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 1999, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 2000, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 2009, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 2010, null, null, null, null, null);
+        assertTrue ("matches", TmfBlockFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java
deleted file mode 100644 (file)
index fcfbdcf..0000000
+++ /dev/null
@@ -1,510 +0,0 @@
-/*******************************************************************************
- * 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 - Added tests to check offsets
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.request;
-
-import junit.framework.TestCase;
-
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub;
-
-/**
- * Test suite for the TmfCoalescedDataRequest class.
- */
-@SuppressWarnings({"nls","javadoc"})
-public class TmfCoalescedDataRequestTest extends TestCase {
-
-       // ------------------------------------------------------------------------
-       // Variables
-       // ------------------------------------------------------------------------
-
-       private TmfCoalescedDataRequest fRequest1;
-       private TmfCoalescedDataRequest fRequest2;
-       private TmfCoalescedDataRequest fRequest3;
-       private TmfCoalescedDataRequest fRequest4;
-
-       private TmfCoalescedDataRequest fRequest1b;
-       private TmfCoalescedDataRequest fRequest1c;
-
-       private int fRequestCount;
-
-       // ------------------------------------------------------------------------
-       // Housekeeping
-       // ------------------------------------------------------------------------
-
-       /**
-        * @param name the test name
-        */
-       public TmfCoalescedDataRequestTest(final String name) {
-               super(name);
-       }
-
-    @Override
-       public void setUp() throws Exception {
-               super.setUp();
-               TmfDataRequest.reset();
-               fRequest1  = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-               fRequest2  = new TmfCoalescedDataRequest(TmfEvent.class, 20, 100, 200);
-               fRequest3  = new TmfCoalescedDataRequest(TmfEvent.class, 20, 200, 200);
-               fRequest4  = new TmfCoalescedDataRequest(TmfEvent.class, 20, 200, 300);
-
-               fRequest1b = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-               fRequest1c = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-
-               fRequestCount = fRequest1c.getRequestId() + 1;
-       }
-
-       @Override
-       public void tearDown() throws Exception {
-               super.tearDown();
-       }
-
-       private static TmfCoalescedDataRequest setupTestRequest(final boolean[] flags) {
-
-               TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200) {
-                   @Override
-                       public void handleCompleted() {
-                       super.handleCompleted();
-                       flags[0] = true;
-                   }
-                   @Override
-                   public void handleSuccess() {
-                       super.handleSuccess();
-                       flags[1] = true;
-                   }
-                   @Override
-                   public void handleFailure() {
-                       super.handleFailure();
-                       flags[2] = true;
-                   }
-                   @Override
-                   public void handleCancel() {
-                       super.handleCancel();
-                       flags[3] = true;
-                   }
-               };
-               return request;
-       }
-
-       // ------------------------------------------------------------------------
-       // Constructors
-       // ------------------------------------------------------------------------
-
-       public void testTmfCoalescedDataRequest() {
-               TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(TmfEvent.class);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getIndex", 0, request.getIndex());
-        assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedDataRequestIndex() {
-               TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(TmfEvent.class, 10);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getIndex", 10, request.getIndex());
-        assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedDataRequestIndexNbRequested() {
-               TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getIndex", 10, request.getIndex());
-        assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedDataRequestIndexNbEventsBlocksize() {
-               TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getIndex", 10, request.getIndex());
-        assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       // ------------------------------------------------------------------------
-       // equals
-       // ------------------------------------------------------------------------
-
-       public void testEqualsReflexivity() {
-        assertTrue("equals", fRequest1.equals(fRequest1));
-        assertTrue("equals", fRequest2.equals(fRequest2));
-
-        assertFalse("equals", fRequest1.equals(fRequest2));
-        assertFalse("equals", fRequest2.equals(fRequest1));
-       }
-
-       public void testEqualsSymmetry() {
-        assertTrue("equals", fRequest1.equals(fRequest1b));
-        assertTrue("equals", fRequest1b.equals(fRequest1));
-
-        assertFalse("equals", fRequest1.equals(fRequest3));
-        assertFalse("equals", fRequest2.equals(fRequest3));
-        assertFalse("equals", fRequest3.equals(fRequest1));
-        assertFalse("equals", fRequest3.equals(fRequest2));
-       }
-
-       public void testEqualsTransivity() {
-        assertTrue("equals", fRequest1.equals(fRequest1b));
-        assertTrue("equals", fRequest1b.equals(fRequest1c));
-        assertTrue("equals", fRequest1.equals(fRequest1c));
-       }
-
-       public void testEqualsNull() {
-        assertFalse("equals", fRequest1.equals(null));
-        assertFalse("equals", fRequest2.equals(null));
-       }
-
-       // ------------------------------------------------------------------------
-       // hashCode
-       // ------------------------------------------------------------------------
-
-       public void testHashCode() {
-        assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode());
-        assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode());
-               assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode());
-       }
-
-       // ------------------------------------------------------------------------
-       // toString
-       // ------------------------------------------------------------------------
-
-       public void testToString() {
-        String expected1 = "[TmfCoalescedDataRequest(0,ITmfEvent,10,100,200)]";
-        String expected2 = "[TmfCoalescedDataRequest(1,ITmfEvent,20,100,200)]";
-        String expected3 = "[TmfCoalescedDataRequest(2,ITmfEvent,20,200,200)]";
-        String expected4 = "[TmfCoalescedDataRequest(3,ITmfEvent,20,200,300)]";
-
-        assertEquals("toString", expected1, fRequest1.toString());
-        assertEquals("toString", expected2, fRequest2.toString());
-        assertEquals("toString", expected3, fRequest3.toString());
-        assertEquals("toString", expected4, fRequest4.toString());
-       }
-
-       // ------------------------------------------------------------------------
-       // isCompatible
-       // ------------------------------------------------------------------------
-
-       public void testIsCompatible() {
-               TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request1 = new TmfDataRequestStub(TmfEvent.class,  10, 100, 200);
-               TmfDataRequest request2 = new TmfDataRequestStub(TmfEvent.class,   5, 100, 200);
-        TmfDataRequest request3 = new TmfDataRequestStub(TmfEvent.class,   5,   4, 200);
-        TmfDataRequest request4 = new TmfDataRequestStub(TmfEvent.class,   5,   5, 200);
-        TmfDataRequest request5 = new TmfDataRequestStub(TmfEvent.class,  15, 100, 200);
-        TmfDataRequest request6 = new TmfDataRequestStub(TmfEvent.class, 100, 100, 200);
-        TmfDataRequest request7 = new TmfDataRequestStub(TmfEvent.class, 110, 100, 200);
-        TmfDataRequest request8 = new TmfDataRequestStub(TmfEvent.class, 111, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request1));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request2));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request3));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request4));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request5));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request6));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request7));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request8));
-
-        TmfDataRequest request9  = new TmfDataRequestStub(TmfEvent.class,   5,   3, 200);
-        TmfDataRequest request10 = new TmfDataRequestStub(TmfEvent.class, 112, 100, 200);
-
-        assertFalse("isCompatible", coalescedRequest.isCompatible(request9));
-        assertFalse("isCompatible", coalescedRequest.isCompatible(request10));
-       }
-
-    // ------------------------------------------------------------------------
-    // addRequest
-    // ------------------------------------------------------------------------
-
-    public void testAddRequest1() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",  10, coalescedRequest.getIndex());
-        assertEquals("addRequest", 100, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest2() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 5, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",   5, coalescedRequest.getIndex());
-        assertEquals("addRequest", 105, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest3() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 5, 4, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",   5, coalescedRequest.getIndex());
-        assertEquals("addRequest", 105, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest4() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 5, 5, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",   5, coalescedRequest.getIndex());
-        assertEquals("addRequest", 105, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest5() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class,  15, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",  10, coalescedRequest.getIndex());
-        assertEquals("addRequest", 105, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest6() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 100, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",  10, coalescedRequest.getIndex());
-        assertEquals("addRequest", 190, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest7() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 110, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",  10, coalescedRequest.getIndex());
-        assertEquals("addRequest", 200, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-    public void testAddRequest8() {
-        TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(TmfEvent.class, 10, 100, 200);
-        TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 111, 100, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request));
-        coalescedRequest.addRequest(request);
-        assertEquals("addRequest",  10, coalescedRequest.getIndex());
-        assertEquals("addRequest", 201, coalescedRequest.getNbRequested());
-        assertEquals("addRequest", 200, coalescedRequest.getBlockSize());
-    }
-
-       // ------------------------------------------------------------------------
-       // done
-       // ------------------------------------------------------------------------
-
-       public void testDone() {
-
-               // Test request
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedDataRequest request = setupTestRequest(crFlags);
-               TmfDataRequest subRequest1 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               TmfDataRequest subRequest2 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.done();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertFalse("isFailed",    request.isFailed());
-               assertFalse("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertTrue ("handleSuccess",   crFlags[1]);
-               assertFalse("handleFailure",   crFlags[2]);
-               assertFalse("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertFalse("isFailed",    subRequest1.isFailed());
-               assertFalse("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertFalse("isFailed",    subRequest2.isFailed());
-               assertFalse("isCancelled", subRequest2.isCancelled());
-       }
-
-       // ------------------------------------------------------------------------
-       // fail
-       // ------------------------------------------------------------------------
-
-       public void testFail() {
-
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedDataRequest request = setupTestRequest(crFlags);
-               TmfDataRequest subRequest1 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               TmfDataRequest subRequest2 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.fail();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertTrue ("isFailed",    request.isFailed());
-               assertFalse("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertFalse("handleSuccess",   crFlags[1]);
-               assertTrue ("handleFailure",   crFlags[2]);
-               assertFalse("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertTrue ("isFailed",    subRequest1.isFailed());
-               assertFalse("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertTrue ("isFailed",    subRequest2.isFailed());
-               assertFalse("isCancelled", subRequest2.isCancelled());
-       }
-
-       // ------------------------------------------------------------------------
-       // cancel
-       // ------------------------------------------------------------------------
-
-       public void testCancel() {
-
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedDataRequest request = setupTestRequest(crFlags);
-               TmfDataRequest subRequest1 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               TmfDataRequest subRequest2 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.cancel();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertFalse("isFailed",    request.isFailed());
-               assertTrue ("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertFalse("handleSuccess",   crFlags[1]);
-               assertFalse("handleFailure",   crFlags[2]);
-               assertTrue ("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertFalse("isFailed",    subRequest1.isFailed());
-               assertTrue ("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertFalse("isFailed",    subRequest2.isFailed());
-               assertTrue ("isCancelled", subRequest2.isCancelled());
-       }
-
-
-       // ------------------------------------------------------------------------
-       // cancel sub-requests
-       // ------------------------------------------------------------------------
-
-    public void testCancelSubRequests() {
-
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedDataRequest request = setupTestRequest(crFlags);
-               TmfDataRequest subRequest1 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               TmfDataRequest subRequest2 = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               subRequest1.cancel();
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertFalse("isFailed",    subRequest1.isFailed());
-               assertTrue ("isCancelled", subRequest1.isCancelled());
-
-               // Validate the coalescing request
-               assertFalse("isCompleted", request.isCompleted());
-               assertFalse("isFailed",     request.isFailed());
-               assertFalse("isCancelled", request.isCancelled());
-
-               // Cancel second sub-request
-               subRequest2.cancel();
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertFalse("isFailed",    subRequest2.isFailed());
-               assertTrue ("isCancelled", subRequest2.isCancelled());
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertFalse("isFailed",    request.isFailed());
-               assertTrue ("isCancelled", request.isCancelled());
-
-               // Finalize coalescing request -
-               // Note: No need to check "request.isCancelled()" since it was verified above
-            request.cancel();
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertFalse("handleSuccess",   crFlags[1]);
-               assertFalse("handleFailure",   crFlags[2]);
-               assertTrue ("handleCancel",    crFlags[3]);
-           }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java
deleted file mode 100644 (file)
index 475e69d..0000000
+++ /dev/null
@@ -1,619 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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.core.tests.request;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Vector;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest;
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedEventRequest;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfEventRequestStub;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
-
-/**
- * <b><u>TmfCoalescedEventRequestTest</u></b>
- * <p>
- * Test suite for the TmfCoalescedEventRequest class.
- */
-@SuppressWarnings({"nls","javadoc"})
-public class TmfCoalescedEventRequestTest extends TestCase {
-
-       // ------------------------------------------------------------------------
-       // Variables
-       // ------------------------------------------------------------------------
-
-       private final TmfTimeRange range1 = new TmfTimeRange(TmfTimeRange.ETERNITY);
-       private final TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH);
-
-       private TmfCoalescedEventRequest fRequest1;
-       private TmfCoalescedEventRequest fRequest2;
-       private TmfCoalescedEventRequest fRequest3;
-       private TmfCoalescedEventRequest fRequest4;
-
-       private TmfCoalescedEventRequest fRequest1b;
-       private TmfCoalescedEventRequest fRequest1c;
-
-       private int fRequestCount;
-
-       // ------------------------------------------------------------------------
-       // Housekeeping
-       // ------------------------------------------------------------------------
-
-    /**
-     * @param name the test name
-     */
-       public TmfCoalescedEventRequestTest(String name) {
-               super(name);
-       }
-
-       @Override
-       public void setUp() throws Exception {
-               super.setUp();
-               TmfDataRequest.reset();
-               fRequest1  = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200);
-               fRequest2  = new TmfCoalescedEventRequest(TmfEvent.class, range2, 100, 200);
-               fRequest3  = new TmfCoalescedEventRequest(TmfEvent.class, range2, 200, 200);
-               fRequest4  = new TmfCoalescedEventRequest(TmfEvent.class, range2, 200, 300);
-
-               fRequest1b = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200);
-               fRequest1c = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200);
-
-               fRequestCount = fRequest1c.getRequestId() + 1;
-       }
-
-       @Override
-       public void tearDown() throws Exception {
-               super.tearDown();
-       }
-
-       private TmfCoalescedEventRequest setupTestRequest(final boolean[] flags) {
-
-               TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200) {
-                   @Override
-                       public void handleCompleted() {
-                       super.handleCompleted();
-                       flags[0] = true;
-                   }
-                   @Override
-                   public void handleSuccess() {
-                       super.handleSuccess();
-                       flags[1] = true;
-                   }
-                   @Override
-                   public void handleFailure() {
-                       super.handleFailure();
-                       flags[2] = true;
-                   }
-                   @Override
-                   public void handleCancel() {
-                       super.handleCancel();
-                       flags[3] = true;
-                   }
-               };
-               return request;
-       }
-
-       // ------------------------------------------------------------------------
-       // Constructors
-       // ------------------------------------------------------------------------
-
-       public void testTmfCoalescedEventRequest() {
-               TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(TmfEvent.class);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getRange", range1, request.getRange());
-        assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedEventRequestIndex() {
-               TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(TmfEvent.class, range1);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getRange", range1, request.getRange());
-        assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedEventRequestIndexNbRequested() {
-               TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getRange", range1, request.getRange());
-        assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() {
-               TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200);
-
-        assertEquals("getRequestId", fRequestCount++, request.getRequestId());
-        assertEquals("getDataType",  ITmfEvent.class, request.getDataType());
-
-        assertEquals("getRange", range1, request.getRange());
-        assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
-        assertFalse("isCompleted", request.isCompleted());
-        assertFalse("isFailed", request.isFailed());
-        assertFalse("isCancelled", request.isCancelled());
-
-        assertEquals("getNbRead", 0, request.getNbRead());
-       }
-
-       // ------------------------------------------------------------------------
-       // equals
-       // ------------------------------------------------------------------------
-
-       public void testEqualsReflexivity() {
-        assertTrue("equals", fRequest1.equals(fRequest1));
-        assertTrue("equals", fRequest2.equals(fRequest2));
-
-        assertFalse("equals", fRequest1.equals(fRequest2));
-        assertFalse("equals", fRequest2.equals(fRequest1));
-       }
-
-       public void testEqualsSymmetry() {
-        assertTrue("equals", fRequest1.equals(fRequest1b));
-        assertTrue("equals", fRequest1b.equals(fRequest1));
-
-        assertFalse("equals", fRequest1.equals(fRequest3));
-        assertFalse("equals", fRequest2.equals(fRequest3));
-        assertFalse("equals", fRequest3.equals(fRequest1));
-        assertFalse("equals", fRequest3.equals(fRequest2));
-       }
-
-       public void testEqualsTransivity() {
-        assertTrue("equals", fRequest1.equals(fRequest1b));
-        assertTrue("equals", fRequest1b.equals(fRequest1c));
-        assertTrue("equals", fRequest1.equals(fRequest1c));
-       }
-
-       public void testEqualsNull() {
-        assertFalse("equals", fRequest1.equals(null));
-        assertFalse("equals", fRequest2.equals(null));
-       }
-
-       public void testEqualsSuper() {
-               TmfCoalescedDataRequest dataRequest1 = new TmfCoalescedDataRequest(
-                               fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested());
-               TmfCoalescedDataRequest dataRequest2 = new TmfCoalescedDataRequest(
-                               fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested());
-               TmfCoalescedDataRequest dataRequest3 = new TmfCoalescedDataRequest(
-                               fRequest3.getDataType(), fRequest3.getIndex(), fRequest3.getNbRequested());
-
-               assertTrue("equals", fRequest1.equals(dataRequest2));
-        assertTrue("equals", fRequest2.equals(dataRequest1));
-        assertFalse("equals", fRequest1.equals(dataRequest3));
-        assertFalse("equals", fRequest3.equals(dataRequest1));
-       }
-
-       // ------------------------------------------------------------------------
-       // hashCode
-       // ------------------------------------------------------------------------
-
-       public void testHashCode() {
-        assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode());
-        assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode());
-               assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode());
-       }
-
-       // ------------------------------------------------------------------------
-       // toString
-       // ------------------------------------------------------------------------
-
-       public void testToString() {
-        String expected1 = "[TmfCoalescedEventRequest(0,ITmfEvent," + range1 + ",0,100,200)]";
-        String expected2 = "[TmfCoalescedEventRequest(1,ITmfEvent," + range2 + ",0,100,200)]";
-        String expected3 = "[TmfCoalescedEventRequest(2,ITmfEvent," + range2 + ",0,200,200)]";
-        String expected4 = "[TmfCoalescedEventRequest(3,ITmfEvent," + range2 + ",0,200,300)]";
-
-        assertEquals("toString", expected1, fRequest1.toString());
-        assertEquals("toString", expected2, fRequest2.toString());
-        assertEquals("toString", expected3, fRequest3.toString());
-        assertEquals("toString", expected4, fRequest4.toString());
-       }
-
-       // ------------------------------------------------------------------------
-       // isCompatible
-       // ------------------------------------------------------------------------
-
-       @SuppressWarnings("hiding")
-       public void testIsCompatible() {
-               TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(TmfEvent.class, range1, 100, 200);
-               TmfEventRequest request1 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               TmfEventRequest request2 = new TmfEventRequestStub(TmfEvent.class, range2, 100, 200);
-               TmfEventRequest request3 = new TmfEventRequestStub(TmfEvent.class, range1, 101, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request1));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request2));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request3));
-       }
-
-    // ------------------------------------------------------------------------
-    // addEvent
-    // ------------------------------------------------------------------------
-
-    @SuppressWarnings("hiding")
-    public void testAddEvent1() {
-        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(TmfEvent.class, range1, 0, 2147483647, 200, ExecutionType.FOREGROUND);
-        TmfEventRequest request1 = new TmfEventRequestStub(TmfEvent.class, range1, 0, 2147483647, 200);
-        TmfEventRequest request2 = new TmfEventRequestStub(TmfEvent.class, range1, 1, 2147483647, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request1));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request2));
-
-        coalescedRequest.addRequest(request1);
-        coalescedRequest.addRequest(request2);
-
-        assertEquals("addRequest",          0, coalescedRequest.getIndex());
-        assertEquals("addRequest", 2147483647, coalescedRequest.getNbRequested());
-        assertEquals("addRequest",        200, coalescedRequest.getBlockSize());
-
-    }
-
-    @SuppressWarnings("hiding")
-    public void testAddEvent2() {
-        TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(TmfEvent.class, range1, 1, 2147483647, 200, ExecutionType.FOREGROUND);
-        TmfEventRequest request1 = new TmfEventRequestStub(TmfEvent.class, range1, 1, 2147483647, 200);
-        TmfEventRequest request2 = new TmfEventRequestStub(TmfEvent.class, range1, 0, 2147483647, 200);
-
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request1));
-        assertTrue("isCompatible", coalescedRequest.isCompatible(request2));
-
-        coalescedRequest.addRequest(request1);
-        coalescedRequest.addRequest(request2);
-
-        assertEquals("addRequest",          0, coalescedRequest.getIndex());
-        assertEquals("addRequest", 2147483647, coalescedRequest.getNbRequested());
-        assertEquals("addRequest",        200, coalescedRequest.getBlockSize());
-
-    }
-
-       // ------------------------------------------------------------------------
-       // done
-       // ------------------------------------------------------------------------
-
-       public void testDone() {
-
-               // Test request
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedEventRequest request = setupTestRequest(crFlags);
-               TmfEventRequest subRequest1 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               TmfEventRequest subRequest2 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.done();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertFalse("isFailed",    request.isFailed());
-               assertFalse("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertTrue ("handleSuccess",   crFlags[1]);
-               assertFalse("handleFailure",   crFlags[2]);
-               assertFalse("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertFalse("isFailed",    subRequest1.isFailed());
-               assertFalse("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertFalse("isFailed",    subRequest2.isFailed());
-               assertFalse("isCancelled", subRequest2.isCancelled());
-       }
-
-       // ------------------------------------------------------------------------
-       // fail
-       // ------------------------------------------------------------------------
-
-       public void testFail() {
-
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedEventRequest request = setupTestRequest(crFlags);
-               TmfEventRequest subRequest1 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               TmfEventRequest subRequest2 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.fail();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertTrue ("isFailed",    request.isFailed());
-               assertFalse("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertFalse("handleSuccess",   crFlags[1]);
-               assertTrue ("handleFailure",   crFlags[2]);
-               assertFalse("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertTrue ("isFailed",    subRequest1.isFailed());
-               assertFalse("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertTrue ("isFailed",    subRequest2.isFailed());
-               assertFalse("isCancelled", subRequest2.isCancelled());
-       }
-
-       // ------------------------------------------------------------------------
-       // cancel
-       // ------------------------------------------------------------------------
-
-       public void testCancel() {
-
-               final boolean[] crFlags = new boolean[4];
-               TmfCoalescedEventRequest request = setupTestRequest(crFlags);
-               TmfEventRequest subRequest1 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               TmfEventRequest subRequest2 = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
-               request.addRequest(subRequest1);
-               request.addRequest(subRequest2);
-
-               request.cancel();
-
-               // Validate the coalescing request
-               assertTrue ("isCompleted", request.isCompleted());
-               assertFalse("isFailed",    request.isFailed());
-               assertTrue ("isCancelled", request.isCancelled());
-
-               assertTrue ("handleCompleted", crFlags[0]);
-               assertFalse("handleSuccess",   crFlags[1]);
-               assertFalse("handleFailure",   crFlags[2]);
-               assertTrue ("handleCancel",    crFlags[3]);
-
-               // Validate the first coalesced request
-               assertTrue ("isCompleted", subRequest1.isCompleted());
-               assertFalse("isFailed",    subRequest1.isFailed());
-               assertTrue ("isCancelled", subRequest1.isCancelled());
-
-               // Validate the second coalesced request
-               assertTrue ("isCompleted", subRequest2.isCompleted());
-               assertFalse("isFailed",    subRequest2.isFailed());
-               assertTrue ("isCancelled", subRequest2.isCancelled());
-       }
-
-       // ------------------------------------------------------------------------
-       // Coalescing
-       // ------------------------------------------------------------------------
-
-    private static final String DIRECTORY   = "testfiles";
-    private static final String TEST_STREAM = "A-Test-10K";
-    private static final int    NB_EVENTS   = 5000;
-    private static final int    BLOCK_SIZE  = 100;
-
-    // Initialize the test trace
-    private TmfTraceStub fTrace = null;
-    private synchronized TmfTraceStub setupTrace(String path) {
-       if (fTrace == null) {
-               try {
-               URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
-               File test = new File(FileLocator.toFileURL(location).toURI());
-               fTrace = new TmfTraceStub(test.getPath(), 500);
-               } catch (TmfTraceException e) {
-                       e.printStackTrace();
-            } catch (URISyntaxException e) {
-                e.printStackTrace();
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
-       }
-       return fTrace;
-    }
-
-       Vector<ITmfEvent> requestedEvents1;
-    Vector<ITmfEvent> requestedEvents2;
-    Vector<ITmfEvent> requestedEvents3;
-
-    TmfEventRequest request1;
-    TmfEventRequest request2;
-    TmfEventRequest request3;
-
-    ITmfDataProvider[] providers;
-
-    private static class TmfTestTriggerSignal extends TmfSignal {
-       public final boolean forceCancel;
-       public final long fIndex;
-               public TmfTestTriggerSignal(Object source, long index, boolean cancel) {
-                       super(source);
-                       forceCancel = cancel;
-                       fIndex = index;
-               }
-    }
-
-       @TmfSignalHandler
-    public void trigger(final TmfTestTriggerSignal signal) {
-
-        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final long REQUEST_OFFSET = 1000;
-
-        requestedEvents1 = new Vector<ITmfEvent>();
-        request1 = new TmfEventRequest(TmfEvent.class, range, signal.fIndex, NB_EVENTS, BLOCK_SIZE) {
-               int nbRead = 0;
-            @Override
-            public void handleData(ITmfEvent event) {
-                       super.handleData(event);
-               if (!isCompleted()) {
-                               requestedEvents1.add(event);
-                       if (++nbRead >= BLOCK_SIZE && signal.forceCancel) {
-                        cancel();
-                    }
-               }
-            }
-        };
-
-        requestedEvents2 = new Vector<ITmfEvent>();
-        request2 = new TmfEventRequest(TmfEvent.class, range, signal.fIndex + REQUEST_OFFSET, NB_EVENTS, BLOCK_SIZE) {
-            @Override
-            public void handleData(ITmfEvent event) {
-                       super.handleData(event);
-               if (!isCompleted()) {
-                       requestedEvents2.add(event);
-               }
-            }
-        };
-
-        requestedEvents3 = new Vector<ITmfEvent>();
-        request3 = new TmfEventRequest(TmfEvent.class, range, signal.fIndex + 2 * REQUEST_OFFSET, NB_EVENTS, BLOCK_SIZE) {
-            @Override
-            public void handleData(ITmfEvent event) {
-                       super.handleData(event);
-               if (!isCompleted()) {
-                       requestedEvents3.add(event);
-               }
-            }
-        };
-
-        providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
-        providers[0].sendRequest(request1);
-        providers[0].sendRequest(request2);
-        providers[0].sendRequest(request3);
-    }
-
-    public void runCoalescedRequest(long startIndex) throws InterruptedException {
-
-        fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
-
-        TmfSignalManager.register(this);
-        TmfTestTriggerSignal signal = new TmfTestTriggerSignal(this, startIndex, false);
-        TmfSignalManager.dispatchSignal(signal);
-
-        request1.waitForCompletion();
-        request2.waitForCompletion();
-        request3.waitForCompletion();
-
-        try {
-            assertEquals("Request1: nbEvents", NB_EVENTS, requestedEvents1.size());
-            assertTrue  ("Request1: isCompleted", request1.isCompleted());
-            assertFalse ("Request1: isCancelled", request1.isCancelled());
-
-            assertEquals("Request2: nbEvents", NB_EVENTS, requestedEvents2.size());
-            assertTrue  ("Request2: isCompleted", request2.isCompleted());
-            assertFalse ("Request2: isCancelled", request2.isCancelled());
-
-            assertEquals("Request3: nbEvents", NB_EVENTS, requestedEvents3.size());
-            assertTrue  ("Request3: isCompleted", request3.isCompleted());
-            assertFalse ("Request3: isCancelled", request3.isCancelled());
-
-            // Ensure that we have distinct events.
-            // Don't go overboard: we are not validating the stub!
-            for (int i = 0; i < NB_EVENTS; i++) {
-                assertEquals("Distinct events", i + 1 + request1.getIndex(), requestedEvents1.get(i).getTimestamp().getValue());
-                assertEquals("Distinct events", i + 1 + request2.getIndex(), requestedEvents2.get(i).getTimestamp().getValue());
-                assertEquals("Distinct events", i + 1 + request3.getIndex(), requestedEvents3.get(i).getTimestamp().getValue());
-            }
-        }
-        finally {
-            TmfSignalManager.deregister(this);
-            fTrace.dispose();
-            fTrace = null;
-        }
-    }
-
-    public void testCoalescedRequest() throws InterruptedException {
-        runCoalescedRequest(0);
-        runCoalescedRequest(1);
-        runCoalescedRequest(5);
-    }
-
-       public void testCancelCoalescedRequest() throws InterruptedException {
-
-               fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
-
-       TmfSignalManager.register(this);
-               TmfTestTriggerSignal signal = new TmfTestTriggerSignal(this, 0, true);
-       TmfSignalManager.dispatchSignal(signal);
-
-        request1.waitForCompletion();
-        request2.waitForCompletion();
-        request3.waitForCompletion();
-
-        assertEquals("Request1: nbEvents", BLOCK_SIZE, requestedEvents1.size());
-        assertTrue  ("Request1: isCompleted", request1.isCompleted());
-        assertTrue  ("Request1: isCancelled", request1.isCancelled());
-
-        assertEquals("Request2: nbEvents", NB_EVENTS, requestedEvents2.size());
-        assertTrue  ("Request2: isCompleted", request2.isCompleted());
-        assertFalse ("Request2: isCancelled", request2.isCancelled());
-
-        assertEquals("Request3: nbEvents", NB_EVENTS, requestedEvents3.size());
-        assertTrue  ("Request3: isCompleted", request3.isCompleted());
-        assertFalse ("Request3: isCancelled", request3.isCancelled());
-
-        // Ensure that we have distinct events.
-        // Don't go overboard: we are not validating the stub!
-        for (int i = 0; i < BLOCK_SIZE; i++) {
-            assertEquals("Distinct events", i + 1 + request1.getIndex(), requestedEvents1.get(i).getTimestamp().getValue());
-        }
-        for (int i = 0; i < NB_EVENTS; i++) {
-            assertEquals("Distinct events", i + 1 + request2.getIndex(), requestedEvents2.get(i).getTimestamp().getValue());
-            assertEquals("Distinct events", i + 1 + request3.getIndex(), requestedEvents3.get(i).getTimestamp().getValue());
-        }
-
-        TmfSignalManager.deregister(this);
-        fTrace.dispose();
-        fTrace = null;
-    }
-
-    // ------------------------------------------------------------------------
-    //
-    // ------------------------------------------------------------------------
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedRequestTest.java
new file mode 100644 (file)
index 0000000..09c7307
--- /dev/null
@@ -0,0 +1,553 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.request;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedRequest;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestState;
+import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfRequestStub;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfCoalescedRequestTest</u></b>
+ * <p>
+ * Test suite for the TmfCoalescedRequest class.
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfCoalescedRequestTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final TmfRequestPriority NORMAL = TmfRequestPriority.NORMAL;
+    private static final TmfRequestPriority HIGH = TmfRequestPriority.HIGH;
+
+    private static final long ALL_EVENTS = ITmfRequest.ALL_EVENTS;
+
+    private static final TmfTimeRange ETERNITY = TmfTimeRange.ETERNITY;
+    private static final TmfTimeRange EPOCH = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+
+    private static final TmfRequestState PENDING = TmfRequestState.PENDING;
+    private static final TmfRequestState RUNNING = TmfRequestState.RUNNING;
+    private static final TmfRequestState COMPLETED = TmfRequestState.COMPLETED;
+
+    // ------------------------------------------------------------------------
+    // Sample requests
+    // ------------------------------------------------------------------------
+
+    private static ITmfRequest fRequest1  = new TmfRequestStub(EPOCH,  10, 100, NORMAL);
+    private static ITmfRequest fRequest2  = new TmfRequestStub(EPOCH,  20, 200, NORMAL);
+    private static final ITmfRequest fRequest3  = new TmfRequestStub(EPOCH, 200, 100, NORMAL);
+
+    private static final ITmfRequest fRequest4  = new TmfRequestStub(ETERNITY,  10, 100, NORMAL);
+    private static final ITmfRequest fRequest5  = new TmfRequestStub(ETERNITY,  20, 200, NORMAL);
+    private static final ITmfRequest fRequest6  = new TmfRequestStub(ETERNITY, 200, 100, NORMAL);
+
+    private static final ITmfRequest fRequest7  = new TmfRequestStub(EPOCH,  10, 100, HIGH);
+    private static final ITmfRequest fRequest8  = new TmfRequestStub(EPOCH,  20, 200, HIGH);
+    private static final ITmfRequest fRequest9  = new TmfRequestStub(EPOCH, 200, 100, HIGH);
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private TmfCoalescedRequest fCoalescedRequest1;
+    private TmfCoalescedRequest fCoalescedRequest2;
+    private int fLastRequestId;
+
+    // ------------------------------------------------------------------------
+       // Housekeeping
+       // ------------------------------------------------------------------------
+
+    /**
+     * @param name the test name
+     */
+       public TmfCoalescedRequestTest(String name) {
+               super(name);
+       }
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+        fRequest1  = new TmfRequestStub(EPOCH,  10, 100, NORMAL);
+        fRequest2  = new TmfRequestStub(EPOCH,  20, 200, NORMAL);
+           fCoalescedRequest1 = new TmfCoalescedRequest(fRequest1);
+           fCoalescedRequest2 = new TmfCoalescedRequest(fRequest2);
+           fLastRequestId = fCoalescedRequest2.getRequestId();
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+    private ITmfRequest setupDummyRequest(final boolean[] flags) {
+
+        TmfCoalescedRequest request = new TmfCoalescedRequest(fRequest1) {
+            @Override
+            public synchronized void handleCompleted() {
+                super.handleCompleted();
+                flags[0] = true;
+            }
+
+            @Override
+            public void handleSuccess() {
+                super.handleSuccess();
+                flags[1] = true;
+            }
+
+            @Override
+            public void handleFailure() {
+                super.handleFailure();
+                flags[2] = true;
+            }
+
+            @Override
+            public void handleCancel() {
+                super.handleCancel();
+                flags[3] = true;
+            }
+        };
+        request.addRequest(fRequest2);
+        fLastRequestId = request.getRequestId();
+        return request;
+    }
+
+    // ------------------------------------------------------------------------
+       // Constructors
+       // ------------------------------------------------------------------------
+
+       @Test
+       public void testTmfRequestByPriority() {
+           TmfCoalescedRequest request = new TmfCoalescedRequest(NORMAL);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        request = new TmfCoalescedRequest(HIGH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", HIGH, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+       }
+
+    @Test
+    public void testTmfRequestByRequest() {
+        TmfCoalescedRequest request = new TmfCoalescedRequest(fRequest1);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", fRequest1.getRequestPriority(), request.getRequestPriority());
+        assertEquals("getTimeRange", fRequest1.getTimeRange(), request.getTimeRange());
+        assertEquals("getNbRequested", fRequest1.getNbRequested(), request.getNbRequested());
+        assertEquals("getStartIndex", fRequest1.getStartIndex(), request.getStartIndex());
+
+        assertEquals("getParent", request, fRequest1.getParent());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        request = new TmfCoalescedRequest(fRequest5);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", fRequest5.getRequestPriority(), request.getRequestPriority());
+        assertEquals("getTimeRange", fRequest5.getTimeRange(), request.getTimeRange());
+        assertEquals("getNbRequested", fRequest5.getNbRequested(), request.getNbRequested());
+        assertEquals("getStartIndex", fRequest5.getStartIndex(), request.getStartIndex());
+
+        assertEquals("getParent", request, fRequest5.getParent());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        request = new TmfCoalescedRequest(fRequest9);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", fRequest9.getRequestPriority(), request.getRequestPriority());
+        assertEquals("getTimeRange", fRequest9.getTimeRange(), request.getTimeRange());
+        assertEquals("getNbRequested", fRequest9.getNbRequested(), request.getNbRequested());
+        assertEquals("getStartIndex", fRequest9.getStartIndex(), request.getStartIndex());
+
+        assertEquals("getParent", request, fRequest9.getParent());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    // ------------------------------------------------------------------------
+    // equals
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        assertEquals("equals", fCoalescedRequest1, fCoalescedRequest1);
+        assertEquals("equals", fCoalescedRequest2, fCoalescedRequest2);
+
+        assertFalse("equals", fCoalescedRequest1.equals(fCoalescedRequest2));
+        assertFalse("equals", fCoalescedRequest2.equals(fCoalescedRequest1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        TmfCoalescedRequest request1b = new TmfCoalescedRequest(fRequest1);
+        fLastRequestId++;
+
+        assertEquals("equals", fCoalescedRequest1, request1b);
+        assertEquals("equals", request1b, fCoalescedRequest1);
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        TmfCoalescedRequest request1b = new TmfCoalescedRequest(fRequest1);
+        fLastRequestId++;
+        TmfCoalescedRequest request1c = new TmfCoalescedRequest(fRequest1);
+        fLastRequestId++;
+
+        assertEquals("equals", fCoalescedRequest1, request1b);
+        assertEquals("equals", request1b, request1c);
+        assertEquals("equals", request1c, fCoalescedRequest1);
+    }
+
+    @Test
+    public void testEqualsNull() {
+        assertFalse("equals", fCoalescedRequest1.equals(null));
+        assertFalse("equals", fCoalescedRequest2.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        assertTrue("hashCode", fCoalescedRequest1.hashCode() == fCoalescedRequest1.hashCode());
+        assertTrue("hashCode", fCoalescedRequest2.hashCode() == fCoalescedRequest2.hashCode());
+        assertTrue("hashCode", fCoalescedRequest1.hashCode() != fCoalescedRequest2.hashCode());
+    }
+
+    // ------------------------------------------------------------------------
+    // toString
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        String expected1 = "TmfCoalescedRequest [fSubRequests=[" + fRequest1 + "]]";
+        String expected2 = "TmfCoalescedRequest [fSubRequests=[" + fRequest2 + "]]";
+
+        assertEquals("toString", expected1, fCoalescedRequest1.toString());
+        assertEquals("toString", expected2, fCoalescedRequest2.toString());
+    }
+
+
+    // ------------------------------------------------------------------------
+    // isCompatible
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testIsCompatible() {
+        assertTrue ("isCompatible", fCoalescedRequest1.isCompatible(fRequest1));
+        assertTrue ("isCompatible", fCoalescedRequest1.isCompatible(fRequest2));
+        assertFalse("isCompatible", fCoalescedRequest1.isCompatible(fRequest3));
+        assertTrue ("isCompatible", fCoalescedRequest1.isCompatible(fRequest4));
+        assertTrue ("isCompatible", fCoalescedRequest1.isCompatible(fRequest5));
+        assertFalse("isCompatible", fCoalescedRequest1.isCompatible(fRequest6));
+
+        assertFalse("isCompatible", fCoalescedRequest1.isCompatible(fRequest7));
+        assertFalse("isCompatible", fCoalescedRequest1.isCompatible(fRequest8));
+        assertFalse("isCompatible", fCoalescedRequest1.isCompatible(fRequest9));
+    }
+
+    // ------------------------------------------------------------------------
+    // addRequest
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testAddRequest() {
+        fCoalescedRequest1.addRequest(fRequest2);
+        assertEquals("getRequestPriority", NORMAL, fCoalescedRequest1.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, fCoalescedRequest1.getTimeRange());
+        assertEquals("getNbRequested", 210, fCoalescedRequest1.getNbRequested());
+        assertEquals("getStartIndex",   10, fCoalescedRequest1.getStartIndex());
+
+        fCoalescedRequest1.addRequest(fRequest3);
+        assertEquals("getRequestPriority", NORMAL, fCoalescedRequest1.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, fCoalescedRequest1.getTimeRange());
+        assertEquals("getNbRequested", 290, fCoalescedRequest1.getNbRequested());
+        assertEquals("getStartIndex",   10, fCoalescedRequest1.getStartIndex());
+
+        fCoalescedRequest1.addRequest(fRequest4);
+        assertEquals("getRequestPriority", NORMAL, fCoalescedRequest1.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, fCoalescedRequest1.getTimeRange());
+        assertEquals("getNbRequested", 290, fCoalescedRequest1.getNbRequested());
+        assertEquals("getStartIndex",   10, fCoalescedRequest1.getStartIndex());
+    }
+
+    // ------------------------------------------------------------------------
+    // getSubRequestIds
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testGetSubRequestIds() {
+        String expected1 = "[" + fRequest1.getRequestId() + "]";
+        String expected2 = "[" + fRequest1.getRequestId() + "," + fRequest2.getRequestId() + "]";
+        String expected3 = "[" + fRequest1.getRequestId() + "," + fRequest2.getRequestId() + "," + fRequest3.getRequestId() + "]";
+
+        assertEquals("getRequestIds", expected1, fCoalescedRequest1.getSubRequestIds());
+
+        fCoalescedRequest1.addRequest(fRequest2);
+        assertEquals("getRequestIds", expected2, fCoalescedRequest1.getSubRequestIds());
+
+        fCoalescedRequest1.addRequest(fRequest3);
+        assertEquals("getRequestIds", expected3, fCoalescedRequest1.getSubRequestIds());
+    }
+
+    // ------------------------------------------------------------------------
+    // notifyParent
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testNotifyParent() {
+        final Boolean[] notifications = new Boolean[2];
+        notifications[0] = notifications[1] = false;
+
+        final TmfRequestStub request1 = new TmfRequestStub();
+        final TmfRequestStub request2 = new TmfRequestStub();
+        TmfCoalescedRequest request = new TmfCoalescedRequest(request1) {
+            @Override
+            public void notifyParent(ITmfRequest child) {
+                notifications[child == request1 ? 0 : 1] = true;
+                super.notifyParent(this);
+            }
+        };
+        request.addRequest(request2);
+        assertFalse("notifyParent", notifications[0]);
+        assertFalse("notifyParent", notifications[1]);
+
+        request1.notifyParent(null);
+        assertTrue("notifyParent", notifications[0]);
+        assertFalse("notifyParent", notifications[1]);
+
+        request2.notifyParent(null);
+        assertTrue("notifyParent", notifications[0]);
+        assertTrue("notifyParent", notifications[1]);
+    }
+
+    // ------------------------------------------------------------------------
+    // start
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testStart() {
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.start();
+
+        assertTrue("isRunning",    request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+        assertEquals("getState",   RUNNING, request.getState());
+        assertNull("getStatus",    request.getStatus());
+
+        assertTrue("isRunning",    fRequest1.isRunning());
+        assertFalse("isCompleted", fRequest1.isCompleted());
+        assertEquals("getState",   RUNNING, fRequest1.getState());
+        assertNull("getStatus",    fRequest1.getStatus());
+
+        assertTrue("isRunning",    fRequest2.isRunning());
+        assertFalse("isCompleted", fRequest2.isCompleted());
+        assertEquals("getState",   RUNNING, fRequest2.getState());
+        assertNull("getStatus",    fRequest2.getStatus());
+
+        assertFalse("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",   flags[1]);
+        assertFalse("handleFailure",   flags[2]);
+        assertFalse("handleCancel",    flags[3]);
+    }
+
+    // ------------------------------------------------------------------------
+    // done
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testDone() {
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.done();
+
+        assertFalse("isRunning",   request.isRunning());
+        assertTrue("isCompleted",  request.isCompleted());
+        assertEquals("getState",   COMPLETED, request.getState());
+        assertEquals("getStatus",  IStatus.OK, request.getStatus().getSeverity());
+        assertTrue("isOK",         request.isOK());
+        assertFalse("isFailed",    request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        assertFalse("isRunning",   fRequest1.isRunning());
+        assertTrue("isCompleted",  fRequest1.isCompleted());
+        assertEquals("getState",   COMPLETED, fRequest1.getState());
+        assertEquals("getStatus",  IStatus.OK, fRequest1.getStatus().getSeverity());
+        assertTrue("isOK",         fRequest1.isOK());
+        assertFalse("isFailed",    fRequest1.isFailed());
+        assertFalse("isCancelled", fRequest1.isCancelled());
+
+        assertFalse("isRunning",   fRequest2.isRunning());
+        assertTrue("isCompleted",  fRequest2.isCompleted());
+        assertEquals("getState",   COMPLETED, fRequest2.getState());
+        assertEquals("getStatus",  IStatus.OK, fRequest2.getStatus().getSeverity());
+        assertTrue("isOK",         fRequest2.isOK());
+        assertFalse("isFailed",    fRequest2.isFailed());
+        assertFalse("isCancelled", fRequest2.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertTrue("handleSuccess",   flags[1]);
+        assertFalse("handleFailure",  flags[2]);
+        assertFalse("handleCancel",   flags[3]);
+    }
+
+    // ------------------------------------------------------------------------
+    // fail
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testFail() {
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.fail();
+
+        assertFalse("isRunning",   request.isRunning());
+        assertTrue("isCompleted",  request.isCompleted());
+        assertEquals("getState",   COMPLETED, request.getState());
+        assertEquals("getStatus",  IStatus.ERROR, request.getStatus().getSeverity());
+        assertFalse("isOK",        request.isOK());
+        assertTrue("isFailed",     request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        assertFalse("isRunning",   fRequest1.isRunning());
+        assertTrue("isCompleted",  fRequest1.isCompleted());
+        assertEquals("getState",   COMPLETED, fRequest1.getState());
+        assertEquals("getStatus",  IStatus.ERROR, fRequest1.getStatus().getSeverity());
+        assertFalse("isOK",        fRequest1.isOK());
+        assertTrue("isFailed",     fRequest1.isFailed());
+        assertFalse("isCancelled", fRequest1.isCancelled());
+
+        assertFalse("isRunning",   fRequest2.isRunning());
+        assertTrue("isCompleted",  fRequest2.isCompleted());
+        assertEquals("getState",   COMPLETED, fRequest2.getState());
+        assertEquals("getStatus",  IStatus.ERROR, fRequest2.getStatus().getSeverity());
+        assertFalse("isOK",        fRequest2.isOK());
+        assertTrue("isFailed",     fRequest2.isFailed());
+        assertFalse("isCancelled", fRequest2.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",  flags[1]);
+        assertTrue("handleFailure",   flags[2]);
+        assertFalse("handleCancel",   flags[3]);
+    }
+
+       // ------------------------------------------------------------------------
+       // cancel
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testCancel() {
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.cancel();
+
+        assertFalse("isRunning",  request.isRunning());
+        assertTrue("isCompleted", request.isCompleted());
+        assertEquals("getState",  COMPLETED, request.getState());
+        assertEquals("getStatus", IStatus.CANCEL, request.getStatus().getSeverity());
+        assertFalse("isOK",       request.isOK());
+        assertFalse("isFailed",   request.isFailed());
+        assertTrue("isCancelled", request.isCancelled());
+
+        assertFalse("isRunning",  fRequest1.isRunning());
+        assertTrue("isCompleted", fRequest1.isCompleted());
+        assertEquals("getState",  COMPLETED, fRequest1.getState());
+        assertEquals("getStatus", IStatus.CANCEL, fRequest1.getStatus().getSeverity());
+        assertFalse("isOK",       fRequest1.isOK());
+        assertFalse("isFailed",   fRequest1.isFailed());
+        assertTrue("isCancelled", fRequest1.isCancelled());
+
+        assertFalse("isRunning",  fRequest2.isRunning());
+        assertTrue("isCompleted", fRequest2.isCompleted());
+        assertEquals("getState",  COMPLETED, fRequest2.getState());
+        assertEquals("getStatus", IStatus.CANCEL, fRequest2.getStatus().getSeverity());
+        assertFalse("isOK",       fRequest2.isOK());
+        assertFalse("isFailed",   fRequest2.isFailed());
+        assertTrue("isCancelled", fRequest2.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",  flags[1]);
+        assertFalse("handleFailure",  flags[2]);
+        assertTrue("handleCancel",    flags[3]);
+    }
+
+}
index 6a29795692a70fc4c4bb83438126f339c160ecc6..1e601044f5865bd121fe43e5c2a424a1c3566c33 100644 (file)
@@ -23,7 +23,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub;
  * <p>
  * Test suite for the TmfDataRequest class.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfDataRequestTest extends TestCase {
 
        // ------------------------------------------------------------------------
@@ -53,7 +53,6 @@ public class TmfDataRequestTest extends TestCase {
        @Override
        protected void setUp() throws Exception {
                super.setUp();
-               TmfDataRequest.reset();
                fRequest1  = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200);
                fRequest2  = new TmfDataRequestStub(TmfEvent.class, 20, 100, 200);
                fRequest3  = new TmfDataRequestStub(TmfEvent.class, 20, 200, 200);
@@ -72,7 +71,7 @@ public class TmfDataRequestTest extends TestCase {
 
                TmfDataRequest request = new TmfDataRequestStub(TmfEvent.class, 10, 100, 200) {
                    @Override
-                       public void handleCompleted() {
+                       public synchronized void handleCompleted() {
                        super.handleCompleted();
                        flags[0] = true;
                    }
@@ -211,10 +210,10 @@ public class TmfDataRequestTest extends TestCase {
        // ------------------------------------------------------------------------
 
        public void testToString() {
-        String expected1 = "[TmfDataRequest(0,TmfEvent,10,100,200)]";
-        String expected2 = "[TmfDataRequest(1,TmfEvent,20,100,200)]";
-        String expected3 = "[TmfDataRequest(2,TmfEvent,20,200,200)]";
-        String expected4 = "[TmfDataRequest(3,TmfEvent,20,200,300)]";
+        String expected1 = "[TmfDataRequest(" + fRequest1.getRequestId() + ",TmfEvent,10,100,200)]";
+        String expected2 = "[TmfDataRequest(" + fRequest2.getRequestId() + ",TmfEvent,20,100,200)]";
+        String expected3 = "[TmfDataRequest(" + fRequest3.getRequestId() + ",TmfEvent,20,200,200)]";
+        String expected4 = "[TmfDataRequest(" + fRequest4.getRequestId() + ",TmfEvent,20,200,300)]";
 
         assertEquals("toString", expected1, fRequest1.toString());
         assertEquals("toString", expected2, fRequest2.toString());
index f5bbc4bff268f1aea539753d4ffed8a667e12faf..05b07607534be5c8d5d870782783375f92349601 100644 (file)
@@ -26,7 +26,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfEventRequestStub;
  * <p>
  * Test suite for the TmfEventRequest class.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfEventRequestTest extends TestCase {
 
        // ------------------------------------------------------------------------
@@ -59,7 +59,6 @@ public class TmfEventRequestTest extends TestCase {
        @Override
        protected void setUp() throws Exception {
                super.setUp();
-               TmfDataRequest.reset();
                fRequest1  = new TmfEventRequestStub(TmfEvent.class, range1, 100, 200);
                fRequest2  = new TmfEventRequestStub(TmfEvent.class, range2, 100, 200);
                fRequest3  = new TmfEventRequestStub(TmfEvent.class, range2, 200, 200);
@@ -77,8 +76,8 @@ public class TmfEventRequestTest extends TestCase {
        private static TmfEventRequest setupTestRequest(final boolean[] flags) {
 
                TmfEventRequest request = new TmfEventRequestStub(TmfEvent.class, new TmfTimeRange(TmfTimeRange.ETERNITY), 100, 200) {
-                   @Override
-                       public void handleCompleted() {
+            @Override
+                       public synchronized void handleCompleted() {
                        super.handleCompleted();
                        flags[0] = true;
                    }
@@ -232,10 +231,10 @@ public class TmfEventRequestTest extends TestCase {
        // ------------------------------------------------------------------------
 
        public void testToString() {
-        String expected1 = "[TmfEventRequest(0,TmfEvent," + range1 + ",0,100,200)]";
-        String expected2 = "[TmfEventRequest(1,TmfEvent," + range2 + ",0,100,200)]";
-        String expected3 = "[TmfEventRequest(2,TmfEvent," + range2 + ",0,200,200)]";
-        String expected4 = "[TmfEventRequest(3,TmfEvent," + range2 + ",0,200,300)]";
+        String expected1 = "[TmfEventRequest(" + fRequest1.getRequestId() + ",TmfEvent," + range1 + ",0,100,200)]";
+        String expected2 = "[TmfEventRequest(" + fRequest2.getRequestId() + ",TmfEvent," + range2 + ",0,100,200)]";
+        String expected3 = "[TmfEventRequest(" + fRequest3.getRequestId() + ",TmfEvent," + range2 + ",0,200,200)]";
+        String expected4 = "[TmfEventRequest(" + fRequest4.getRequestId() + ",TmfEvent," + range2 + ",0,200,300)]";
 
         assertEquals("toString", expected1, fRequest1.toString());
         assertEquals("toString", expected2, fRequest2.toString());
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventTypeFilterTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventTypeFilterTest.java
new file mode 100644 (file)
index 0000000..6d4adb6
--- /dev/null
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.request;
+
+import junit.framework.TestCase;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.request.TmfEventTypeFilter;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfEventTypeFilterTest</u></b>
+ * <p>
+ * Test suite for the TmfEventTypeFilter class.
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfEventTypeFilterTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final TmfEventTypeFilter ALL_EVENTS = TmfEventTypeFilter.ALL_EVENTS;
+
+    // ------------------------------------------------------------------------
+       // Housekeeping
+       // ------------------------------------------------------------------------
+
+    /**
+     * @param name the test name
+     */
+       public TmfEventTypeFilterTest(String name) {
+               super(name);
+       }
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+    // ------------------------------------------------------------------------
+       // Constructors
+       // ------------------------------------------------------------------------
+
+       @Test
+       public void testTmfBlockFilter() {
+           TmfEventTypeFilter filter = ALL_EVENTS;
+        assertEquals("getEventType", ITmfEvent.class, filter.getEventType());
+
+        filter = new TmfEventTypeFilter(ITmfEvent.class);
+        assertEquals("getEventType", ITmfEvent.class, filter.getEventType());
+
+        filter = new TmfEventTypeFilter(TmfEvent.class);
+        assertEquals("getEventType", TmfEvent.class, filter.getEventType());
+
+       }
+
+    @Test
+    public void testTmfBlockFilterCopy() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(filter1);
+
+        assertEquals("getEventType", filter1.getEventType(), filter2.getEventType());
+        assertEquals("getEventType", TmfEvent.class, filter2.getEventType());
+    }
+
+    // ------------------------------------------------------------------------
+       // equals
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class);
+
+        assertEquals("equals", filter1, filter1);
+        assertEquals("equals", filter2, filter2);
+
+        assertFalse("equals", filter1.equals(filter2));
+        assertFalse("equals", filter2.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter3 = new TmfEventTypeFilter(TmfEvent.class);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter1);
+
+        assertFalse("equals", filter1.equals(filter3));
+        assertFalse("equals", filter3.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class);
+        TmfEventTypeFilter filter3 = new TmfEventTypeFilter(TmfEvent.class);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter3);
+        assertEquals("equals", filter3, filter1);
+    }
+
+    @Test
+    public void testEqualsNull() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class);
+
+        assertFalse("equals", filter1.equals(null));
+        assertFalse("equals", filter2.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class);
+
+        assertEquals("hashCode", filter1.hashCode(), filter1.hashCode());
+        assertEquals("hashCode", filter2.hashCode(), filter2.hashCode());
+        assertFalse("hashCode",  filter1.hashCode() == filter2.hashCode());
+    }
+
+       // ------------------------------------------------------------------------
+       // toString
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class);
+
+        String expected0 = "TmfEventTypeFilter [fEventType=ITmfEvent]";
+        String expected1 = "TmfEventTypeFilter [fEventType=ITmfEvent]";
+        String expected2 = "TmfEventTypeFilter [fEventType=TmfEvent]";
+
+        assertEquals("toString", expected0, ALL_EVENTS.toString());
+        assertEquals("toString", expected1, filter1.toString());
+        assertEquals("toString", expected2, filter2.toString());
+    }
+
+    // ------------------------------------------------------------------------
+    // matches
+    // ------------------------------------------------------------------------
+
+    private class TmfEvent1 extends TmfEvent {
+        public TmfEvent1(final ITmfEvent event) {
+            super(event);
+        }
+    }
+
+    private class TmfEvent2 extends TmfEvent {
+        public TmfEvent2(final ITmfEvent event) {
+            super(event);
+        }
+    }
+
+    /**
+     * The only test that really matters...
+     */
+    @Test
+    public void testMatches() {
+
+        TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent1.class);
+        TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent2.class);
+
+        TmfEvent  event0 = new TmfEvent(null, 0, null, null, null, null, null);
+        TmfEvent1 event1 = new TmfEvent1(event0);
+        TmfEvent2 event2 = new TmfEvent2(event0);
+
+        assertFalse("matches", filter1.matches(event0));
+        assertFalse("matches", filter2.matches(event0));
+
+        assertTrue ("matches", filter1.matches(event1));
+        assertFalse("matches", filter2.matches(event1));
+
+        assertFalse("matches", filter2.matches(event1));
+        assertTrue ("matches", filter2.matches(event2));
+
+        assertTrue("matches", ALL_EVENTS.matches(event1));
+        assertTrue("matches", ALL_EVENTS.matches(event2));
+        assertTrue("matches", ALL_EVENTS.matches(event0));
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRangeFilterTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRangeFilterTest.java
new file mode 100644 (file)
index 0000000..c582852
--- /dev/null
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.request;
+
+import junit.framework.TestCase;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.request.TmfRangeFilter;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfRangeFilterTest</u></b>
+ * <p>
+ * Test suite for the TmfRangeFilter class.
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfRangeFilterTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final TmfRangeFilter ALL_EVENTS = TmfRangeFilter.ALL_EVENTS;
+
+    // ------------------------------------------------------------------------
+       // Housekeeping
+       // ------------------------------------------------------------------------
+
+    /**
+     * @param name the test name
+     */
+       public TmfRangeFilterTest(String name) {
+               super(name);
+       }
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+    // ------------------------------------------------------------------------
+       // Constructors
+       // ------------------------------------------------------------------------
+
+       @Test
+       public void testTmfRangeFilter() {
+           TmfRangeFilter filter = ALL_EVENTS;
+        assertEquals("getTimeRange", TmfTimeRange.ETERNITY, filter.getTimeRange());
+
+        TmfTimeRange range = TmfTimeRange.NULL_RANGE;
+        filter = new TmfRangeFilter(range);
+        assertEquals("getTimeRange", range, filter.getTimeRange());
+
+        range = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        filter = new TmfRangeFilter(range);
+        assertEquals("getTimeRange", range, filter.getTimeRange());
+
+        range = new TmfTimeRange(new TmfTimestamp(10), TmfTimestamp.BIG_CRUNCH);
+        filter = new TmfRangeFilter(range);
+        assertEquals("getTimeRange", range, filter.getTimeRange());
+       }
+
+    @Test
+    public void testTmfRangeFilterCopy() {
+        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range);
+        TmfRangeFilter filter2 = new TmfRangeFilter(filter1);
+
+        assertEquals("getTimeRange",   filter1.getTimeRange(),   filter2.getTimeRange());
+    }
+
+    // ------------------------------------------------------------------------
+       // equals
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        TmfTimeRange range1 = TmfTimeRange.ETERNITY;
+        TmfTimeRange range2 = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range2);
+
+        assertEquals("equals", filter1, filter1);
+        assertEquals("equals", filter2, filter2);
+
+        assertFalse("equals", filter1.equals(filter2));
+        assertFalse("equals", filter2.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        TmfTimeRange range1 = TmfTimeRange.ETERNITY;
+        TmfTimeRange range2 = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter3 = new TmfRangeFilter(range2);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter1);
+
+        assertFalse("equals", filter1.equals(filter3));
+        assertFalse("equals", filter3.equals(filter1));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range);
+        TmfRangeFilter filter3 = new TmfRangeFilter(range);
+
+        assertEquals("equals", filter1, filter2);
+        assertEquals("equals", filter2, filter3);
+        assertEquals("equals", filter3, filter1);
+    }
+
+    @Test
+    public void testEqualsNull() {
+        TmfTimeRange range1 = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(10), TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range2);
+
+        assertFalse("equals", filter1.equals(null));
+        assertFalse("equals", filter2.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        TmfTimeRange range1 = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(10), TmfTimestamp.BIG_CRUNCH);
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range2);
+
+        assertEquals("hashCode", filter1.hashCode(), filter1.hashCode());
+        assertEquals("hashCode", filter2.hashCode(), filter2.hashCode());
+        assertFalse("hashCode",  filter1.hashCode() == filter2.hashCode());
+    }
+
+       // ------------------------------------------------------------------------
+       // toString
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        TmfTimeRange range1 = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_CRUNCH);
+        TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(10), new TmfTimestamp(1000));
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range2);
+
+        String expected0 = "TmfRangeFilter [fTimeRange=TmfTimeRange [fStartTime=" + TmfTimestamp.BIG_BANG + ", fEndTime=" + TmfTimestamp.BIG_CRUNCH + "]]";
+        String expected1 = "TmfRangeFilter [fTimeRange=TmfTimeRange [fStartTime=" + TmfTimestamp.ZERO     + ", fEndTime=" + TmfTimestamp.BIG_CRUNCH + "]]";
+        String expected2 = "TmfRangeFilter [fTimeRange=TmfTimeRange [fStartTime=" + new TmfTimestamp(10) + ", fEndTime=" +  new TmfTimestamp(1000) + "]]";
+
+        assertEquals("toString", expected0, TmfRangeFilter.ALL_EVENTS.toString());
+        assertEquals("toString", expected1, filter1.toString());
+        assertEquals("toString", expected2, filter2.toString());
+    }
+
+    // ------------------------------------------------------------------------
+    // matches
+    // ------------------------------------------------------------------------
+
+    /**
+     * The only test that really matters...
+     */
+    @Test
+    public void testMatches() {
+
+        TmfTimeRange range1 = new TmfTimeRange(new TmfTimestamp(0), new TmfTimestamp(1000));
+        TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(10), new TmfTimestamp(2000));
+
+        TmfRangeFilter filter1 = new TmfRangeFilter(range1);
+        TmfRangeFilter filter2 = new TmfRangeFilter(range2);
+
+        ITmfEvent event = new TmfEvent(null, 0, new TmfTimestamp(0), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(5), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(9), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(10), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(999), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(1000), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertTrue ("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(1001), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(1999), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(2000), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertTrue ("matches", filter2.matches(event));
+
+        event = new TmfEvent(null, 0, new TmfTimestamp(2001), null, null, null, null);
+        assertTrue ("matches", TmfRangeFilter.ALL_EVENTS.matches(event));
+        assertFalse("matches", filter1.matches(event));
+        assertFalse("matches", filter2.matches(event));
+    }
+
+}
index bd6ef51b3c6de083c5a0d37249a542139a404d8f..81dcf906a74535f1fa3b2ac794e4ecbe373d53cf 100644 (file)
@@ -19,9 +19,9 @@ import org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor;
 import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
@@ -29,7 +29,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 /**
  * Test suite for the TmfRequestExecutor class.
  */
-@SuppressWarnings({ "nls" })
+@SuppressWarnings("nls")
 public class TmfRequestExecutorTest extends TestCase {
 
     // ------------------------------------------------------------------------
@@ -145,7 +145,7 @@ public class TmfRequestExecutorTest extends TestCase {
         public void broadcast(TmfSignal signal) {
         }
         @Override
-        public void sendRequest(ITmfDataRequest request) {
+        public void sendRequest(ITmfRequest request) {
         }
         @Override
         public void fireRequest() {
@@ -159,18 +159,18 @@ public class TmfRequestExecutorTest extends TestCase {
             return context.getRank() >= 0 ? fEvent : null;
         }
         @Override
-        public ITmfContext armRequest(ITmfDataRequest request) {
+        public ITmfContext armRequest(ITmfRequest request) {
             return new MyContext(request.getNbRequested());
         }
        }
 
        // Dummy request
-    private static class MyRequest extends TmfDataRequest {
-        public MyRequest(ExecutionType priority, int requested) {
-            super(ITmfEvent.class, 0, requested, priority);
+    private static class MyRequest extends TmfRequest {
+        public MyRequest(TmfRequestPriority priority, int requested) {
+            super(TmfTimeRange.ETERNITY, 0, requested, priority);
         }
         @Override
-        public void done() {
+        public synchronized void done() {
             synchronized (monitor) {
                 monitor.notifyAll();
             }
@@ -179,7 +179,7 @@ public class TmfRequestExecutorTest extends TestCase {
 
     // Dummy thread
     private static class MyThread extends TmfEventThread {
-        public MyThread(TmfDataProvider provider, ITmfDataRequest request) {
+        public MyThread(TmfDataProvider provider, ITmfRequest request) {
             super(provider, request);
         }
     }
@@ -191,11 +191,11 @@ public class TmfRequestExecutorTest extends TestCase {
         */
        public void testExecute() {
         MyProvider provider = new MyProvider();
-        MyRequest  request1 = new MyRequest(ExecutionType.BACKGROUND, Integer.MAX_VALUE /  5);
+        MyRequest  request1 = new MyRequest(ITmfRequest.TmfRequestPriority.NORMAL, Integer.MAX_VALUE /  50);
         MyThread   thread1  = new MyThread(provider, request1);
-        MyRequest  request2 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10);
+        MyRequest  request2 = new MyRequest(ITmfRequest.TmfRequestPriority.HIGH, Integer.MAX_VALUE / 100);
         MyThread   thread2  = new MyThread(provider, request2);
-        MyRequest  request3 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10);
+        MyRequest  request3 = new MyRequest(ITmfRequest.TmfRequestPriority.HIGH, Integer.MAX_VALUE / 100);
         MyThread   thread3  = new MyThread(provider, request3);
 
         // Start thread1
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestTest.java
new file mode 100644 (file)
index 0000000..e4eb57a
--- /dev/null
@@ -0,0 +1,870 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.request;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestState;
+import org.eclipse.linuxtools.tmf.core.request.TmfBlockFilter;
+import org.eclipse.linuxtools.tmf.core.request.TmfRangeFilter;
+import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfRequestStub;
+import org.junit.Test;
+
+/**
+ * <b><u>TmfRequestTest</u></b>
+ * <p>
+ * Test suite for the TmfRequest class.
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfRequestTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final TmfRequestPriority NORMAL = TmfRequestPriority.NORMAL;
+    private static final TmfRequestPriority HIGH = TmfRequestPriority.HIGH;
+
+    private static final long ALL_EVENTS = ITmfRequest.ALL_EVENTS;
+
+    private static final TmfTimeRange ETERNITY = TmfTimeRange.ETERNITY;
+    private static final TmfTimeRange EPOCH = new TmfTimeRange(TmfTimestamp.ZERO, TmfTimestamp.BIG_BANG);
+
+    private static final TmfRequestState PENDING = TmfRequestState.PENDING;
+    private static final TmfRequestState RUNNING = TmfRequestState.RUNNING;
+    private static final TmfRequestState COMPLETED = TmfRequestState.COMPLETED;
+
+    // ------------------------------------------------------------------------
+       // Variables
+       // ------------------------------------------------------------------------
+
+       private static ITmfRequest fRequest1;
+    private static ITmfRequest fRequest1b;
+    private static ITmfRequest fRequest1c;
+
+    private static ITmfRequest fRequest2;
+
+       private static int fLastRequestId;
+
+    // ------------------------------------------------------------------------
+       // Housekeeping
+       // ------------------------------------------------------------------------
+
+    /**
+     * @param name the test name
+     */
+       public TmfRequestTest(String name) {
+               super(name);
+       }
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+           fRequest1  = new TmfRequestStub();
+           fRequest1b = new TmfRequestStub();
+           fRequest1c = new TmfRequestStub();
+           fRequest2 = new TmfRequestStub(HIGH);
+           fLastRequestId = fRequest2.getRequestId();
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+    private static ITmfRequest setupDummyRequest(final boolean[] flags) {
+
+        ITmfRequest request = new TmfRequestStub(10, 100) {
+            @Override
+            public synchronized void handleCompleted() {
+                super.handleCompleted();
+                flags[0] = true;
+            }
+
+            @Override
+            public void handleSuccess() {
+                super.handleSuccess();
+                flags[1] = true;
+            }
+
+            @Override
+            public void handleFailure() {
+                super.handleFailure();
+                flags[2] = true;
+            }
+
+            @Override
+            public void handleCancel() {
+                super.handleCancel();
+                flags[3] = true;
+            }
+        };
+        fLastRequestId = request.getRequestId();
+        return request;
+    }
+
+    // ------------------------------------------------------------------------
+       // Constructors
+       // ------------------------------------------------------------------------
+
+       @Test
+       public void testTmfRequest() {
+        ITmfRequest request = new TmfRequestStub();
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+        assertEquals("getEventFilters", TmfBlockFilter.ALL_EVENTS, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("getEventFilters", TmfRangeFilter.ALL_EVENTS, request.getEventFilter(TmfRangeFilter.class));
+        assertNull("getParent", request.getParent());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+       }
+
+    @Test
+    public void testTmfRequestPriority() {
+
+        // 1. Normal priority
+        ITmfRequest request = new TmfRequestStub(TmfRequestPriority.NORMAL);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 2. High priority
+        request = new TmfRequestStub(TmfRequestPriority.HIGH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", HIGH, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testTmfRequestTimeRange() {
+
+        // 1. Eternity
+        ITmfRequest request = new TmfRequestStub(ETERNITY);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 2. Since the epoch
+        request = new TmfRequestStub(EPOCH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testTmfRequestBlock() {
+
+        // 1. All events
+        ITmfRequest request = new TmfRequestStub(0, ALL_EVENTS);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 2. For an event count
+        long nbRequested = 10000;
+        request = new TmfRequestStub(0, nbRequested);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 3. From a given index
+        long index = 100;
+        request = new TmfRequestStub(index, ALL_EVENTS);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 4. From a given index, for an event count
+        request = new TmfRequestStub(index, nbRequested);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testTmfRequestRangeAndBlock() {
+
+        // 1. All events since beginning of time
+        ITmfRequest request = new TmfRequestStub(ETERNITY, 0, ALL_EVENTS);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 2. All events since the epoch
+        request = new TmfRequestStub(EPOCH, 0, ALL_EVENTS);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 3. A block of events since the beginning of time
+        long nbRequested = 10000;
+        request = new TmfRequestStub(ETERNITY, 0, nbRequested);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 4. All events from a given index since the beginning of time
+        long index = 100;
+        request = new TmfRequestStub(ETERNITY, index, ALL_EVENTS);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 4. Some events from a given index since the epoch
+        request = new TmfRequestStub(EPOCH, index, nbRequested);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testTmfRequestRangeAndBlockWithPriority() {
+
+        // 1. All events since beginning of time
+        ITmfRequest request = new TmfRequestStub(ETERNITY, 0, ALL_EVENTS, NORMAL);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 2. All events since beginning of time, high priority
+        request = new TmfRequestStub(ETERNITY, 0, ALL_EVENTS, HIGH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", HIGH, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 3. A block of events since the beginning of time
+        long nbRequested = 10000;
+        long index = 100;
+        request = new TmfRequestStub(EPOCH, index, nbRequested, NORMAL);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        // 4. A block of events since the beginning of time, high priority
+        request = new TmfRequestStub(EPOCH, index, nbRequested, HIGH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", HIGH, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testTmfRequestCopy() {
+        TmfRequestStub other = new TmfRequestStub();
+        ITmfRequest request = new TmfRequestStub(other);
+        fLastRequestId += 2;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    // ------------------------------------------------------------------------
+       // equals
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        assertEquals("equals", fRequest1, fRequest1);
+        assertEquals("equals", fRequest2, fRequest2);
+
+        assertFalse("equals", fRequest1.equals(fRequest2));
+        assertFalse("equals", fRequest2.equals(fRequest1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        assertEquals("equals", fRequest1, fRequest1b);
+        assertEquals("equals", fRequest1b, fRequest1);
+
+        assertFalse("equals", fRequest1.equals(fRequest2));
+        assertFalse("equals", fRequest2.equals(fRequest1));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        assertEquals("equals", fRequest1, fRequest1b);
+        assertEquals("equals", fRequest1b, fRequest1c);
+        assertEquals("equals", fRequest1c, fRequest1);
+    }
+
+    @Test
+    public void testEqualsNull() {
+        assertFalse("equals", fRequest1.equals(null));
+        assertFalse("equals", fRequest2.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode());
+        assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode());
+        assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode());
+    }
+
+       // ------------------------------------------------------------------------
+       // toString
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        String expected1 = "TmfRequest [fRequestId=" + fRequest1.getRequestId() + "]";
+        String expected2 = "TmfRequest [fRequestId=" + fRequest2.getRequestId() + "]";
+
+        assertEquals("toString", expected1, fRequest1.toString());
+        assertEquals("toString", expected2, fRequest2.toString());
+    }
+
+    // ------------------------------------------------------------------------
+    // Setters
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testSetTimeRange() {
+
+        TmfRequestStub request = new TmfRequestStub(ETERNITY);
+        request.setTimeRange(EPOCH);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", EPOCH, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testSetNbRequested() {
+        long nbRequested = 10000;
+
+        TmfRequestStub request = new TmfRequestStub(ETERNITY, 0, ALL_EVENTS);
+        request.setNbRequested(nbRequested);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", nbRequested, request.getNbRequested());
+        assertEquals("getStartIndex", 0, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    @Test
+    public void testSetStartIndex() {
+        long index = 100;
+
+        TmfRequestStub request = new TmfRequestStub(ETERNITY, 0, ALL_EVENTS);
+        request.setStartIndex(index);
+        fLastRequestId++;
+
+        assertEquals("getRequestId", fLastRequestId, request.getRequestId());
+        assertEquals("getRequestPriority", NORMAL, request.getRequestPriority());
+        assertEquals("getTimeRange", ETERNITY, request.getTimeRange());
+        assertEquals("getNbRequested", ALL_EVENTS, request.getNbRequested());
+        assertEquals("getStartIndex", index, request.getStartIndex());
+
+        assertEquals("getNbEventsRead", 0, request.getNbEventsRead());
+        assertEquals("getState", PENDING, request.getState());
+        assertFalse("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+
+        assertNull("getStatus", request.getStatus());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+    }
+
+    // ------------------------------------------------------------------------
+    // setEventFilters, addEventFilter
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testSetEventFilters() {
+        TmfRequestStub request = new TmfRequestStub();
+        Collection<ITmfFilter> filters = new ArrayList<ITmfFilter>();
+        request.setEventFilters(filters);
+        assertEquals("setEventFilters", TmfBlockFilter.ALL_EVENTS, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", TmfRangeFilter.ALL_EVENTS, request.getEventFilter(TmfRangeFilter.class));
+
+        TmfBlockFilter blockFilter = new TmfBlockFilter(10, 1000);
+        filters.add(blockFilter);
+        request.setEventFilters(filters);
+        assertEquals("setEventFilters", blockFilter, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", TmfRangeFilter.ALL_EVENTS, request.getEventFilter(TmfRangeFilter.class));
+
+        TmfRangeFilter rangeFilter = new TmfRangeFilter(EPOCH);
+        filters.add(rangeFilter);
+        request.setEventFilters(filters);
+        assertEquals("setEventFilters", blockFilter, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", rangeFilter, request.getEventFilter(TmfRangeFilter.class));
+    }
+
+    @Test
+    public void testAddEventFilters() {
+        TmfRequestStub request = new TmfRequestStub();
+        Collection<ITmfFilter> filters = new ArrayList<ITmfFilter>();
+        request.setEventFilters(filters);
+        assertEquals("setEventFilters", TmfBlockFilter.ALL_EVENTS, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", TmfRangeFilter.ALL_EVENTS, request.getEventFilter(TmfRangeFilter.class));
+
+        TmfBlockFilter blockFilter = new TmfBlockFilter(10, 1000);
+        request.addEventFilter(blockFilter);
+        assertEquals("setEventFilters", blockFilter, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", TmfRangeFilter.ALL_EVENTS, request.getEventFilter(TmfRangeFilter.class));
+
+        TmfRangeFilter rangeFilter = new TmfRangeFilter(EPOCH);
+        request.addEventFilter(rangeFilter);
+        assertEquals("setEventFilters", blockFilter, request.getEventFilter(TmfBlockFilter.class));
+        assertEquals("setEventFilters", rangeFilter, request.getEventFilter(TmfRangeFilter.class));
+    }
+
+    // ------------------------------------------------------------------------
+    // setParent, notifyParent
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testSetParent() {
+        TmfRequestStub request1 = new TmfRequestStub();
+        TmfRequestStub request2 = new TmfRequestStub();
+
+        assertNull("getParent", request2.getParent());
+        request2.setParent(request1);
+        assertEquals("getParent", request1, request2.getParent());
+        request2.setParent(null);
+        assertNull("getParent", request2.getParent());
+    }
+
+    @Test
+    public void testNotifyParent() {
+        final Boolean[] notifications = new Boolean[2];
+        notifications[0] = notifications[1] = false;
+
+        TmfRequestStub request1 = new TmfRequestStub() {
+            @Override
+            public void notifyParent(ITmfRequest child) {
+                notifications[0] = true;
+                super.notifyParent(this);
+            }
+        };
+        TmfRequestStub request2 = new TmfRequestStub() {
+            @Override
+            public void notifyParent(ITmfRequest child) {
+                notifications[1] = true;
+                super.notifyParent(this);
+            }
+        };
+
+        request2.setParent(request1);
+        assertFalse("notifyParent", notifications[0]);
+        assertFalse("notifyParent", notifications[1]);
+
+        request2.notifyParent(null);
+        assertTrue("notifyParent", notifications[0]);
+        assertTrue("notifyParent", notifications[1]);
+    }
+
+    // ------------------------------------------------------------------------
+    // start
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testStart() {
+
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.start();
+
+        assertTrue("isRunning", request.isRunning());
+        assertFalse("isCompleted", request.isCompleted());
+        assertEquals("getState", RUNNING, request.getState());
+
+        assertNull("getStatus", request.getStatus());
+
+        assertFalse("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",   flags[1]);
+        assertFalse("handleFailure",   flags[2]);
+        assertFalse("handleCancel",    flags[3]);
+    }
+
+       // ------------------------------------------------------------------------
+       // done
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testDone() {
+
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.done();
+
+        assertFalse("isRunning", request.isRunning());
+        assertTrue("isCompleted", request.isCompleted());
+        assertEquals("getState", COMPLETED, request.getState());
+
+        assertEquals("getStatus", IStatus.OK, request.getStatus().getSeverity());
+        assertTrue("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertTrue("handleSuccess",   flags[1]);
+        assertFalse("handleFailure",  flags[2]);
+        assertFalse("handleCancel",   flags[3]);
+    }
+
+       // ------------------------------------------------------------------------
+       // fail
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testFail() {
+
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.fail();
+
+        assertFalse("isRunning", request.isRunning());
+        assertTrue("isCompleted", request.isCompleted());
+        assertEquals("getState", COMPLETED, request.getState());
+
+        assertEquals("getStatus", IStatus.ERROR, request.getStatus().getSeverity());
+        assertFalse("isOK", request.isOK());
+        assertTrue("isFailed", request.isFailed());
+        assertFalse("isCancelled", request.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",  flags[1]);
+        assertTrue("handleFailure",   flags[2]);
+        assertFalse("handleCancel",   flags[3]);
+    }
+
+       // ------------------------------------------------------------------------
+       // cancel
+       // ------------------------------------------------------------------------
+
+    @Test
+    public void testCancel() {
+
+        final boolean[] flags = new boolean[4];
+        ITmfRequest request = setupDummyRequest(flags);
+        request.cancel();
+
+        assertFalse("isRunning", request.isRunning());
+        assertTrue("isCompleted", request.isCompleted());
+        assertEquals("getState", COMPLETED, request.getState());
+
+        assertEquals("getStatus", IStatus.CANCEL, request.getStatus().getSeverity());
+        assertFalse("isOK", request.isOK());
+        assertFalse("isFailed", request.isFailed());
+        assertTrue("isCancelled", request.isCancelled());
+
+        assertTrue("handleCompleted", flags[0]);
+        assertFalse("handleSuccess",  flags[1]);
+        assertFalse("handleFailure",  flags[2]);
+        assertTrue("handleCancel",    flags[3]);
+    }
+
+}
index 34e51611c7b58fa2d9c8d74ac0b5ad2832daec1b..26a005788f02f7be24aceba217160ea0d496e934 100644 (file)
@@ -48,7 +48,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 /**
  * Test suite for the TmfExperiment class (single trace).
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfExperimentTest extends TestCase {
 
     // ------------------------------------------------------------------------
index cbeb4595d917bb76f852019329aaad7c6cfabeff..1591ff4db8a842d2eb7a2765e82da53d1ab3e671 100644 (file)
@@ -42,7 +42,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 /**
  * Test suite for the TmfExperiment class (multiple traces).
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfMultiTraceExperimentTest extends TestCase {
 
     // ------------------------------------------------------------------------
index 1b957a841643692c9cb83f5daa5dccc206df80ad..a007785bfd6e61796576f23b9a8920d20c8b1f53 100644 (file)
@@ -25,7 +25,7 @@ import junit.framework.TestCase;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
@@ -47,7 +47,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 /**
  * Test suite for the TmfTrace class.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfTraceTest extends TestCase {
 
     // ------------------------------------------------------------------------
@@ -1233,7 +1233,7 @@ public class TmfTraceTest extends TestCase {
                 requestedEvents.add(event);
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
@@ -1262,7 +1262,7 @@ public class TmfTraceTest extends TestCase {
                 requestedEvents.add(event);
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
@@ -1292,7 +1292,7 @@ public class TmfTraceTest extends TestCase {
                 requestedEvents.add(event);
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
@@ -1323,7 +1323,7 @@ public class TmfTraceTest extends TestCase {
                 requestedEvents.add(event);
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
@@ -1351,7 +1351,7 @@ public class TmfTraceTest extends TestCase {
                 requestedEvents.add(event);
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
@@ -1385,7 +1385,7 @@ public class TmfTraceTest extends TestCase {
                 }
             }
         };
-        final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
+        final ITmfEventProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
index dfb0c05e5cd89f03bcfc3b107fde408dcab69a0c..34f407cedd4cc1cbaf36fcf875b337270524c8f6 100644 (file)
@@ -23,8 +23,8 @@ import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 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.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
@@ -34,7 +34,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
  * <p>
  * TODO: Implement me. Please.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfDataProviderStub extends TmfDataProvider {
 
     private static final String DIRECTORY   = "testfiles";
@@ -64,7 +64,7 @@ public class TmfDataProviderStub extends TmfDataProvider {
     // ------------------------------------------------------------------------
 
     @Override
-    public ITmfContext armRequest(final ITmfDataRequest request) {
+    public ITmfContext armRequest(final ITmfRequest request) {
         if (request instanceof ITmfEventRequest) {
             final ITmfContext context = fTrace.seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
             return context;
@@ -78,7 +78,7 @@ public class TmfDataProviderStub extends TmfDataProvider {
     }
 
     @Override
-    public boolean isCompleted(final ITmfDataRequest request, final ITmfEvent data, final int nbRead) {
+    public boolean isCompleted(final ITmfRequest request, final ITmfEvent data, final int nbRead) {
         return false;
     }
 
index 66c2cb37cfd5ada8f7f5a69d875ce60b422675e2..e5c44e6d3bac810ebc53b75490cec5424f136483 100644 (file)
@@ -23,8 +23,7 @@ import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 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.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
@@ -70,12 +69,9 @@ public class TmfEventProviderStub extends TmfEventProvider {
     // ------------------------------------------------------------------------
 
     @Override
-    public ITmfContext armRequest(final ITmfDataRequest request) {
-        if (request instanceof ITmfEventRequest) {
-            final ITmfContext context = fTrace.seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
-            return context;
-        }
-        return null;
+    public ITmfContext armRequest(final ITmfRequest request) {
+        final ITmfContext context = fTrace.seekEvent(request.getTimeRange().getStartTime());
+        return context;
     }
 
     @Override
index 29b889d11553c5f820e2840abd4b6b79235a81f5..824e89f79e96bc66164909b0e64dfc0b49baf4fd 100644 (file)
@@ -15,13 +15,12 @@ package org.eclipse.linuxtools.tmf.tests.stubs.component;
 import java.util.concurrent.TimeUnit;
 
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
@@ -32,7 +31,7 @@ import org.eclipse.linuxtools.tmf.tests.stubs.event.TmfSyntheticEventStub;
  * <p>
  * TODO: Implement me. Please.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings({"nls","javadoc", "deprecation"})
 public class TmfSyntheticEventProviderStub extends TmfEventProvider {
 
     public static final int BLOCK_SIZE = 100;
@@ -43,17 +42,11 @@ public class TmfSyntheticEventProviderStub extends TmfEventProvider {
     }
 
     @Override
-    public ITmfContext armRequest(final ITmfDataRequest request) {
+    public ITmfContext armRequest(final ITmfRequest request) {
 
         // Get the TmfSyntheticEventStub provider
-        final ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
-        final ITmfDataProvider provider = eventProviders[0];
-
-        // make sure we have the right type of request
-        if (!(request instanceof ITmfEventRequest)) {
-            request.cancel();
-            return null;
-        }
+        final ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class);
+        final ITmfEventProvider provider = eventProviders[0];
 
         final TmfEventRequest eventRequest = (TmfEventRequest) request;
         final TmfTimeRange range = eventRequest.getRange();
index 545b803fa4575d95f19e8f5ef70f966b616c80da..48c38d731dbd499c00deab2179c6486b03d6e1f6 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 /**
  *
  */
+@SuppressWarnings("deprecation")
 public class TmfDataRequestStub extends TmfDataRequest {
 
     /**
index 3e2ba6a74b9c1582eb8e1d5e533868796d970e5a..79192c0eaab6a66d709b2511fe8fa64868359217 100644 (file)
@@ -70,7 +70,7 @@ public class TmfEventRequestStub extends TmfEventRequest {
      * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
      */
     @Override
-    public void handleData(final ITmfEvent data) {
-        super.handleData(data);
+    public synchronized void handleEvent(final ITmfEvent data) {
+        super.handleEvent(data);
     }
 }
diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/request/TmfRequestStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/request/TmfRequestStub.java
new file mode 100644 (file)
index 0000000..68ca3b5
--- /dev/null
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.tests.stubs.request;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.request.TmfRequest;
+
+/**
+ * <b><u>TmfRequestStub</u></b>
+ */
+public class TmfRequestStub extends TmfRequest {
+
+    /**
+     * Constructor for all the events at normal priority
+     */
+    public TmfRequestStub() {
+        super();
+    }
+
+    /**
+     * Constructor for all the events at the specified  priority
+     *
+     * @param priority the request priority
+     */
+    public TmfRequestStub(TmfRequestPriority priority) {
+        super(priority);
+    }
+
+    /**
+     * Constructor for all the events in a time range
+     *
+     * @param timeRange The time range
+     */
+    public TmfRequestStub(TmfTimeRange timeRange) {
+        super(timeRange);
+    }
+
+    /**
+     * Constructor for all the events in a block
+     *
+     * @param startIndex  The start index
+     * @param nbRequested The number of events requested
+     */
+    public TmfRequestStub(long startIndex, long nbRequested) {
+        super(startIndex, nbRequested);
+    }
+
+    /**
+     * Standard constructor
+     *
+     * @param timeRange   The time range
+     * @param startIndex  The start index
+     * @param nbRequested The number of events requested
+     */
+    public TmfRequestStub(TmfTimeRange timeRange, long startIndex, long nbRequested) {
+        super(timeRange, startIndex, nbRequested);
+    }
+
+    /**
+     * Full constructor
+     *
+     * @param timeRange   Time range of interest
+     * @param nbRequested Number of events requested
+     * @param startIndex  Index of the first event requested
+     * @param priority    Request priority
+     */
+    public TmfRequestStub(TmfTimeRange timeRange, long startIndex, long nbRequested, TmfRequestPriority priority) {
+        super(timeRange, startIndex, nbRequested, priority);
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other request
+     */
+    public TmfRequestStub(TmfRequestStub other) {
+        super(other);
+    }
+
+    /**
+     * @param timeRange the time range
+     */
+    @Override
+    public void setTimeRange(TmfTimeRange timeRange) {
+        super.setTimeRange(timeRange);
+    }
+
+    /**
+     * @param nbRequested the number of events requested
+     */
+    @Override
+    public void setNbRequested(long nbRequested) {
+        super.setNbRequested(nbRequested);
+    }
+
+    /**
+     * @param index the index of the first event requested
+     */
+    @Override
+    public void setStartIndex(long index) {
+        super.setStartIndex(index);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#handleEvent(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public synchronized void handleEvent(final ITmfEvent data) {
+        super.handleEvent(data);
+    }
+}
index 0dfd93ef6ed9ee243824487623ccb842b4db19ce..040ce9f8f7bfae2873aae99f2bbb0b484490fd4a 100644 (file)
@@ -106,7 +106,7 @@ public class TmfEventParserStub implements ITmfEventParser {
                 content.append("]");
 
                 final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
-                final TmfEvent event = new TmfEvent(fEventStream,
+                final TmfEvent event = new TmfEvent(fEventStream, context.getRank(),
                         new TmfTimestamp(ts, -3, 0),     // millisecs
                         source, fTypes[typeIndex], root, reference.toString());
                 return event;
index 54b6ac1870eab2cb708ab005d91156684180208a..8998620bb217ed0171ebebbc76ea856277167570 100644 (file)
@@ -18,9 +18,9 @@ import java.io.IOException;
 
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 
 /**
@@ -38,8 +38,8 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
  * <li><strong>Event</strong>: TMF trace events
  * </ul>
  *
- * @version 1.0
  * @author Francois Chouinard
+ * @version 1.0
  */
 @SuppressWarnings("nls")
 public class TmfCoreTracer {
@@ -209,7 +209,7 @@ public class TmfCoreTracer {
     }
 
     @SuppressWarnings("javadoc")
-    public static void traceRequest(ITmfDataRequest request, String msg) {
+    public static void traceRequest(ITmfRequest request, String msg) {
         if (REQUEST_CLASS_ENABLED) {
             String message = ("[REQ] Req=" + request.getRequestId() + " " + msg);
             trace(message);
@@ -226,7 +226,7 @@ public class TmfCoreTracer {
     }
 
     @SuppressWarnings("javadoc")
-    public static void traceEvent(ITmfDataProvider provider, ITmfDataRequest request, ITmfEvent event) {
+    public static void traceEvent(ITmfEventProvider provider, ITmfRequest request, ITmfEvent event) {
         if (EVENT_CLASS_ENABLED) {
             String message = ("[EVT] Provider=" + provider.toString()
                     + ", Req=" + request.getRequestId() + ", Event=" + event.getTimestamp());
index 97c95cbdc641e2539422df51974eeba540afbd66..173f0546500977c87e2261db424e97b75c7ab423 100644 (file)
 package org.eclipse.linuxtools.internal.tmf.core.component;
 
 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
 /**
@@ -41,12 +41,12 @@ public class TmfEventThread implements Runnable {
     /**
      * The wrapped event request
      */
-    private final ITmfDataRequest fRequest;
+    private final ITmfRequest fRequest;
 
     /**
      * The request execution priority
      */
-    private final ExecutionType   fExecType;
+    private final TmfRequestPriority fExecType;
 
     /**
      * The wrapped thread (if applicable)
@@ -74,12 +74,12 @@ public class TmfEventThread implements Runnable {
      * @param provider the event provider
      * @param request the request to process
      */
-    public TmfEventThread(TmfDataProvider provider, ITmfDataRequest request) {
+    public TmfEventThread(TmfDataProvider provider, ITmfRequest request) {
         assert provider != null;
         assert request  != null;
         fProvider = provider;
         fRequest  = request;
-        fExecType = request.getExecType();
+        fExecType = request.getRequestPriority();
         fThread   = null;
     }
 
@@ -109,21 +109,21 @@ public class TmfEventThread implements Runnable {
     /**
      * @return The event provider
      */
-    public ITmfDataProvider getProvider() {
+    public ITmfEventProvider getProvider() {
         return fProvider;
     }
 
     /**
      * @return The event request
      */
-    public ITmfDataRequest getRequest() {
+    public ITmfRequest getRequest() {
         return fRequest;
     }
 
     /**
      * @return The request execution priority
      */
-    public ExecutionType getExecType() {
+    public TmfRequestPriority getExecType() {
         return fExecType;
     }
 
@@ -155,7 +155,7 @@ public class TmfEventThread implements Runnable {
 
         // Extract the generic information
         fRequest.start();
-        int nbRequested = fRequest.getNbRequested();
+        long nbRequested = fRequest.getNbRequested();
         int nbRead = 0;
         isCompleted = false;
 
@@ -184,9 +184,7 @@ public class TmfEventThread implements Runnable {
                 }
 
                 TmfCoreTracer.traceEvent(fProvider, fRequest, event);
-                if (fRequest.getDataType().isInstance(event)) {
-                    fRequest.handleData(event);
-                }
+                fRequest.handleEvent(event);
 
                 // To avoid an unnecessary read passed the last event requested
                 if (++nbRead < nbRequested) {
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedDataRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedDataRequest.java
deleted file mode 100644 (file)
index d8a2e3b..0000000
+++ /dev/null
@@ -1,350 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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.internal.tmf.core.request;
-
-import java.util.Vector;
-
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-
-/**
- * The TMF coalesced data request
- *
- * @version 1.0
- * @author Francois Chouinard
- */
-public class TmfCoalescedDataRequest extends TmfDataRequest {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-       /**
-        * The list of coalesced requests
-        */
-       protected Vector<ITmfDataRequest> fRequests = new Vector<ITmfDataRequest>();
-
-    // ------------------------------------------------------------------------
-    // Constructor
-    // ------------------------------------------------------------------------
-
-    /**
-     * Request all the events of a given type (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType) {
-        this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request all the events of a given type (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, ExecutionType priority) {
-        this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request all the events of a given type from the given index (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index) {
-        this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request all the events of a given type from the given index (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, ExecutionType priority) {
-        this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request 'n' events of a given type from the given index (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     * @param nbRequested the number of events requested
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested) {
-        this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request 'n' events of a given type from the given index (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     * @param nbRequested the number of events requested
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, ExecutionType priority) {
-        this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request 'n' events of a given type from the given index (high priority).
-     * Events are returned in blocks of the given size.
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     * @param nbRequested the number of events requested
-     * @param blockSize the number of events per block
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, int blockSize) {
-        super(ITmfEvent.class, index, nbRequested, blockSize, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request 'n' events of a given type from the given index (given priority).
-     * Events are returned in blocks of the given size.
-     *
-     * @param dataType the requested data type
-     * @param index the index of the first event to retrieve
-     * @param nbRequested the number of events requested
-     * @param blockSize the number of events per block
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, int blockSize, ExecutionType priority) {
-        super(ITmfEvent.class, index, nbRequested, blockSize, priority);
-    }
-
-    // ------------------------------------------------------------------------
-    // Management
-    // ------------------------------------------------------------------------
-
-    /**
-     * Add a request to this one.
-     *
-     * @param request The request to add
-     */
-    public void addRequest(ITmfDataRequest request) {
-        fRequests.add(request);
-        merge(request);
-    }
-
-    /**
-     * Check if a request is compatible with the current coalesced one
-     *
-     * @param request
-     *            The request to verify
-     * @return If the request is compatible, true or false
-     */
-    public boolean isCompatible(ITmfDataRequest request) {
-        if (request.getExecType() == getExecType()) {
-            return overlaps(request);
-        }
-        return false;
-    }
-
-    private boolean overlaps(ITmfDataRequest request) {
-        long start = request.getIndex();
-        long end = start + request.getNbRequested();
-
-        // Return true if either the start or end index falls within
-        // the coalesced request boundaries
-        return (start <= (fIndex + fNbRequested + 1) && (end >= fIndex - 1));
-    }
-
-    private void merge(ITmfDataRequest request) {
-        long start = request.getIndex();
-        long end = Math.min(start + request.getNbRequested(), TmfDataRequest.ALL_DATA);
-
-        if (start < fIndex) {
-            if (fNbRequested != TmfDataRequest.ALL_DATA) {
-                fNbRequested += (fIndex - start);
-            }
-            fIndex = start;
-        }
-        if ((request.getNbRequested() == TmfDataRequest.ALL_DATA) ||
-             (fNbRequested == TmfDataRequest.ALL_DATA))
-        {
-            fNbRequested = TmfDataRequest.ALL_DATA;
-        } else {
-            fNbRequested = (int) Math.max(end - fIndex, fNbRequested);
-        }
-    }
-
-       /**
-        * @return The list of IDs of the sub-requests
-        */
-       @SuppressWarnings("nls")
-    public String getSubRequestIds() {
-           StringBuffer result = new StringBuffer("[");
-           for (int i = 0; i < fRequests.size(); i++) {
-               if (i != 0) {
-                result.append(", ");
-            }
-               result.append(fRequests.get(i).getRequestId());
-           }
-           result.append("]");
-           return result.toString();
-       }
-
-    // ------------------------------------------------------------------------
-    // ITmfDataRequest
-    // ------------------------------------------------------------------------
-
-    @Override
-       public void handleData(ITmfEvent data) {
-               super.handleData(data);
-       // Don't call sub-requests handleData() unless this is a
-               // TmfCoalescedDataRequest; extended classes should call
-               // the sub-requests handleData().
-               if (getClass() == TmfCoalescedDataRequest.class) {
-                   long index = getIndex() + getNbRead() - 1;
-               for (ITmfDataRequest request : fRequests) {
-                   if (!request.isCompleted()) {
-                    if (request.getDataType().isInstance(data)) {
-                        long start = request.getIndex();
-                        long end = start + request.getNbRequested();
-                        if (index >= start && index < end) {
-                            request.handleData(data);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void start() {
-        for (ITmfDataRequest request : fRequests) {
-            if (!request.isCompleted()) {
-                request.start();
-            }
-        }
-        super.start();
-    }
-
-       @Override
-    public void done() {
-       for (ITmfDataRequest request : fRequests) {
-           if (!request.isCompleted()) {
-               request.done();
-           }
-       }
-       super.done();
-    }
-
-    @Override
-    public void fail() {
-       for (ITmfDataRequest request : fRequests) {
-               request.fail();
-       }
-       super.fail();
-    }
-
-    @Override
-    public void cancel() {
-       for (ITmfDataRequest request : fRequests) {
-           if (!request.isCompleted()) {
-               request.cancel();
-           }
-       }
-       super.cancel();
-    }
-
-    @Override
-    public synchronized boolean isCompleted() {
-        // Firstly, check if coalescing request is completed
-        if (super.isCompleted()) {
-            return true;
-        }
-
-        // Secondly, check if all sub-requests are finished
-        if (fRequests.size() > 0) {
-            // If all sub requests are completed the coalesced request is
-            // treated as completed, too.
-            for (ITmfDataRequest request : fRequests) {
-                if (!request.isCompleted()) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        // Coalescing request is not finished if there are no sub-requests
-        return false;
-    }
-
-    @Override
-    public synchronized boolean isCancelled() {
-        // Firstly, check if coalescing request is canceled
-        if (super.isCancelled()) {
-            return true;
-        }
-
-        // Secondly, check if all sub-requests are canceled
-        if (fRequests.size() > 0) {
-            // If all sub requests are canceled the coalesced request is
-            // treated as completed, too.
-            for (ITmfDataRequest request : fRequests) {
-                if (!request.isCancelled()) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        // Coalescing request is not canceled if there are no sub-requests
-        return false;
-
-    }
-
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    // All requests have a unique id
-    public int hashCode() {
-       return super.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object other) {
-       if (other instanceof TmfCoalescedDataRequest) {
-               TmfCoalescedDataRequest request = (TmfCoalescedDataRequest) other;
-                       return  (request.getDataType()    == getDataType())   &&
-                                       (request.getIndex()       == getIndex())      &&
-                                       (request.getNbRequested() == getNbRequested() &&
-                               (request.getExecType()    == getExecType()));
-               }
-               return false;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-               return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
-                       + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
-    }
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java
deleted file mode 100644 (file)
index 80f1ae8..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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.internal.tmf.core.request;
-
-import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-
-/**
- * The TMF coalesced event request
- *
- * @version 1.0
- * @author Francois Chouinard
- */
-public class TmfCoalescedEventRequest extends TmfCoalescedDataRequest implements ITmfEventRequest {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-       private TmfTimeRange fRange;    // The requested events time range
-
-    // ------------------------------------------------------------------------
-    // Constructor
-    // ------------------------------------------------------------------------
-
-    /**
-     * Request all the events of a given type (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType) {
-        this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request all the events of a given type (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, ExecutionType priority) {
-        this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request all the events of a given type for the given time range (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range) {
-        this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request all the events of a given type for the given time range (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, ExecutionType priority) {
-        this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request 'n' events of a given type from the given time range (high priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param nbRequested the number of events requested
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested) {
-        this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request 'n' events of a given type for the given time range (given priority)
-     * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param nbRequested the number of events requested
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) {
-        this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, priority);
-    }
-
-    /**
-     * Request 'n' events of a given type for the given time range (high priority).
-     * Events are returned in blocks of the given size.
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param nbRequested the number of events requested
-     * @param blockSize the number of events per block
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize) {
-        this(dataType, range, 0, nbRequested, blockSize, ExecutionType.FOREGROUND);
-    }
-
-    /**
-     * Request 'n' events of a given type for the given time range (given priority).
-     * Events are returned in blocks of the given size.
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param nbRequested the number of events requested
-     * @param blockSize the number of events per block
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) {
-        this(dataType, range, 0, nbRequested, blockSize, priority);
-    }
-
-    /**
-     * Request 'n' events of a given type for the given time range (given priority).
-     * Events are returned in blocks of the given size.
-     *
-     * @param dataType the requested data type
-     * @param range the time range of the requested events
-     * @param index the index of the first event to retrieve
-     * @param nbRequested the number of events requested
-     * @param blockSize the number of events per block
-     * @param priority the requested execution priority
-     */
-    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
-        super(ITmfEvent.class, index, nbRequested, blockSize, priority);
-        fRange = range;
-
-        if (TmfCoreTracer.isRequestTraced()) {
-            String type = getClass().getName();
-            type = type.substring(type.lastIndexOf('.') + 1);
-            @SuppressWarnings("nls")
-            String message = "CREATED "
-                    + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)")
-                    + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested()
-                    + " Range=" + getRange()
-                    + " DataType=" + getDataType().getSimpleName();
-            TmfCoreTracer.traceRequest(this, message);
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Management
-    // ------------------------------------------------------------------------
-
-    @Override
-    public void addRequest(ITmfDataRequest request) {
-        super.addRequest(request);
-        if (request instanceof ITmfEventRequest) {
-            merge((ITmfEventRequest) request);
-        }
-    }
-
-       @Override
-       public boolean isCompatible(ITmfDataRequest request) {
-           if (request instanceof ITmfEventRequest) {
-               if (super.isCompatible(request)) {
-                   return overlaps((ITmfEventRequest) request);
-               }
-           }
-           return false;
-       }
-
-    private boolean overlaps(ITmfEventRequest request) {
-        ITmfTimestamp startTime = request.getRange().getStartTime();
-        ITmfTimestamp endTime   = request.getRange().getEndTime();
-        return (startTime.compareTo(endTime) <= 0) && (fRange.getStartTime().compareTo(fRange.getEndTime()) <= 0);
-    }
-
-    private void merge(ITmfEventRequest request) {
-        ITmfTimestamp startTime = request.getRange().getStartTime();
-        ITmfTimestamp endTime   = request.getRange().getEndTime();
-        if (!fRange.contains(startTime) && fRange.getStartTime().compareTo(startTime) > 0) {
-            fRange = new TmfTimeRange(startTime, fRange.getEndTime());
-        }
-        if (!fRange.contains(endTime) && fRange.getEndTime().compareTo(endTime) < 0) {
-            fRange = new TmfTimeRange(fRange.getStartTime(), endTime);
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfDataRequest
-    // ------------------------------------------------------------------------
-
-    @Override
-    public void handleData(ITmfEvent data) {
-        super.handleData(data);
-        long index = getIndex() + getNbRead() - 1;
-        for (ITmfDataRequest request : fRequests) {
-            if (data == null) {
-                request.handleData(null);
-            } else {
-                long start = request.getIndex();
-                long end = start + request.getNbRequested();
-                if (request instanceof ITmfEventRequest) {
-                    ITmfEventRequest req = (ITmfEventRequest) request;
-                    if (!req.isCompleted() && index >= start && index < end) {
-                        ITmfTimestamp ts = data.getTimestamp();
-                        if (req.getRange().contains(ts)) {
-                            if (req.getDataType().isInstance(data)) {
-                                req.handleData(data);
-                            }
-                        }
-                    }
-                }
-                else {
-                    TmfDataRequest req = (TmfDataRequest) request;
-                    if (!req.isCompleted() && index >= start && index < end) {
-                        if (req.getDataType().isInstance(data)) {
-                            req.handleData(data);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfEventRequest
-    // ------------------------------------------------------------------------
-
-       @Override
-       public TmfTimeRange getRange() {
-               return fRange;
-       }
-
-       @Override
-       public void setStartIndex(int index) {
-               setIndex(index);
-       }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    // All requests have a unique id
-    public int hashCode() {
-       return super.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object other) {
-       if (other instanceof TmfCoalescedEventRequest) {
-               TmfCoalescedEventRequest request = (TmfCoalescedEventRequest) other;
-                       return  (request.getDataType()    == getDataType()) &&
-                                       (request.getIndex()       == getIndex())    &&
-                                       (request.getNbRequested() == getNbRequested()) &&
-                               (request.getRange().equals(getRange()));
-               }
-       if (other instanceof TmfCoalescedDataRequest) {
-                       return super.equals(other);
-       }
-               return false;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-               return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
-                       + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedRequest.java
new file mode 100644 (file)
index 0000000..2c7a268
--- /dev/null
@@ -0,0 +1,412 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.core.request;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfBlockFilter;
+import org.eclipse.linuxtools.tmf.core.request.TmfRangeFilter;
+import org.eclipse.linuxtools.tmf.core.request.TmfRequest;
+
+/**
+ * The TMF coalesced request
+ * <p>
+ * Since different TMF components can issue simultaneous requests to their event
+ * provider (e.g. as the result of a user action), it is desirable to coalesce
+ * these requests when possible in order to reduce costly I/O with the back-end.
+ * <p>
+ * The TmfCoalescedRequest acts as a request aggregator. It bundles compatible
+ * requests and is the one dispatched to the event provider. As each event is
+ * read in sequence, it re-distributes them to its sub-requests as appropriate.
+ * <p>
+ * The sub-request compatibility is evaluated based on the following criteria:
+ * <ul>
+ * <li>Request type (pre-emptible or not)
+ * <li>Block ranges (start index + nb requested) overlap or are contiguous
+ * <li>Time ranges overlap or are contiguous
+ * </ul>
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ */
+public class TmfCoalescedRequest extends TmfRequest {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+   /** The list of coalesced requests */
+   private final List<ITmfRequest> fSubRequests = new ArrayList<ITmfRequest>();
+
+    /** The list of coalesced requests */
+    private int fNbSubRequests;
+
+   // ------------------------------------------------------------------------
+    // Constructor
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor
+     */
+    public TmfCoalescedRequest() {
+        this(TmfRequestPriority.NORMAL);
+    }
+
+    /**
+     * Basic constructor
+     * @param priority the request priority
+     */
+    public TmfCoalescedRequest(TmfRequestPriority priority) {
+       super(priority);
+    }
+
+    /**
+     * Create a coalesced request based on the provided request
+     *
+     * @param request the base request
+     */
+    public TmfCoalescedRequest(ITmfRequest request) {
+        super(request != null ? request.getRequestPriority() : null);
+
+        // Initialize sub-requests list with the request
+        if (request != null) {
+            fSubRequests.add(request);
+            fNbSubRequests++;
+            request.setParent(this);
+
+            // Collect the filter values of interestIndex
+            TmfBlockFilter blockFilter = (TmfBlockFilter) request.getEventFilter(TmfBlockFilter.class);
+            long startIndex = blockFilter.getStartIndex();
+            long nbRequested = blockFilter.getNbRequested();
+            addEventFilter(new TmfBlockFilter(startIndex, nbRequested));
+
+            TmfRangeFilter rangeFilter = (TmfRangeFilter) request.getEventFilter(TmfRangeFilter.class);
+            TmfTimeRange timeRange = rangeFilter.getTimeRange();
+            addEventFilter(new TmfRangeFilter(timeRange));
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Request execution state
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#isCompleted()
+     */
+    @Override
+    public synchronized boolean isCompleted() {
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCompleted()) {
+                return false;
+            }
+        }
+        return super.isCompleted();
+    }
+
+    // ------------------------------------------------------------------------
+    // Request completion status
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#isCancelled()
+     */
+    @Override
+    public synchronized boolean isCancelled() {
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCancelled()) {
+                return false;
+            }
+        }
+        return super.isCancelled();
+    }
+
+    // ------------------------------------------------------------------------
+    // Request operations
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#start()
+     */
+    @Override
+    public void start() {
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCompleted()) {
+                request.start();
+            }
+        }
+        super.start();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#done()
+     */
+    @Override
+    public void done() {
+        if (fRequestStatus == null) {
+            fRequestStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, "OK", null); //$NON-NLS-1$
+            for (ITmfRequest request : fSubRequests) {
+                if (!request.isCompleted()) {
+                    request.done();
+                }
+                ((MultiStatus) fRequestStatus).add(request.getStatus());
+            }
+        }
+        super.done();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#fail()
+     */
+    @Override
+    public void fail() {
+        fRequestStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "FAIL", null); //$NON-NLS-1$
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCompleted()) {
+                request.fail();
+                ((MultiStatus) fRequestStatus).add(request.getStatus());
+            }
+        }
+        super.fail();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#cancel()
+     */
+    @Override
+    public void cancel() {
+        fRequestStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.CANCEL, "CANCEL", null); //$NON-NLS-1$
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCompleted()) {
+                request.cancel();
+            }
+            ((MultiStatus) fRequestStatus).add(request.getStatus());
+        }
+        super.cancel();
+    }
+
+    // ------------------------------------------------------------------------
+    // Request processing hooks
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#handleEvent(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public synchronized void handleEvent(ITmfEvent event) {
+        super.handleEvent(event);
+        for (ITmfRequest request : fSubRequests) {
+            if (!request.isCompleted() && request.matches(event)) {
+                request.handleEvent(event);
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#notifyParent(org.eclipse.linuxtools.tmf.core.request.ITmfRequest)
+     */
+    @Override
+    public void notifyParent(ITmfRequest child) {
+        if (--fNbSubRequests <= 0) {
+            done();
+            super.notifyParent(this);
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Management
+    // ------------------------------------------------------------------------
+
+    /**
+     * Add a request to this one.
+     *
+     * @param request The request to add
+     * @return true if the request was successfully coalesced, false otherwise
+     */
+    public synchronized boolean addRequest(ITmfRequest request) {
+        if (isCompatible(request)) {
+            fSubRequests.add(request);
+            fNbSubRequests++;
+            request.setParent(this);
+            adjustFilters(request);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @return The list of IDs of the sub-requests
+     */
+    @SuppressWarnings("nls")
+    public String getSubRequestIds() {
+        StringBuffer result = new StringBuffer("[");
+        for (int i = 0; i < fSubRequests.size(); i++) {
+            if (i != 0) {
+                result.append(",");
+            }
+            result.append(fSubRequests.get(i).getRequestId());
+        }
+        result.append("]");
+        return result.toString();
+    }
+
+    // ------------------------------------------------------------------------
+    // Compatibility checks
+    // ------------------------------------------------------------------------
+
+    /**
+     * Check if a request is compatible i.e. can be coalesced with the
+     * other sub-requests.
+     * Compatibility is evaluated on the following criteria:
+     * - Request type (pre-emptible or not)
+     * - Block parameters (start index + requested)
+     * - Time range
+     *
+     * @param request The request to evaluate
+     * @return true if the request is compatible, false otherwise
+     */
+    public boolean isCompatible(ITmfRequest request) {
+        if (request.getRequestPriority() != getRequestPriority()) {
+            return false;
+        }
+        // Check the block range
+        TmfBlockFilter blockFilter = (TmfBlockFilter) request.getEventFilter(TmfBlockFilter.class);
+        if (!isCompatible(blockFilter)) {
+            return false;
+        }
+        // Check the time range
+        TmfRangeFilter rangeFilter = (TmfRangeFilter) request.getEventFilter(TmfRangeFilter.class);
+        if (!isCompatible(rangeFilter)) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Check if the filter time range overlaps the coalesced request time range.
+     * The test boils down to a verification of the intersection of the ranges.
+     *
+     * @param filter the time range filter to test
+     * @return true if the time range is compatible; false otherwise
+     */
+    private boolean isCompatible(TmfRangeFilter filter) {
+        TmfRangeFilter rangeFilter = (TmfRangeFilter) getEventFilter(TmfRangeFilter.class);
+        return rangeFilter.getTimeRange().getIntersection(filter.getTimeRange()) != null;
+    }
+
+    /**
+     * Check if the filter block overlaps the coalesced request block.
+     * The test boils down to a verification that at least one of the block
+     * boundaries falls within the other block boundaries.
+     *
+     * @param filter the block filter to test
+     * @return true if the time range is compatible; false otherwise
+     */
+    private boolean isCompatible(TmfBlockFilter filter) {
+        TmfBlockFilter blockFilter = (TmfBlockFilter) getEventFilter(TmfBlockFilter.class);
+        return filter.getStartIndex() - 1 <= (blockFilter.getEndIndex()) &&
+               filter.getEndIndex() - 1   >= (blockFilter.getStartIndex());
+    }
+
+    // ------------------------------------------------------------------------
+    // Filter adjustments
+    // ------------------------------------------------------------------------
+
+    /**
+     * Adjust the coalesced request filters based on a given request
+     *
+     * @param request the request to consider
+     */
+    private void adjustFilters(ITmfRequest request) {
+        TmfBlockFilter blockFilter = (TmfBlockFilter) request.getEventFilter(TmfBlockFilter.class);
+        adjustFilter(blockFilter);
+        TmfRangeFilter rangeFilter = (TmfRangeFilter) request.getEventFilter(TmfRangeFilter.class);
+        adjustFilter(rangeFilter);
+    }
+
+    /**
+     * @param filter the block filter to adjust
+     */
+    private void adjustFilter(TmfBlockFilter filter) {
+        TmfBlockFilter blockFilter = (TmfBlockFilter) getEventFilter(TmfBlockFilter.class);
+        long startIndex = Math.min(blockFilter.getStartIndex(), filter.getStartIndex());
+        long endIndex   = Math.max(blockFilter.getEndIndex(), filter.getEndIndex());
+        long nbRequested = endIndex - startIndex;
+        addEventFilter(new TmfBlockFilter(startIndex, nbRequested));
+    }
+
+    /**
+     * @param filter the time range filter to adjust
+     */
+    private void adjustFilter(TmfRangeFilter filter) {
+        TmfRangeFilter rangeFilter = (TmfRangeFilter) getEventFilter(TmfRangeFilter.class);
+        TmfTimeRange timeRange = rangeFilter.getTimeRange().getUnion(filter.getTimeRange());
+        addEventFilter(new TmfRangeFilter(timeRange));
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fSubRequests == null) ? 0 : fSubRequests.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (!(obj instanceof TmfCoalescedRequest)) {
+            return false;
+        }
+        TmfCoalescedRequest other = (TmfCoalescedRequest) obj;
+        if (fSubRequests == null) {
+            if (other.fSubRequests != null) {
+                return false;
+            }
+        } else if (!fSubRequests.equals(other.fSubRequests)) {
+            return false;
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#toString()
+     */
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfCoalescedRequest [fSubRequests=" + fSubRequests + "]";
+    }
+
+}
index 2be614393454e30adddc921bb08a4dd220a34672..96e029c9da0e2e3a38409440705faf61e0e0cb32 100644 (file)
@@ -21,7 +21,7 @@ import java.util.concurrent.Executors;
 
 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfEventThread;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
 
 /**
  * A simple, straightforward request executor.
@@ -41,7 +41,7 @@ public class TmfRequestExecutor implements Executor {
 
        // The request queues
        private final Queue<TmfEventThread> fHighPriorityTasks = new ArrayBlockingQueue<TmfEventThread>(100);
-    private final Queue<TmfEventThread> fLowPriorityTasks  = new ArrayBlockingQueue<TmfEventThread>(100);
+    private final Queue<TmfEventThread> fNormPriorityTasks = new ArrayBlockingQueue<TmfEventThread>(100);
 
        // The tasks
        private TmfEventThread fActiveTask;
@@ -81,7 +81,7 @@ public class TmfRequestExecutor implements Executor {
         */
     @Deprecated
        public synchronized int getNbPendingRequests() {
-               return fHighPriorityTasks.size() + fLowPriorityTasks.size();
+               return fHighPriorityTasks.size() + fNormPriorityTasks.size();
        }
 
        /**
@@ -128,13 +128,13 @@ public class TmfRequestExecutor implements Executor {
         };
 
         // Add the thread to the appropriate queue
-        ExecutionType priority = thread.getExecType();
-        (priority == ExecutionType.FOREGROUND ? fHighPriorityTasks : fLowPriorityTasks).offer(wrapper);
+        TmfRequestPriority priority = thread.getExecType();
+        (priority == TmfRequestPriority.HIGH ? fHighPriorityTasks : fNormPriorityTasks).offer(wrapper);
 
         // Schedule or preempt as appropriate
         if (fActiveTask == null) {
             scheduleNext();
-        } else if (priority == ExecutionType.FOREGROUND && priority != fActiveTask.getExecType()) {
+        } else if (priority == TmfRequestPriority.HIGH && priority != fActiveTask.getExecType()) {
             fActiveTask.getThread().suspend();
             fSuspendedTask = fActiveTask;
             scheduleNext();
@@ -152,7 +152,7 @@ public class TmfRequestExecutor implements Executor {
                        fActiveTask = fSuspendedTask;
                        fSuspendedTask = null;
                        fActiveTask.getThread().resume();
-                   } else if ((fActiveTask = fLowPriorityTasks.poll()) != null) {
+                   } else if ((fActiveTask = fNormPriorityTasks.poll()) != null) {
                        fExecutor.execute(fActiveTask);
                    }
                }
index de62ee1da353e6720f97b780da1d386de4ef2783..ffa595aad2f9ced24fcfe399b4c89636cf64064c 100644 (file)
@@ -41,6 +41,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
  * @author alexmont
  *
  */
+@SuppressWarnings("deprecation")
 public class HistoryBuilder extends TmfComponent {
 
     private final IStateChangeInput sci;
@@ -233,6 +234,7 @@ class StateSystemBuildRequest extends TmfEventRequest {
     private final IStateChangeInput sci;
     private final ITmfTrace trace;
 
+    @SuppressWarnings("deprecation")
     StateSystemBuildRequest(HistoryBuilder builder) {
         super(builder.getInputPlugin().getExpectedEventType(),
                 TmfTimeRange.ETERNITY,
@@ -245,6 +247,7 @@ class StateSystemBuildRequest extends TmfEventRequest {
     }
 
     @Override
+    @SuppressWarnings("deprecation")
     public void handleData(final ITmfEvent event) {
         super.handleData(event);
         if (event != null) {
index bb993c41b6e0d3b409df74a384dff222f3a37b3b..59c636a4892e83216be210cc6fde5524246a66da 100644 (file)
 package org.eclipse.linuxtools.tmf.core.component;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
 /**
  * This is the interface of the data providers in TMF. Data providers have the
  * capability of handling data requests.
  *
- * @version 1.0
  * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
  *
  * @see TmfDataProvider
  * @see TmfEventProvider
@@ -33,7 +34,7 @@ public interface ITmfDataProvider extends ITmfComponent {
      *
      * @param request The request to process
      */
-    public void sendRequest(ITmfDataRequest request);
+    public void sendRequest(ITmfRequest request);
 
     /**
      * Queue the coalesced requests.
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/ITmfEventProvider.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/ITmfEventProvider.java
new file mode 100644 (file)
index 0000000..a7e2769
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.component;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+
+/**
+ * This is the interface of the event providers in TMF. Event providers have the
+ * capability of handling event requests.
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ *
+ * @see TmfDataProvider
+ * @see TmfEventProvider
+ */
+public interface ITmfEventProvider extends ITmfComponent {
+
+    /**
+     * Queue the request for processing.
+     *
+     * @param request The request to process
+     */
+    public void sendRequest(ITmfRequest request);
+
+    /**
+     * Queue the coalesced requests.
+     */
+    public void fireRequest();
+
+    /**
+     * Increments/decrements the pending requests counters and fires the request
+     * if necessary (counter == 0). Used for coalescing requests across multiple
+     * TmfDataProvider's.
+     *
+     * @param isIncrement
+     *            Should we increment (true) or decrement (false) the pending
+     *            counter
+     */
+    public void notifyPendingRequest(boolean isIncrement);
+
+    /**
+     * Return the next event based on the context supplied. The context
+     * will be updated for the subsequent read.
+     *
+     * @param context the trace read context (updated)
+     * @return the event referred to by context
+     */
+    public ITmfEvent getNext(ITmfContext context);
+
+}
index 6d7ec2ba9caf12f8adfb4a10bea4a774d091039d..86cd58e54aa74bdc5d55ceb29ceb8ae9e7614755 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -8,7 +8,8 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Replace background requests by pre-emptable requests
+ *   Francois Chouinard - Replace background requests by pre-emptible requests
+ *   Francois Chouinard - Rebased on TmfCoalescedRequest:s
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.component;
@@ -21,19 +22,18 @@ import java.util.concurrent.SynchronousQueue;
 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfEventThread;
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest;
+import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedRequest;
 import org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfStartSynchSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 
 /**
- * An abstract base class that implements ITmfDataProvider.
+ * An abstract base class that implements ITmfEventProvider.
  * <p>
  * This abstract class implements the housekeeping methods to register/
  * de-register the event provider and to handle generically the event requests.
@@ -45,7 +45,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
  * @author Francois Chouinard
  * @version 1.1
  */
-public abstract class TmfDataProvider extends TmfComponent implements ITmfDataProvider {
+public abstract class TmfDataProvider extends TmfComponent implements ITmfEventProvider {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -83,6 +83,9 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
 
     private int fRequestPendingCounter = 0;
 
+    /** List of coalesced requests */
+    protected Vector<TmfCoalescedRequest> fPendingCoalescedRequests = new Vector<TmfCoalescedRequest>();
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -114,7 +117,6 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
         fSignalDepth = 0;
 
         fLogData = TmfCoreTracer.isEventTraced();
-//        fLogError = TmfCoreTracer.isErrorTraced();
 
         TmfProviderManager.register(fType, this);
     }
@@ -163,7 +165,6 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
         TmfProviderManager.deregister(fType, this);
         fExecutor.stop();
         super.dispose();
-        // if (Tracer.isComponentTraced()) Tracer.traceComponent(this, "stopped");
     }
 
     // ------------------------------------------------------------------------
@@ -192,8 +193,14 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
     // ITmfRequestHandler
     // ------------------------------------------------------------------------
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider#sendRequest(org.eclipse.linuxtools.tmf.core.request.ITmfRequest)
+     */
+    /**
+     * @since 2.0
+     */
     @Override
-    public void sendRequest(final ITmfDataRequest request) {
+    public void sendRequest(final ITmfRequest request) {
         synchronized (fLock) {
             if (fSignalDepth > 0) {
                 coalesceDataRequest(request);
@@ -203,6 +210,9 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider#fireRequest()
+     */
     @Override
     public void fireRequest() {
         synchronized (fLock) {
@@ -210,7 +220,7 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
                 return;
             }
             if (fPendingCoalescedRequests.size() > 0) {
-                for (TmfDataRequest request : fPendingCoalescedRequests) {
+                for (ITmfRequest request : fPendingCoalescedRequests) {
                     dispatchRequest(request);
                 }
                 fPendingCoalescedRequests.clear();
@@ -251,21 +261,16 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
     // Coalescing (primitive test...)
     // ------------------------------------------------------------------------
 
-    /** List of coalesced requests */
-    protected Vector<TmfCoalescedDataRequest> fPendingCoalescedRequests = new Vector<TmfCoalescedDataRequest>();
-
     /**
      * Create a new request from an existing one, and add it to the coalesced
      * requests
      *
-     * @param request
-     *            The request to copy
+     * @param request The request to copy
+     * @since 2.0
      */
-    protected void newCoalescedDataRequest(ITmfDataRequest request) {
+    protected void newCoalescedDataRequest(ITmfRequest request) {
         synchronized (fLock) {
-            TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(request.getDataType(), request.getIndex(),
-                    request.getNbRequested(), request.getBlockSize(), request.getExecType());
-            coalescedRequest.addRequest(request);
+            TmfCoalescedRequest coalescedRequest = new TmfCoalescedRequest(request);
             if (TmfCoreTracer.isRequestTraced()) {
                 TmfCoreTracer.traceRequest(request, "COALESCED with " + coalescedRequest.getRequestId()); //$NON-NLS-1$
                 TmfCoreTracer.traceRequest(coalescedRequest, "now contains " + coalescedRequest.getSubRequestIds()); //$NON-NLS-1$
@@ -277,12 +282,12 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
     /**
      * Add an existing requests to the list of coalesced ones
      *
-     * @param request
-     *            The request to add to the list
+     * @param request The request to add to the list
+     * @since 2.0
      */
-    protected void coalesceDataRequest(ITmfDataRequest request) {
+    protected void coalesceDataRequest(ITmfRequest request) {
         synchronized (fLock) {
-            for (TmfCoalescedDataRequest coalescedRequest : fPendingCoalescedRequests) {
+            for (TmfCoalescedRequest coalescedRequest : fPendingCoalescedRequests) {
                 if (coalescedRequest.isCompatible(request)) {
                     coalescedRequest.addRequest(request);
                     if (TmfCoreTracer.isRequestTraced()) {
@@ -300,21 +305,21 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
     // Request processing
     // ------------------------------------------------------------------------
 
-    private void dispatchRequest(final ITmfDataRequest request) {
-        if (request.getExecType() == ExecutionType.FOREGROUND) {
+    private void dispatchRequest(final ITmfRequest request) {
+        if (request.getRequestPriority() == TmfRequestPriority.HIGH) {
             queueRequest(request);
         } else {
-            queueBackgroundRequest(request, request.getBlockSize(), true);
+            queueBackgroundRequest(request, true);
         }
     }
 
     /**
      * Queue a request.
      *
-     * @param request
-     *            The data request
+     * @param request The data request
+     * @since 2.0
      */
-    protected void queueRequest(final ITmfDataRequest request) {
+    protected void queueRequest(final ITmfRequest request) {
 
         if (fExecutor.isShutdown()) {
             request.cancel();
@@ -333,14 +338,12 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
     /**
      * Queue a background request
      *
-     * @param request
-     *            The request
-     * @param blockSize
-     *            The request should be split in chunks of this size
-     * @param indexing
-     *            Should we index the chunks
+     * @param request The request
+     * @param indexing Should we index the chunks
+     *
+     * @since 2.0
      */
-    protected void queueBackgroundRequest(final ITmfDataRequest request, final int blockSize, final boolean indexing) {
+    protected void queueBackgroundRequest(final ITmfRequest request, final boolean indexing) {
         queueRequest(request);
     }
 
@@ -354,7 +357,7 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
      *         serviced
      * @since 2.0
      */
-    public abstract ITmfContext armRequest(ITmfDataRequest request);
+    public abstract ITmfContext armRequest(ITmfRequest request);
 
 //    /**
 //     * Return the next event based on the context supplied. The context
@@ -369,12 +372,16 @@ public abstract class TmfDataProvider extends TmfComponent implements ITmfDataPr
      * Checks if the data meets the request completion criteria.
      *
      * @param request the request
-     * @param data the data to verify
+     * @param event the event to check
      * @param nbRead the number of events read so far
      * @return true if completion criteria is met
+     *
+     * @since 2.0
      */
-    public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
-        return request.isCompleted() || nbRead >= request.getNbRequested();
+    public boolean isCompleted(ITmfRequest request, ITmfEvent event, int nbRead) {
+        return request.isCompleted() ||
+               nbRead >= request.getNbRequested() ||
+               request.getTimeRange().getEndTime().compareTo(event.getTimestamp()) < 0;
     }
 
     // ------------------------------------------------------------------------
index cb54d2e2f47c6cf229e009c3df6d1615b867a6f0..ad8d8227d0c6f521c836d6f2301f009ed62d49e3 100644 (file)
 
 package org.eclipse.linuxtools.tmf.core.component;
 
-import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedEventRequest;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 
 /**
  * An extension of TmfDataProvider timestamped events providers.
@@ -84,31 +79,31 @@ public abstract class TmfEventProvider extends TmfDataProvider {
     // TmfDataProvider
     // ------------------------------------------------------------------------
 
-    @Override
-    public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
-        boolean requestCompleted = super.isCompleted(request, data, nbRead);
-        if (!requestCompleted && request instanceof ITmfEventRequest) {
-            ITmfTimestamp endTime = ((ITmfEventRequest) request).getRange().getEndTime();
-            return data.getTimestamp().compareTo(endTime, false) > 0;
-        }
-        return requestCompleted;
-    }
-
-    @Override
-    protected synchronized void newCoalescedDataRequest(ITmfDataRequest request) {
-        if (request instanceof ITmfEventRequest) {
-            ITmfEventRequest eventRequest = (ITmfEventRequest) request;
-            TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(eventRequest.getDataType(), eventRequest.getRange(),
-                    eventRequest.getIndex(), eventRequest.getNbRequested(), eventRequest.getBlockSize(), eventRequest.getExecType());
-            coalescedRequest.addRequest(eventRequest);
-            if (TmfCoreTracer.isRequestTraced()) {
-                TmfCoreTracer.traceRequest(request, "COALESCED with " + coalescedRequest.getRequestId()); //$NON-NLS-1$
-                TmfCoreTracer.traceRequest(coalescedRequest, "now contains " + coalescedRequest.getSubRequestIds()); //$NON-NLS-1$
-            }
-            fPendingCoalescedRequests.add(coalescedRequest);
-        } else {
-            super.newCoalescedDataRequest(request);
-        }
-    }
+//    @Override
+//    public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) {
+//        boolean requestCompleted = super.isCompleted(request, data, nbRead);
+//        if (!requestCompleted && request instanceof ITmfEventRequest) {
+//            ITmfTimestamp endTime = ((ITmfEventRequest) request).getRange().getEndTime();
+//            return data.getTimestamp().compareTo(endTime, false) > 0;
+//        }
+//        return requestCompleted;
+//    }
+//
+//    @Override
+//    protected synchronized void newCoalescedDataRequest(ITmfDataRequest request) {
+//        if (request instanceof ITmfEventRequest) {
+//            ITmfEventRequest eventRequest = (ITmfEventRequest) request;
+//            TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(eventRequest.getDataType(), eventRequest.getRange(),
+//                    eventRequest.getIndex(), (int) eventRequest.getNbRequested(), eventRequest.getBlockSize(), eventRequest.getExecType());
+//            coalescedRequest.addRequest(eventRequest);
+//            if (TmfCoreTracer.isRequestTraced()) {
+//                TmfCoreTracer.traceRequest(request, "COALESCED with " + coalescedRequest.getRequestId()); //$NON-NLS-1$
+//                TmfCoreTracer.traceRequest(coalescedRequest, "now contains " + coalescedRequest.getSubRequestIds()); //$NON-NLS-1$
+//            }
+//            fPendingCoalescedRequests.add(coalescedRequest);
+//        } else {
+//            super.newCoalescedDataRequest(request);
+//        }
+//    }
 
 }
index 556122c48270f2f409ffbe29f9fbb902bef07e81..561f9c7386346e616409539cfc8a5c1e9a823eaa 100644 (file)
@@ -154,6 +154,20 @@ public final class TmfTimeRange {
                         : fEndTime);
     }
 
+    /**
+     * Get the union of two time ranges
+     *
+     * @param range the other time range
+     * @return the intersection time range, or null if no intersection exists
+     *
+     * @since 2.0
+     */
+    public TmfTimeRange getUnion(final TmfTimeRange range) {
+        ITmfTimestamp start = (fStartTime.compareTo(range.fStartTime, true) < 0) ? fStartTime : range.fStartTime;
+        ITmfTimestamp end   = (fEndTime.compareTo(range.fEndTime, true) < 0)     ? fEndTime   : range.fEndTime;
+        return new TmfTimeRange(start, end);
+    }
+
     // ------------------------------------------------------------------------
     // Object
     // ------------------------------------------------------------------------
index 299caa5f689e2d93ac00df37ea2b5d3942e33318..0c8dfdcca16978558721f3546e088604480185e3 100644 (file)
@@ -353,6 +353,14 @@ public class TmfTimestamp implements ITmfTimestamp {
      */
     @Override
     public String toString(final TmfTimestampFormat format) {
+        // Check the border cases
+        if (equals(BIG_BANG)) {
+            return "BIG_BANG"; //$NON-NLS-1$
+        }
+        if (equals(BIG_CRUNCH)) {
+            return "BIG_CRUNCH"; //$NON-NLS-1$
+        }
+        // Format the timestamp
         try {
             ITmfTimestamp ts = normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
             return format.format(ts.getValue());
index f22d0ea2fba41440b9e2a0b1aa67fd4ca92e234f..1f7e515d3fef2e8990304c32f3f4c9bb76c44398 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Rebased on ITmfRequest, removed duplicates, deprecated
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.request;
@@ -20,7 +21,8 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
  * @version 1.0
  * @author Francois Chouinard
  */
-public interface ITmfDataRequest {
+@Deprecated
+public interface ITmfDataRequest extends ITmfRequest {
 
        // ------------------------------------------------------------------------
        // Constants
@@ -49,11 +51,6 @@ public interface ITmfDataRequest {
      */
     public Class<? extends ITmfEvent> getDataType();
 
-    /**
-     * @return request ID
-     */
-    public int getRequestId();
-
     /**
      * @return request ID
      */
@@ -64,11 +61,6 @@ public interface ITmfDataRequest {
      */
     public long getIndex();
 
-    /**
-     * @return the number of requested events
-     */
-    public int getNbRequested();
-
     /**
      * @return the block size (for BG requests)
      */
@@ -79,30 +71,6 @@ public interface ITmfDataRequest {
      */
     public int getNbRead();
 
-       // ------------------------------------------------------------------------
-       // Request state predicates
-       // ------------------------------------------------------------------------
-
-    /**
-     * @return true if the request is still active
-     */
-    public boolean isRunning();
-
-    /**
-     * @return true if the request is completed
-     */
-    public boolean isCompleted();
-
-    /**
-     * @return true if the request has failed
-     */
-    public boolean isFailed();
-
-    /**
-     * @return true if the request was cancelled
-     */
-    public boolean isCancelled();
-
        // ------------------------------------------------------------------------
        // Data handling
        // ------------------------------------------------------------------------
@@ -114,64 +82,4 @@ public interface ITmfDataRequest {
      */
     public void handleData(ITmfEvent data);
 
-       // ------------------------------------------------------------------------
-       // Request notifications
-       // ------------------------------------------------------------------------
-
-    /**
-     * Request processing start notification
-     */
-    public void handleStarted();
-
-    /**
-     * Request processing completion notification
-     */
-    public void handleCompleted();
-
-    /**
-     * Request successful completion notification
-     */
-    public void handleSuccess();
-
-    /**
-     * Request failure notification
-     */
-    public void handleFailure();
-
-    /**
-     * Request cancellation notification
-     */
-    public void handleCancel();
-
-    /**
-     * To suspend the client thread until the request completes
-     * (or is canceled).
-     *
-     * @throws InterruptedException thrown if the request was cancelled
-     */
-    public void waitForCompletion() throws InterruptedException;
-
-       // ------------------------------------------------------------------------
-       // Request state modifiers
-       // ------------------------------------------------------------------------
-
-    /**
-     * Put the request in the running state
-     */
-    public void start();
-
-    /**
-     * Put the request in the completed state
-     */
-    public void done();
-
-    /**
-     * Put the request in the failed completed state
-     */
-    public void fail();
-
-    /**
-     * Put the request in the cancelled completed state
-     */
-    public void cancel();
 }
index 54c9819107cb4e9c629cf560b01f9d2a5dbba5d8..e835abd622f219416e641240fafb33150bd44996 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Deprecated the API
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.request;
@@ -20,6 +21,8 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
  * @version 1.0
  * @author Francois Chouinard
  */
+@Deprecated
+@SuppressWarnings("deprecation")
 public interface ITmfEventRequest extends ITmfDataRequest {
 
     /**
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/ITmfRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/ITmfRequest.java
new file mode 100644 (file)
index 0000000..b2cb455
--- /dev/null
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.request;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+/**
+ * The TMF request API.
+ * <p>
+ * ITmfRequest:s are used to obtain blocks of events from an event provider. Open
+ * ranges can be used, typically for continuous streaming.
+ * <p>
+ * The request is processed asynchronously by a TmfRequestHandler which invokes
+ * the request's handleEvent() synchronously for each event that matches the
+ * request filter(s).
+ * <p>
+ * The TmfProvider indicates that the request is completed by calling done().
+ * The request can be canceled at any time with cancel(). In case of unexpected
+ * exception or error, fail() will be called.
+ * <p>
+ * Typical usage:
+ * <pre>
+ * <code>
+ * ITmfRequest request = new TmfRequest(someParams) {
+ *     &#64;Override
+ *     public synchronized void handleEvent(ITmfEvent event) {
+ *          super.handleEvent(event);
+ *          // do something
+ *     }
+ *     &#64;Override
+ *     public void handleCompleted() {
+ *          // do something
+ *     }
+ *     &#64;Override
+ *     public void handleCancel() {
+ *          // do something
+ *     }
+ *     &#64;Override
+ *     public void handleFailure() {
+ *          // do something
+ *     }
+ * };
+ * request.addEventFilter(myFilter);
+ * fProcessor.process(request);
+ * </code>
+ * </pre>
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ */
+public interface ITmfRequest {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /** The request count for all the events */
+    public static final long ALL_EVENTS = Long.MAX_VALUE;
+
+    // ------------------------------------------------------------------------
+    // Enumerated Types
+    // ------------------------------------------------------------------------
+
+    /**
+     * The request execution type/priority
+     * @author francois
+     */
+    public enum TmfRequestPriority {
+        /**
+         * Normal priority request (preemptible)
+         */
+        NORMAL,
+        /**
+         * High priority request (non-preemptible)
+         */
+        HIGH
+    }
+
+    /**
+     * The request execution state
+     * @author francois
+     */
+    public enum TmfRequestState {
+        /**
+         * The request is created but has not started being processed yet
+         */
+        PENDING,
+        /**
+         * The request is being handled but has not completed yet
+         */
+        RUNNING,
+        /**
+         * The request has completed
+         */
+        COMPLETED
+    }
+
+       // ------------------------------------------------------------------------
+       // Getters
+       // ------------------------------------------------------------------------
+
+    /**
+     * @return the request ID
+     */
+    public int getRequestId();
+
+    /**
+     * @return the request type
+     */
+    public TmfRequestPriority getRequestPriority();
+
+    /**
+     * @return the time range of interest
+     */
+    public TmfTimeRange getTimeRange();
+
+    /**
+     * @return the number of events requested
+     */
+    public long getNbRequested();
+
+    /**
+     * @return the index of the first event requested
+     */
+    public long getStartIndex();
+
+    /**
+     * @return the number of events read so far
+     */
+    public long getNbEventsRead();
+
+    /**
+     * @param filterType the filter type to retrieve
+     *
+     * @return the corresponding filter (if any)
+     */
+    public ITmfFilter getEventFilter(Class<?> filterType);
+
+    /**
+     * Add/replace a filter
+     *
+     * @param filter the new filter
+     */
+    public void addEventFilter(ITmfFilter filter);
+
+    /**
+     * Check if the event matches the request
+     *
+     * @param event the event to test
+     *
+     * @return true if the event matches the request, false otherwise
+     */
+    public boolean matches(ITmfEvent event);
+
+    /**
+     * Sets the request's parent in the hierarchy
+     *
+     * @param parent the parent request
+     */
+    public void setParent(ITmfRequest parent);
+
+    /**
+     * Gets the request's parent in the hierarchy
+     *
+     * @return the parent request
+     */
+    public ITmfRequest getParent();
+
+    /**
+     * Completion notification for teh parent request
+     *
+     * @param child the child request
+     */
+    public void notifyParent(ITmfRequest child);
+
+       // ------------------------------------------------------------------------
+       // Request execution state
+       // ------------------------------------------------------------------------
+
+    /**
+     * @return the request execution state
+     */
+    public TmfRequestState getState();
+
+    /**
+     * @return true if the request is still active
+     */
+    public boolean isRunning();
+
+    /**
+     * @return true if the request is completed
+     */
+    public boolean isCompleted();
+
+    // ------------------------------------------------------------------------
+    // Request completion status
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the request completion status
+     */
+    public IStatus getStatus();
+
+    /**
+     * @return true if the request completed successfully
+     */
+    public boolean isOK();
+
+    /**
+
+     * @return true if the request has failed */
+    public boolean isFailed();
+
+    /**
+     * @return true if the request was cancelled
+     */
+    public boolean isCancelled();
+
+    // ------------------------------------------------------------------------
+    // Request operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Put the request in the running state
+     */
+    public void start();
+
+    /**
+     * Put the request in the terminated state
+     */
+    public void done();
+
+    /**
+     * Put the request in the failed state
+     */
+    public void fail();
+
+    /**
+     * Put the request in the cancelled state
+     */
+    public void cancel();
+
+    /**
+     * To suspend the client thread until the request starts
+     * (or is canceled).
+     *
+     * @throws InterruptedException thrown if the request was cancelled
+     */
+    public void waitForStart() throws InterruptedException;
+
+    /**
+     * To suspend the client thread until the request completes
+     * (or is canceled).
+     *
+     * @throws InterruptedException thrown if the request was cancelled
+     */
+    public void waitForCompletion() throws InterruptedException;
+
+       // ------------------------------------------------------------------------
+       // Request processing hooks
+       // ------------------------------------------------------------------------
+
+    /**
+     * Request processing start notification
+     */
+    public void handleStarted();
+
+    /**
+     * Process the piece of data
+     *
+     * @param event the data to process
+     */
+    public void handleEvent(ITmfEvent event);
+
+    /**
+     * Request processing completion notification
+     */
+    public void handleCompleted();
+
+    /**
+     * Request successful completion notification
+     */
+    public void handleSuccess();
+
+    /**
+     * Request failure notification
+     */
+    public void handleFailure();
+
+    /**
+     * Request cancellation notification
+     */
+    public void handleCancel();
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfBlockFilter.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfBlockFilter.java
new file mode 100644 (file)
index 0000000..09a9844
--- /dev/null
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.request;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+
+/**
+ * An event filter based on the requested event block (start event index +
+ * number of requested events).
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ */
+public final class TmfBlockFilter implements ITmfFilter {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * Filter for all events by index
+     */
+    public static final TmfBlockFilter ALL_EVENTS = new TmfBlockFilter(0, Long.MAX_VALUE);
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * Request start index
+     */
+    private final long fStartIndex;
+
+    /**
+     * Request end index (non-inclusive)
+     */
+    private final long fEndIndex;
+
+    /**
+     * Number of events requested
+     */
+    private final long fNbRequested;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Standard constructor
+     *
+     * @param startIndex start index
+     * @param nbRequested nb requested events
+     */
+    public TmfBlockFilter(long startIndex, long nbRequested) {
+        fStartIndex  = startIndex  >= 0 ? startIndex  : 0;
+        fNbRequested = nbRequested >= 0 ? nbRequested : Long.MAX_VALUE;
+        fEndIndex = (Long.MAX_VALUE - fNbRequested) > fStartIndex ? fStartIndex + nbRequested : Long.MAX_VALUE;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other filter
+     */
+    public TmfBlockFilter(TmfBlockFilter other) {
+        fStartIndex  = other.fStartIndex;
+        fEndIndex    = other.fEndIndex;
+        fNbRequested = other.fNbRequested;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the filter start index
+     */
+    public long getStartIndex() {
+        return fStartIndex;
+    }
+
+    /**
+     * @return the filter end index (non-inclusive)
+     */
+    public long getEndIndex() {
+        return fEndIndex;
+    }
+
+    /**
+     * @return the filter number of events requested
+     */
+    public long getNbRequested() {
+        return fNbRequested;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfFilter
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public boolean matches(ITmfEvent event) {
+        long rank = event.getRank();
+        return ((rank == ITmfContext.UNKNOWN_RANK) || (rank >= fStartIndex && rank < (fStartIndex + fNbRequested)));
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (int) (fEndIndex ^ (fEndIndex >>> 32));
+        result = prime * result + (int) (fNbRequested ^ (fNbRequested >>> 32));
+        result = prime * result + (int) (fStartIndex ^ (fStartIndex >>> 32));
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof TmfBlockFilter)) {
+            return false;
+        }
+        TmfBlockFilter other = (TmfBlockFilter) obj;
+        if (fEndIndex != other.fEndIndex) {
+            return false;
+        }
+        if (fNbRequested != other.fNbRequested) {
+            return false;
+        }
+        if (fStartIndex != other.fStartIndex) {
+            return false;
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfBlockFilter [fStartIndex=" + fStartIndex + ", fEndIndex=" + fEndIndex + ", fNbRequested=" + fNbRequested + "]";
+    }
+
+}
index 025657ab0d1d66d8bd55ddf282df10d893f976f8..7161871e229eb442008122880c493738affe83d8 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -8,29 +8,30 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Rebased on TmfRequest and deprecated
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.request;
 
-import java.util.concurrent.CountDownLatch;
-
 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 
 /**
- * TmfDataRequests are used to obtain blocks of contiguous data from a data provider. Open ranges can be used,
- * especially for continuous streaming.
+ * TmfDataRequests are used to obtain blocks of contiguous data from a data
+ * provider. Open ranges can be used, especially for continuous streaming.
  * <p>
- * The request is processed asynchronously by a TmfProvider and, as blocks of data become available, handleData() is
- * invoked synchronously for each block. Upon return, the data instances go out of scope and become eligible for gc. It
- * is is thus the responsibility of the requester to either clone or keep a reference to the data it wishes to track
- * specifically.
+ * The request is processed asynchronously by a TmfProvider and, as blocks of
+ * data become available, handleData() is invoked synchronously for each block.
+ * Upon return, the data instances go out of scope and become eligible for gc.
+ * It is is thus the responsibility of the requester to either clone or keep a
+ * reference to the data it wishes to track specifically.
  * <p>
- * This data block approach is used to avoid busting the heap for very large trace files. The block size is
- * configurable.
+ * This data block approach is used to avoid busting the heap for very large
+ * trace files. The block size is configurable.
  * <p>
- * The TmfProvider indicates that the request is completed by calling done(). The request can be canceled at any time
- * with cancel().
+ * The TmfProvider indicates that the request is completed by calling done().
+ * The request can be canceled at any time with cancel().
  * <p>
  * Typical usage:
  *
@@ -60,17 +61,21 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
  * </i></code>
  * </pre>
  *
- * TODO: Consider decoupling from "time range", "rank", etc and for the more generic notion of "criteria". This would
- * allow to extend for "time range", etc instead of providing specialized constructors. This also means removing the
- * criteria info from the data structure (with the possible exception of fNbRequested). The nice thing about it is that
- * it would prepare us well for the coming generation of analysis tools.
+ * TODO: Consider decoupling from "time range", "rank", etc and for the more
+ * generic notion of "criteria". This would allow to extend for "time range",
+ * etc instead of providing specialized constructors. This also means removing
+ * the criteria info from the data structure (with the possible exception of
+ * fNbRequested). The nice thing about it is that it would prepare us well for
+ * the coming generation of analysis tools.
  *
  * TODO: Implement request failures (codes, etc...)
  *
- * @version 1.0
  * @author Francois Chouinard
+ * @version 1.1
  */
-public abstract class TmfDataRequest implements ITmfDataRequest {
+@Deprecated
+@SuppressWarnings("deprecation")
+public abstract class TmfDataRequest extends TmfRequest implements ITmfDataRequest {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -82,48 +87,19 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
     /** The request count for all the events */
     public static final int ALL_DATA = Integer.MAX_VALUE;
 
-    private static int fRequestNumber = 0;
-
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
 
-    private final Class<? extends ITmfEvent> fDataType;
-    private final ExecutionType fExecType;
-
-    /** A unique request ID */
-    private final int fRequestId;
-
-    /** The index (rank) of the requested event */
-    protected long fIndex;
-
-    /** The number of requested events (ALL_DATA for all) */
-    protected int fNbRequested;
+    private final TmfEventTypeFilter fEventTypeFilter;
 
     /** The block size (for BG requests) */
     private final int fBlockSize;
 
-    /** The number of reads so far */
-    private int fNbRead;
-
-    private final CountDownLatch startedLatch = new CountDownLatch(1);
-    private final CountDownLatch completedLatch = new CountDownLatch(1);
-    private boolean fRequestRunning;
-    private boolean fRequestCompleted;
-    private boolean fRequestFailed;
-    private boolean fRequestCanceled;
-
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
-    /**
-     * Resets the request counter (used for testing)
-     */
-    public static void reset() {
-        fRequestNumber = 0;
-    }
-
     /**
      * Request all the events of a given type (high priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
@@ -217,18 +193,12 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      * @param priority the requested execution priority
      */
     public TmfDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, int blockSize, ExecutionType priority) {
-        fRequestId = fRequestNumber++;
-        fDataType = dataType;
-        fIndex = index;
-        fNbRequested = nbRequested;
-        fBlockSize = blockSize;
-        fExecType = priority;
-        fNbRead = 0;
+        super(TmfTimeRange.ETERNITY, index, nbRequested,
+              priority == ITmfDataRequest.ExecutionType.FOREGROUND ? ITmfRequest.TmfRequestPriority.HIGH : ITmfRequest.TmfRequestPriority.NORMAL);
+        fEventTypeFilter = new TmfEventTypeFilter(dataType);
+        addEventFilter(fEventTypeFilter);
 
-        fRequestRunning = false;
-        fRequestCompleted = false;
-        fRequestFailed = false;
-        fRequestCanceled = false;
+        fBlockSize = blockSize;
 
         if (!(this instanceof ITmfEventRequest) && TmfCoreTracer.isRequestTraced()) {
             String type = getClass().getName();
@@ -254,20 +224,12 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
     // Accessors
     // ------------------------------------------------------------------------
 
-    /**
-     * @return the request ID
-     */
-    @Override
-    public int getRequestId() {
-        return fRequestId;
-    }
-
     /**
      * @return the index of the first event requested
      */
     @Override
     public long getIndex() {
-        return fIndex;
+        return getStartIndex();
     }
 
     /**
@@ -275,15 +237,17 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      */
     @Override
     public ExecutionType getExecType() {
-        return fExecType;
+        return getRequestPriority() == ITmfRequest.TmfRequestPriority.HIGH ?
+                ITmfDataRequest.ExecutionType.FOREGROUND : ITmfDataRequest.ExecutionType.BACKGROUND;
     }
 
-    /**
-     * @return the number of requested events (ALL_DATA = all)
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getNbRequested()
      */
     @Override
-    public int getNbRequested() {
-        return fNbRequested;
+    public synchronized long getNbRequested() {
+        long nbRequested = super.getNbRequested();
+        return (nbRequested > 0 && nbRequested < Integer.MAX_VALUE) ? nbRequested : Integer.MAX_VALUE;
     }
 
     /**
@@ -299,39 +263,7 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      */
     @Override
     public synchronized int getNbRead() {
-        return fNbRead;
-    }
-
-    /**
-     * @return indicates if the request is currently running
-     */
-    @Override
-    public synchronized boolean isRunning() {
-        return fRequestRunning;
-    }
-
-    /**
-     * @return indicates if the request is completed
-     */
-    @Override
-    public synchronized boolean isCompleted() {
-        return fRequestCompleted;
-    }
-
-    /**
-     * @return indicates if the request has failed
-     */
-    @Override
-    public synchronized boolean isFailed() {
-        return fRequestFailed;
-    }
-
-    /**
-     * @return indicates if the request is canceled
-     */
-    @Override
-    public synchronized boolean isCancelled() {
-        return fRequestCanceled;
+        return (int) getNbEventsRead();
     }
 
     /**
@@ -339,7 +271,7 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      */
     @Override
     public Class<? extends ITmfEvent> getDataType() {
-        return fDataType;
+        return fEventTypeFilter.getEventType();
     }
 
     // ------------------------------------------------------------------------
@@ -353,11 +285,11 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      *            the start time index
      */
     protected void setIndex(int index) {
-        fIndex = index;
+        setStartIndex(index);
     }
 
     // ------------------------------------------------------------------------
-    // Operators
+    // Operations
     // ------------------------------------------------------------------------
 
     /**
@@ -377,148 +309,18 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
      */
     @Override
     public void handleData(ITmfEvent data) {
-        if (data != null) {
-            fNbRead++;
-        }
-    }
-
-    @Override
-    public void handleStarted() {
-        if (TmfCoreTracer.isRequestTraced()) {
-            TmfCoreTracer.traceRequest(this, "STARTED"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * 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.
-     */
-    @Override
-    public void handleCompleted() {
-        boolean requestFailed = false;
-        boolean requestCanceled = false;
-        synchronized (this) {
-            requestFailed = fRequestFailed;
-            requestCanceled = fRequestCanceled;
-        }
-
-        if (requestFailed) {
-            handleFailure();
-        } else if (requestCanceled) {
-            handleCancel();
-        } else {
-            handleSuccess();
-        }
-        if (TmfCoreTracer.isRequestTraced()) {
-            TmfCoreTracer.traceRequest(this, "COMPLETED (" + fNbRead + " events read)"); //$NON-NLS-1$ //$NON-NLS-2$
-        }
+        super.handleEvent(data);
     }
 
-    @Override
-    public void handleSuccess() {
-        if (TmfCoreTracer.isRequestTraced()) {
-            TmfCoreTracer.traceRequest(this, "SUCCEEDED"); //$NON-NLS-1$
-        }
-    }
-
-    @Override
-    public void handleFailure() {
-        if (TmfCoreTracer.isRequestTraced()) {
-            TmfCoreTracer.traceRequest(this, "FAILED"); //$NON-NLS-1$
-        }
-    }
-
-    @Override
-    public void handleCancel() {
-        if (TmfCoreTracer.isRequestTraced()) {
-            TmfCoreTracer.traceRequest(this, "CANCELLED"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * To suspend the client thread until the request starts (or is canceled).
-     *
-     * @throws InterruptedException
-     *             If the thread was interrupted while waiting
-     */
-    public void waitForStart() throws InterruptedException {
-        while (!fRequestRunning) {
-            startedLatch.await();
-        }
-    }
-
-    /**
-     * To suspend the client thread until the request completes (or is
-     * canceled).
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.TmfRequest#handleEvent(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
      *
-     * @throws InterruptedException
-     *             If the thread was interrupted while waiting
-     */
-    @Override
-    public void waitForCompletion() throws InterruptedException {
-        while (!fRequestCompleted) {
-            completedLatch.await();
-        }
-    }
-
-    /**
-     * Called by the request processor upon starting to service the request.
+     * The TmfEventThread now calls handleEvent(). To ensure that handleData()
+     * overrides are correctly handled, the method is overridden here.
      */
     @Override
-    public void start() {
-        synchronized (this) {
-            fRequestRunning = true;
-        }
-        handleStarted();
-        startedLatch.countDown();
-    }
-
-    /**
-     * Called by the request processor upon completion.
-     */
-    @Override
-    public void done() {
-        synchronized (this) {
-            if (!fRequestCompleted) {
-                fRequestRunning = false;
-                fRequestCompleted = true;
-            } else {
-                return;
-            }
-        }
-        try {
-            handleCompleted();
-        } finally {
-            completedLatch.countDown();
-        }
-    }
-
-    /**
-     * Called by the request processor upon failure.
-     */
-    @Override
-    public void fail() {
-        synchronized (this) {
-            fRequestFailed = true;
-        }
-        done();
-    }
-
-    /**
-     * Called by the request processor upon cancellation.
-     */
-    @Override
-    public void cancel() {
-        synchronized (this) {
-            fRequestCanceled = true;
-        }
-        done();
+    public synchronized void handleEvent(ITmfEvent data) {
+        handleData(data);
     }
 
     // ------------------------------------------------------------------------
@@ -533,10 +335,13 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
 
     @Override
     public boolean equals(Object other) {
+        if (other == this) {
+            return true;
+        }
         if (other instanceof TmfDataRequest) {
             TmfDataRequest request = (TmfDataRequest) other;
-            return (request.fDataType == fDataType) && (request.fIndex == fIndex)
-                    && (request.fNbRequested == fNbRequested);
+            return (request.fEventTypeFilter.getEventType() == fEventTypeFilter.getEventType()) && (request.getStartIndex() == getStartIndex())
+                    && (request.getNbRequested() == getNbRequested());
         }
         return false;
     }
@@ -544,7 +349,7 @@ public abstract class TmfDataRequest implements ITmfDataRequest {
     @Override
     @SuppressWarnings("nls")
     public String toString() {
-        return "[TmfDataRequest(" + fRequestId + "," + fDataType.getSimpleName() + "," + fIndex + "," + fNbRequested
+        return "[TmfDataRequest(" + getRequestId() + "," + fEventTypeFilter.getEventType().getSimpleName() + "," + getStartIndex() + "," + getNbRequested()
                 + "," + getBlockSize() + ")]";
     }
 }
index 653eaf6a7920402e798caccc6dc4672250bd3efe..ba79e3bcf40c2b6e642abb11944b56f60d85c9ec 100644 (file)
@@ -22,13 +22,14 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
  * @version 1.0
  * @author Francois Chouinard
  */
+@SuppressWarnings("deprecation")
 public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEventRequest {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
 
-    private final TmfTimeRange fRange; // The requested events time range
+    private final TmfRangeFilter fRangeFilter;  // The requested events time range
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -157,7 +158,8 @@ public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEven
      */
     public TmfEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
        super(dataType, index, nbRequested, blockSize, priority);
-       fRange = range;
+       fRangeFilter = new TmfRangeFilter(range);
+       addEventFilter(fRangeFilter);
 
         if (TmfCoreTracer.isRequestTraced()) {
             String type = getClass().getName();
@@ -181,7 +183,7 @@ public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEven
      */
     @Override
        public TmfTimeRange getRange() {
-        return fRange;
+        return fRangeFilter.getTimeRange();
     }
 
     // ------------------------------------------------------------------------
@@ -213,7 +215,7 @@ public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEven
     public boolean equals(Object other) {
        if (other instanceof TmfEventRequest) {
                TmfEventRequest request = (TmfEventRequest) other;
-               return super.equals(other) && request.fRange.equals(fRange);
+               return super.equals(other) && request.fRangeFilter.getTimeRange().equals(fRangeFilter.getTimeRange());
        }
        return false;
     }
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfEventTypeFilter.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfEventTypeFilter.java
new file mode 100644 (file)
index 0000000..8bb67e8
--- /dev/null
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.request;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+/**
+ * An event filter base on the requested data type.
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ */
+public final class TmfEventTypeFilter implements ITmfFilter {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * Filter for all types of events
+     */
+    public static final TmfEventTypeFilter ALL_EVENTS = new TmfEventTypeFilter(ITmfEvent.class);
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * Event type
+     */
+    private final Class<? extends ITmfEvent> fEventType;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Standard constructor
+     *
+     * @param eventType the event type
+     */
+    public TmfEventTypeFilter(Class<? extends ITmfEvent> eventType) {
+        fEventType = eventType != null ? eventType : ITmfEvent.class;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other filter
+     */
+    public TmfEventTypeFilter(TmfEventTypeFilter other) {
+        fEventType = other.fEventType;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the event type
+     */
+    public Class<? extends ITmfEvent> getEventType() {
+        return fEventType;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfFilter
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public boolean matches(ITmfEvent event) {
+        return fEventType.isInstance(event);
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fEventType == null) ? 0 : fEventType.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof TmfEventTypeFilter)) {
+            return false;
+        }
+        TmfEventTypeFilter other = (TmfEventTypeFilter) obj;
+        if (fEventType == null) {
+            if (other.fEventType != null) {
+                return false;
+            }
+        } else if (!fEventType.equals(other.fEventType)) {
+            return false;
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfEventTypeFilter [fEventType=" + fEventType.getSimpleName() + "]";
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRangeFilter.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRangeFilter.java
new file mode 100644 (file)
index 0000000..b76414c
--- /dev/null
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.request;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+/**
+ * An event filter based on the requested time range.
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ */
+public final class TmfRangeFilter implements ITmfFilter {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * Filter for all events by time range
+     */
+    public static final TmfRangeFilter ALL_EVENTS = new TmfRangeFilter(TmfTimeRange.ETERNITY);
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /** The time range requested */
+    private final TmfTimeRange fTimeRange;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Standard constructor
+     *
+     * @param timeRange the time range of interest
+     */
+    public TmfRangeFilter(TmfTimeRange timeRange) {
+        fTimeRange = timeRange != null ? timeRange : TmfTimeRange.ETERNITY;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other filter
+     */
+    public TmfRangeFilter(TmfRangeFilter other) {
+        fTimeRange = other.fTimeRange;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the filter time range
+     */
+    public TmfTimeRange getTimeRange() {
+        return fTimeRange;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfFilter
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public boolean matches(ITmfEvent event) {
+        return fTimeRange.contains(event.getTimestamp());
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof TmfRangeFilter)) {
+            return false;
+        }
+        TmfRangeFilter other = (TmfRangeFilter) obj;
+        if (fTimeRange == null) {
+            if (other.fTimeRange != null) {
+                return false;
+            }
+        } else if (!fTimeRange.equals(other.fTimeRange)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfRangeFilter [fTimeRange=" + fTimeRange + "]";
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/request/TmfRequest.java
new file mode 100644 (file)
index 0000000..0592089
--- /dev/null
@@ -0,0 +1,630 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.request;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
+import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
+
+/**
+ * A generic request implementation.
+ *
+ * @author Francois Chouinard
+ * @version 1.0
+ * @since 2.0
+ */
+public abstract class TmfRequest implements ITmfRequest, ITmfFilter {
+
+    // ------------------------------------------------------------------------
+    // Static attributes
+    // ------------------------------------------------------------------------
+
+    /** The plug-in ID */
+    private static final String PLUGIN_ID = Activator.PLUGIN_ID;
+
+    /** The unique request number */
+    private static int fRequestCounter = 0;
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /** The request unique ID */
+    private final int fRequestId;
+
+    /** The request type */
+    private final TmfRequestPriority fRequestPriority;
+
+    /** The event filters */
+    private Map<Class<? extends ITmfFilter>, ITmfFilter> fEventFilters = new HashMap<Class<? extends ITmfFilter>, ITmfFilter>();
+
+    /** The event block filter - an optimization */
+    private TmfBlockFilter fBlockFilter;
+
+    /** The event range filter - an optimization */
+    private TmfRangeFilter fRangeFilter;
+
+    /** The number of events reads so far */
+    private long fNbEventsRead;
+
+    /** The request execution state */
+    private TmfRequestState fRequestState;
+
+    /** The request completion status */
+    protected IStatus fRequestStatus;
+
+    /** The parent request */
+    private ITmfRequest fParentRequest;
+
+    /** Latch used for request processing start */
+    private final CountDownLatch startedLatch = new CountDownLatch(1);
+
+    /** Latch used for request completion */
+    private final CountDownLatch completedLatch = new CountDownLatch(1);
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor for all the events at normal priority
+     */
+    public TmfRequest() {
+        this(TmfRequestPriority.NORMAL);
+    }
+
+    /**
+     * Constructor for all the events at the specified  priority
+     *
+     * @param priority the request priority
+     */
+    public TmfRequest(TmfRequestPriority priority) {
+        this(TmfTimeRange.ETERNITY, 0, ALL_EVENTS, priority);
+    }
+
+    /**
+     * Constructor for all the events in a time range
+     *
+     * @param timeRange The time range
+     */
+    public TmfRequest(TmfTimeRange timeRange) {
+        this(timeRange, 0, ALL_EVENTS, TmfRequestPriority.NORMAL);
+    }
+
+    /**
+     * Constructor for all the events in a block
+     *
+     * @param startIndex  The start index
+     * @param nbRequested The number of events requested
+     */
+    public TmfRequest(long startIndex, long nbRequested) {
+        this(TmfTimeRange.ETERNITY, startIndex, nbRequested, TmfRequestPriority.NORMAL);
+    }
+
+    /**
+     * Standard constructor
+     *
+     * @param timeRange   The time range
+     * @param startIndex  The start index
+     * @param nbRequested The number of events requested
+     */
+    public TmfRequest(TmfTimeRange timeRange, long startIndex, long nbRequested) {
+        this(timeRange, startIndex, nbRequested, TmfRequestPriority.NORMAL);
+    }
+
+    /**
+     * Full constructor
+     *
+     * @param timeRange   Time range of interest
+     * @param nbRequested Number of events requested
+     * @param startIndex  Index of the first event requested
+     * @param priority    Request priority
+     */
+    public TmfRequest(TmfTimeRange timeRange, long startIndex, long nbRequested, TmfRequestPriority priority) {
+        fRequestId = fRequestCounter++;
+        fRequestPriority = priority;
+        fBlockFilter = new TmfBlockFilter(startIndex, nbRequested);
+        fRangeFilter = new TmfRangeFilter(timeRange);
+        fEventFilters.put(TmfBlockFilter.class, fBlockFilter);
+        fEventFilters.put(TmfRangeFilter.class, fRangeFilter);
+
+        fRequestState = TmfRequestState.PENDING;
+        fRequestStatus = null;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other request
+     */
+    public TmfRequest(TmfRequest other) {
+        this(null, 0, 0, other.fRequestPriority);
+        setEventFilters(other.getEventFilters());
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters and Setters
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getRequestId()
+     */
+    @Override
+    public int getRequestId() {
+        return fRequestId;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getRequestPriority()
+     */
+    @Override
+    public TmfRequestPriority getRequestPriority() {
+        return fRequestPriority;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getTimeRange()
+     */
+    @Override
+    public TmfTimeRange getTimeRange() {
+        return fRangeFilter.getTimeRange();
+    }
+
+    /**
+     * @param timeRange the new time range
+     */
+    protected void setTimeRange(final TmfTimeRange timeRange) {
+        fRangeFilter = new TmfRangeFilter(timeRange);
+        addEventFilter(fRangeFilter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getNbRequested()
+     */
+    @Override
+    public long getNbRequested() {
+        return fBlockFilter.getNbRequested();
+    }
+
+    /**
+     * @param nbRequested the number of events requested
+     */
+    protected void setNbRequested(long nbRequested) {
+        fBlockFilter = new TmfBlockFilter(fBlockFilter.getStartIndex(), nbRequested);
+        fRangeFilter = new TmfRangeFilter(fRangeFilter.getTimeRange());
+        addEventFilter(fBlockFilter);
+        addEventFilter(fRangeFilter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getStartIndex()
+     */
+    @Override
+    public long getStartIndex() {
+        return fBlockFilter.getStartIndex();
+    }
+
+    /**
+     * @param index the new start index
+     */
+    protected void setStartIndex(long index) {
+        fBlockFilter = new TmfBlockFilter(index, fBlockFilter.getNbRequested());
+        addEventFilter(fBlockFilter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getEventFilter(java.lang.Class)
+     */
+    @Override
+    public ITmfFilter getEventFilter(Class<?> filterType) {
+        return fEventFilters.get(filterType);
+    }
+
+    /**
+     * @return the list of event filters
+     */
+    protected Collection<ITmfFilter> getEventFilters() {
+        return fEventFilters.values();
+    }
+
+    /**
+     * @param filters the new list of event filters
+     */
+    public void setEventFilters(Collection<ITmfFilter> filters) {
+        clearFilters();
+        for (ITmfFilter filter : filters) {
+            addEventFilter(filter);
+        }
+    }
+
+    private void clearFilters() {
+        fEventFilters.clear();
+        fBlockFilter = TmfBlockFilter.ALL_EVENTS;
+        fRangeFilter = TmfRangeFilter.ALL_EVENTS;
+        fEventFilters.put(TmfBlockFilter.class, fBlockFilter);
+        fEventFilters.put(TmfRangeFilter.class, fRangeFilter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#addEventFilter(org.eclipse.linuxtools.tmf.core.filter.ITmfFilter)
+     */
+    @Override
+    public void addEventFilter(ITmfFilter filter) {
+        if (filter instanceof TmfBlockFilter) {
+            fBlockFilter = (TmfBlockFilter) filter;
+        } else if (filter instanceof TmfRangeFilter) {
+            fRangeFilter = (TmfRangeFilter) filter;
+        }
+        fEventFilters.put(filter.getClass(), filter);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getNbEventRead()
+     */
+    @Override
+    public long getNbEventsRead() {
+        return fNbEventsRead;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#setParent(org.eclipse.linuxtools.tmf.core.request.ITmfRequest)
+     */
+    @Override
+    public void setParent(ITmfRequest parent) {
+        fParentRequest = parent;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getParent()
+     */
+    @Override
+    public ITmfRequest getParent() {
+        return fParentRequest;
+    }
+
+    // ------------------------------------------------------------------------
+    // Request execution state
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getState()
+     */
+    @Override
+    public TmfRequestState getState() {
+        return fRequestState;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#isRunning()
+     */
+    @Override
+    public boolean isRunning() {
+        return fRequestState == TmfRequestState.RUNNING;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#isCompleted()
+     */
+    @Override
+    public boolean isCompleted() {
+        return fRequestState == TmfRequestState.COMPLETED;
+    }
+
+    // ------------------------------------------------------------------------
+    // Request completion status
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#getStatus()
+     */
+    @Override
+    public IStatus getStatus() {
+        return fRequestStatus;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#isOK()
+     */
+    @Override
+    public boolean isOK() {
+        return fRequestStatus != null && fRequestStatus.getSeverity() == IStatus.OK;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#isFailed()
+     */
+    @Override
+    public boolean isFailed() {
+        return fRequestStatus != null && fRequestStatus.getSeverity() == IStatus.ERROR;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#isCancelled()
+     */
+    @Override
+    public boolean isCancelled() {
+        return fRequestStatus != null && fRequestStatus.getSeverity() == IStatus.CANCEL;
+    }
+
+    // ------------------------------------------------------------------------
+    // Request operations
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#start()
+     */
+    @Override
+    public void start() {
+        synchronized (this) {
+            fRequestState  = TmfRequestState.RUNNING;
+        }
+        handleStarted();
+        startedLatch.countDown();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#done()
+     */
+    @Override
+    public void done() {
+        synchronized (this) {
+            if (fRequestState != TmfRequestState.COMPLETED) {
+                fRequestState = TmfRequestState.COMPLETED;
+                if (fRequestStatus == null) {
+                    fRequestStatus = new Status(IStatus.OK, PLUGIN_ID, "OK"); //$NON-NLS-1$
+                }
+            } else {
+                return;
+            }
+        }
+        try {
+            handleCompleted();
+        } finally {
+            completedLatch.countDown();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#fail()
+     */
+    @Override
+    public void fail() {
+        synchronized (this) {
+            if (fRequestStatus == null) {
+                fRequestStatus = new Status(IStatus.ERROR, PLUGIN_ID, "FAILED"); //$NON-NLS-1$
+            }
+        }
+        done();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#cancel()
+     */
+    @Override
+    public void cancel() {
+        synchronized (this) {
+            if (fRequestStatus == null) {
+                fRequestStatus = new Status(IStatus.CANCEL, PLUGIN_ID, "CANCEL"); //$NON-NLS-1$
+            }
+        }
+        done();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#waitForStart()
+     */
+    @Override
+    public void waitForStart() throws InterruptedException {
+        while (!isRunning() && !isCompleted()) {
+            startedLatch.await();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#waitForCompletion()
+     */
+    @Override
+    public void waitForCompletion() throws InterruptedException {
+        while (!isCompleted()) {
+            completedLatch.await();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Request processing hooks
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#handleStarted()
+     */
+    @Override
+    public void handleStarted() {
+        if (TmfCoreTracer.isRequestTraced()) {
+            TmfCoreTracer.traceRequest(this, "STARTED"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Handle incoming event one at a time i.e. this method is invoked
+     * for every data item obtained by the request.
+     *
+     * @param event a piece of data
+     */
+    @Override
+    public synchronized void handleEvent(ITmfEvent event) {
+        if (event != null) {
+            fNbEventsRead++;
+        }
+    }
+
+    /**
+     * 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.
+     */
+    @Override
+    public synchronized void handleCompleted() {
+        if (isFailed()) {
+            handleFailure();
+        } else if (isCancelled()) {
+            handleCancel();
+        } else {
+            handleSuccess();
+        }
+        notifyParent(this);
+        if (TmfCoreTracer.isRequestTraced()) {
+            TmfCoreTracer.traceRequest(this, "COMPLETED (" + fNbEventsRead + " events read)"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#notifyParent(org.eclipse.linuxtools.tmf.core.request.ITmfRequest)
+     */
+    @Override
+    public void notifyParent(ITmfRequest child) {
+        if (fParentRequest != null) {
+            fParentRequest.notifyParent(this);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#handleSuccess()
+     */
+    @Override
+    public void handleSuccess() {
+        if (TmfCoreTracer.isRequestTraced()) {
+            TmfCoreTracer.traceRequest(this, "SUCCEEDED"); //$NON-NLS-1$
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#handleFailure()
+     */
+    @Override
+    public void handleFailure() {
+        if (TmfCoreTracer.isRequestTraced()) {
+            TmfCoreTracer.traceRequest(this, "FAILED"); //$NON-NLS-1$
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.request.ITmfRequest#handleCancel()
+     */
+    @Override
+    public void handleCancel() {
+        if (TmfCoreTracer.isRequestTraced()) {
+            TmfCoreTracer.traceRequest(this, "CANCELLED"); //$NON-NLS-1$
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfFilter
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
+     */
+    @Override
+    public boolean matches(ITmfEvent event) {
+        for (ITmfFilter filter : fEventFilters.values()) {
+            if (!filter.matches(event)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + fRequestId;
+        result = prime * result + ((fRequestPriority == null) ? 0 : fRequestPriority.hashCode());
+        result = prime * result + ((fEventFilters == null) ? 0 : fEventFilters.hashCode());
+        result = prime * result + ((fBlockFilter == null) ? 0 : fBlockFilter.hashCode());
+        result = prime * result + ((fRangeFilter == null) ? 0 : fRangeFilter.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof TmfRequest)) {
+            return false;
+        }
+        TmfRequest other = (TmfRequest) obj;
+        if (fRequestPriority != other.fRequestPriority) {
+            return false;
+        }
+        // Check that our filters match other's
+        for (ITmfFilter filter : fEventFilters.values()) {
+            ITmfFilter filter2 = other.getEventFilter(filter.getClass());
+            if (filter2 == null) {
+                return false;
+            }
+            if (!filter.equals(filter2)) {
+                return false;
+            }
+        }
+        // Check that others' filters match ours
+        for (ITmfFilter filter : other.fEventFilters.values()) {
+            ITmfFilter filter2 = getEventFilter(filter.getClass());
+            if (filter2 == null) {
+                return false;
+            }
+            if (!filter.equals(filter2)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return "TmfRequest [fRequestId=" + fRequestId + "]";
+    }
+
+}
index 4bd9e4dc3d81a6f1c2f1bd4b2263549e12f87592..683f1788154c198e86c761815b7cc42b0b57ddcf 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
  * @author Alexandre Montplaisir
  * @since 2.0
  */
+@SuppressWarnings("deprecation")
 public class TmfEventsStatistics implements ITmfStatistics {
 
     /* All timestamps should be stored in nanoseconds in the statistics backend */
@@ -263,8 +264,8 @@ public class TmfEventsStatistics implements ITmfStatistics {
         }
 
         @Override
-        public void handleData(final ITmfEvent event) {
-            super.handleData(event);
+        public synchronized void handleEvent(final ITmfEvent event) {
+            super.handleEvent(event);
             if (event != null) {
                 if (event.getTrace() == trace) {
                     processEvent(event);
@@ -324,8 +325,8 @@ public class TmfEventsStatistics implements ITmfStatistics {
         }
 
         @Override
-        public void handleData(ITmfEvent event) {
-            super.handleData(event);
+        public synchronized void handleEvent(ITmfEvent event) {
+            super.handleEvent(event);
             if ((event != null)  && (event.getTrace() == trace)) {
                 long ts = event.getTimestamp().normalize(0, SCALE).getValue();
                 Long key = results.floorKey(ts);
index 7acd78af1770ec140fe496f8a14f512e3efcce52..5f3f44b8ecd23da5dc9aff915f68a90893445b6d 100644 (file)
@@ -25,10 +25,9 @@ import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfRequest.TmfRequestPriority;
+import org.eclipse.linuxtools.tmf.core.request.TmfRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 
 /**
@@ -74,7 +73,7 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer {
     /**
      * The indexing request
      */
-    private ITmfEventRequest fIndexingRequest = null;
+    private ITmfRequest fIndexingRequest = null;
 
     // ------------------------------------------------------------------------
     // Construction
@@ -170,15 +169,14 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer {
 
         // Build a background request for all the trace data. The index is
         // updated as we go by readNextEvent().
-        fIndexingRequest = new TmfEventRequest(ITmfEvent.class,
-                range, offset, TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
+        fIndexingRequest = new TmfRequest(range, offset, ITmfRequest.ALL_EVENTS, TmfRequestPriority.NORMAL)
         {
             @Override
-            public void handleData(final ITmfEvent event) {
-                super.handleData(event);
+            public synchronized void handleEvent(final ITmfEvent event) {
+                super.handleEvent(event);
                 if (event != null) {
                     // Update the trace status at regular intervals
-                    if ((getNbRead() % fCheckpointInterval) == 0) {
+                    if ((getNbEventsRead() % fCheckpointInterval) == 0) {
                         updateTraceStatus();
                     }
                 }
@@ -190,7 +188,7 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer {
             }
 
             @Override
-            public void handleCompleted() {
+            public synchronized void handleCompleted() {
                 job.cancel();
                 super.handleCompleted();
                 fIsIndexing = false;
index b6caaa80d17e3cffb714e23b6765db291863fde8..534a51e1c1f4b86b4dfd31cbafdb154700a42781 100644 (file)
@@ -24,8 +24,8 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 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.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfBlockFilter;
 import org.eclipse.linuxtools.tmf.core.signal.TmfClearExperimentSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
@@ -202,24 +202,22 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser {
      * @since 2.0
      */
     @Override
-    public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
+    public synchronized ITmfContext armRequest(final ITmfRequest request) {
 
         // Make sure we have something to read from
         if (fTraces == null) {
             return null;
         }
 
-        if (request instanceof ITmfEventRequest
-            && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
-            && request.getIndex() == 0)
-        {
-            final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
-            ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
+        ITmfTimestamp startTime = request.getTimeRange().getStartTime();
+        long startindex = request.getStartIndex();
+        if (!TmfTimestamp.BIG_BANG.equals(startTime) && startindex == 0) {
+            final ITmfContext context = seekEvent(request.getTimeRange().getStartTime());
+            request.addEventFilter(new TmfBlockFilter(context.getRank(), request.getNbRequested()));
             return context;
-
         }
 
-        return seekEvent(request.getIndex());
+        return seekEvent(request.getStartIndex());
     }
 
     // ------------------------------------------------------------------------
@@ -411,7 +409,7 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser {
      */
     @Override
     @SuppressWarnings("nls")
-    public synchronized String toString() {
+    public String toString() {
         return "[TmfExperiment (" + getName() + ")]";
     }
 
index ecee99cd7ce6001dd8d4cff183144485db80845c..51007e1f4d4221ad76a4dfd723c74f8f9cea61ea 100644 (file)
@@ -27,8 +27,8 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 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.request.ITmfRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfBlockFilter;
 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
@@ -424,7 +424,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
      */
     @Override
-    public synchronized long getNbEvents() {
+    public long getNbEvents() {
         return fNbEvents;
     }
 
@@ -697,20 +697,20 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
      * @since 2.0
      */
     @Override
-    public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
+    public synchronized ITmfContext armRequest(final ITmfRequest 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) request).getRange().getStartTime());
-            ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
-            return context;
 
+        ITmfTimestamp startTime = request.getTimeRange().getStartTime();
+        long startindex = request.getStartIndex();
+        if (!TmfTimestamp.BIG_BANG.equals(startTime) && startindex == 0) {
+            final ITmfContext context = seekEvent(request.getTimeRange().getStartTime());
+            request.addEventFilter(new TmfBlockFilter(context.getRank(), request.getNbRequested()));
+            return context;
         }
-        return seekEvent(request.getIndex());
+
+        return seekEvent(request.getStartIndex());
     }
 
     // ------------------------------------------------------------------------
@@ -829,7 +829,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
      */
     @Override
     @SuppressWarnings("nls")
-    public synchronized String toString() {
+    public String toString() {
         return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
                 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
                 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
index 77fab28140e9cb6d15d6e077c37d04e5ea778197..1c7b4dcaa228120e5f5404c08380b4d9248a16a2 100644 (file)
@@ -100,7 +100,7 @@ public class TmfUml2SDTestTrace implements ITmfEventParser {
             fields[2] = new TmfEventField("signal", signal);
 
             ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields);
-            TmfEvent tmfEvent = new TmfEvent(fEventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference);
+            TmfEvent tmfEvent = new TmfEvent(fEventStream, context.getRank(), new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference);
 
             return tmfEvent;
         } catch (final EOFException e) {
index 5c7ed8466a1285cc7517531743e1dffc3be77536..b6079c022e2cbeaaa2870b5f8a08d1bb502fe0b2 100644 (file)
@@ -2012,7 +2012,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                 }
 
                 @Override
-                public void handleCompleted() {
+                public synchronized void handleCompleted() {
                     super.handleCompleted();
                     if (fTrace == null) {
                         return;
index b9043e99f1a7dfa8eee447f74eab266a63378427..7194de4751425636ad4e4f4e6199705183e7eec2 100644 (file)
@@ -34,6 +34,13 @@ import org.eclipse.swt.widgets.Composite;
  */
 public class HistogramCurrentTimeControl extends HistogramTextControl {
 
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    @SuppressWarnings("unused")
+    private long fTraceStartTime;
+
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
index 7930df748844b7c02220f9a0e8bc306cd9d19dc8..7b55d6d8e4ab8b5b4dedd453d7a81d847ad146cb 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
  * @author Francois Chouinard
  * <p>
  */
+@SuppressWarnings("deprecation")
 public class HistogramRequest extends TmfEventRequest {
 
     // ------------------------------------------------------------------------
@@ -81,6 +82,7 @@ public class HistogramRequest extends TmfEventRequest {
      * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
      */
     @Override
+    @SuppressWarnings("javadoc")
     public void handleData(ITmfEvent event) {
         super.handleData(event);
         if (event != null) {
@@ -95,7 +97,8 @@ public class HistogramRequest extends TmfEventRequest {
      * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
      */
     @Override
-    public void handleCompleted() {
+    @SuppressWarnings("javadoc")
+    public synchronized void handleCompleted() {
         fHistogram.complete();
         super.handleCompleted();
     }
index 2f7f0cb242909f76bf8d8e53fa16b1193846528f..b8e118bb3a74f1546fb1d014c8d82005b2e0964a 100644 (file)
@@ -56,6 +56,7 @@ import org.eclipse.ui.IEditorPart;
  * @version 2.0
  * @author Francois Chouinard
  */
+@SuppressWarnings("deprecation")
 public class HistogramView extends TmfView {
 
     // ------------------------------------------------------------------------
index 1977c59225f40407cc548cf103cffc80fe993eb5..62e6baf058ae0339104edc1d52b6de2c19c2f94e 100644 (file)
@@ -98,6 +98,7 @@ import org.eclipse.ui.progress.IProgressConstants;
  * @version 1.0
  * @author Bernd Hufmann
  */
+@SuppressWarnings("deprecation")
 public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader, ISDFindProvider, ISDFilterProvider, ISDAdvancedPagingProvider, ISelectionListener  {
 
     // ------------------------------------------------------------------------
@@ -303,8 +304,8 @@ public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader,
                  * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
                  */
                 @Override
-                public void handleData(ITmfEvent event) {
-                    super.handleData(event);
+                public synchronized void handleEvent(ITmfEvent event) {
+                    super.handleEvent(event);
 
                     ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event);
 
@@ -375,7 +376,7 @@ public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader,
                  * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
                  */
                 @Override
-                public void handleCompleted() {
+                public synchronized void handleCompleted() {
                     if (fEvents.isEmpty()) {
                         fFrame = new Frame();
                         fView.setFrameSync(fFrame);
@@ -1137,8 +1138,8 @@ public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader,
             private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>();
 
             @Override
-            public void handleData(ITmfEvent event) {
-                super.handleData(event);
+            public synchronized void handleEvent(ITmfEvent event) {
+                super.handleEvent(event);
 
                 ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event);
 
@@ -1429,8 +1430,8 @@ public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader,
          * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
          */
         @Override
-        public void handleData(ITmfEvent event) {
-            super.handleData(event);
+        public synchronized void handleEvent(ITmfEvent event) {
+            super.handleEvent(event);
 
             if ((fMonitor!= null) && fMonitor.isCanceled()) {
                 super.cancel();
This page took 0.121179 seconds and 5 git commands to generate.