tmf: Fix fake event problem in AbstractTmfStateProvider
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 26 Jun 2013 18:17:30 +0000 (14:17 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 27 Jun 2013 20:13:29 +0000 (16:13 -0400)
For a given state provider, if the last event modifies the state
AND the user calls .waitForEmptyQueue() right before closing the
tree manually, the resulting history would have an incorrect end
time and it would be impossible to query at the timestamp of the
last event.

This was due do a "fake" synchronization event being set as the
provider's current event, so when closing the history it would
use its time stamp which is effectively 0.

Remedy this by using an internal event class explicitely for this.
Thanks to J.-C. Kouamé for finding this one!

Change-Id: I06227ca656a67991966b1d1dd15330cb97754fbe
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14080
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java

index 95214e1d735a5510caaab3c0a18a8c05b659642e..78e5e8cef66457c984c23b08eb46b0120a0b83ff 100644 (file)
@@ -141,8 +141,7 @@ 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.
          */
-        TmfTimestamp ts = new TmfTimestamp(0); /* it must not be -1! */
-        TmfEvent ev = new TmfEvent(null, ts, null, null, null, null);
+        TmfEvent ev = new EmptyEvent();
 
         try {
             eventsQueue.put(ev);
@@ -154,6 +153,20 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
         }
     }
 
+    // ------------------------------------------------------------------------
+    // Inner classes
+    // ------------------------------------------------------------------------
+
+    /**
+     * 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);
+        }
+    }
+
     /**
      * This is the runner class for the second thread, which will take the
      * events from the queue and pass them through the state system.
@@ -171,6 +184,12 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
             try {
                 event = eventsQueue.take();
                 while (event.getTimestamp().getValue() != -1) {
+                    if (event instanceof EmptyEvent) {
+                        /* Synchronization event, should be ignored */
+                        event = eventsQueue.take();
+                        continue;
+                    }
+
                     currentEvent = event;
 
                     /* Make sure this is an event the sub-class can process */
This page took 0.027442 seconds and 5 git commands to generate.