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;
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();
* 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);
}
}
// ------------------------------------------------------------------------
- // 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
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;