tmf: Remove dependency to ctfadaptor from the state system
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 27 Feb 2014 19:30:43 +0000 (14:30 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 28 Feb 2014 18:56:41 +0000 (13:56 -0500)
Change-Id: I79b7cf539eba6ace434fc7dfbb32bc3386c68b8c
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/22640
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java

index fb17295cb9f79e85a7f77cba30effbdc9e5c9fa3..8c5d6acd1ab8079b9269c6d454444552c1737220 100644 (file)
@@ -15,11 +15,9 @@ package org.eclipse.linuxtools.tmf.core.statesystem;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 
@@ -98,7 +96,7 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
     public void dispose() {
         /* Insert a null event in the queue to stop the event handler's thread. */
         try {
-            eventsQueue.put(CtfTmfEventFactory.getNullEvent());
+            eventsQueue.put(END_EVENT);
             eventHandlerThread.join();
         } catch (InterruptedException e) {
             e.printStackTrace();
@@ -138,10 +136,8 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
          * the state. That way, when that event leaves the queue, we will know
          * for sure that the state system processed the preceding real event.
          */
-        TmfEvent ev = new EmptyEvent();
-
         try {
-            eventsQueue.put(ev);
+            eventsQueue.put(EMPTY_QUEUE_EVENT);
             while (!eventsQueue.isEmpty()) {
                 Thread.sleep(100);
             }
@@ -151,18 +147,20 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
     }
 
     // ------------------------------------------------------------------------
-    // Inner classes
+    // Special event types
     // ------------------------------------------------------------------------
 
-    /**
-     * Empty event that should be totally ignored by the event handler. It can
-     * by used for synchronisation purposes.
-     */
-    private class EmptyEvent extends TmfEvent {
-        public EmptyEvent() {
-            super(null, new TmfTimestamp(0), null, null, null, null);
-        }
-    }
+    /** Fake event indicating the build is over, and the provider should close */
+    private static class EndEvent extends TmfEvent {}
+    /** Fake event indicating we want to clear the current queue */
+    private static class EmptyQueueEvent extends TmfEvent {}
+
+    private static final EndEvent END_EVENT = new EndEvent();
+    private static final EmptyQueueEvent EMPTY_QUEUE_EVENT = new EmptyQueueEvent();
+
+    // ------------------------------------------------------------------------
+    // Inner classes
+    // ------------------------------------------------------------------------
 
     /**
      * This is the runner class for the second thread, which will take the
@@ -182,8 +180,9 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
 
             try {
                 event = eventsQueue.take();
-                while (event.getTimestamp().getValue() != -1) {
-                    if (event instanceof EmptyEvent) {
+                /* This is a singleton, we want to do != instead of !x.equals */
+                while (event != END_EVENT) {
+                    if (event == EMPTY_QUEUE_EVENT) {
                         /* Synchronization event, should be ignored */
                         event = eventsQueue.take();
                         continue;
This page took 0.025883 seconds and 5 git commands to generate.