2010-09-17 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug325662
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / control / LttngSyntheticEventProvider.java
index 4af8017b7af444437fe7a3374b038c0ef09d51e0..821c6c8ab22978238b1f5a12818259e144227e5e 100644 (file)
@@ -51,10 +51,10 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
        // ========================================================================
        // Data
        // ========================================================================
+
        public static final int BLOCK_SIZE = 1;
        public static final int NB_EVENTS  = 1;
-       public static final int QUEUE_SIZE = 1; // lttng specific, one event at a
-                                                                                       // time
+       public static final int QUEUE_SIZE = 1; // lttng specific, one event at a time
 
        // TmfDataProvider<LttngEvent> fExtProvider = null;
        private ITmfDataRequest<LttngSyntheticEvent> fmainRequest = null;
@@ -64,7 +64,8 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
        private int fMainReqEventCount = 0;
        volatile boolean startIndSent = false;
        private LTTngTreeNode fExperiment = null;
-       private ITransEventProcessor fstateUpdateProcessor = StateEventToHandlerFactory.getInstance();
+       private ITransEventProcessor fstateUpdateProcessor = StateEventToHandlerFactory
+                       .getInstance();
        private boolean waitForRequest = false;
 
        // ========================================================================
@@ -82,12 +83,15 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                // the framework
                TmfEventSource source = new TmfEventSource(this);
                LttngEventType dtype = new LttngEventType();
-               LttngTimestamp statusTimeStamp = new LttngTimestamp(TmfTimestamp.Zero);
+               LttngTimestamp statusTimeStamp = new LttngTimestamp(
+                               TmfTimestamp.Zero);
 
-               fStatusEvent = new LttngSyntheticEvent(null, statusTimeStamp, source, dtype, null, null, null);
+               fStatusEvent = new LttngSyntheticEvent(null, statusTimeStamp, source,
+                               dtype, null, null, null);
                fStatusEvent.setSequenceInd(SequenceInd.STARTREQ);
 
-               fStatusEventAck = new LttngSyntheticEvent(null, statusTimeStamp, source, dtype, null, null, null);
+               fStatusEventAck = new LttngSyntheticEvent(null, statusTimeStamp,
+                               source, dtype, null, null, null);
                fStatusEventAck.setSequenceInd(SequenceInd.ACK);
        }
 
@@ -97,7 +101,8 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
 
        @SuppressWarnings("unchecked")
        @Override
-       public ITmfContext armRequest(final ITmfDataRequest<LttngSyntheticEvent> request) {
+       public ITmfContext armRequest(
+                       final ITmfDataRequest<LttngSyntheticEvent> request) {
                // validate
                // make sure we have the right type of request
                if (!(request instanceof ITmfEventRequest<?>)) {
@@ -136,7 +141,8 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                for (IStateTraceManager traceManager : fEventProviderRequests.keySet()) {
 
                        // restore trace state system to nearest check point
-                       TmfTimestamp checkPoint = traceManager.restoreCheckPointByTimestamp(reqWindow.getStartTime());
+                       TmfTimestamp checkPoint = traceManager
+                                       .restoreCheckPointByTimestamp(reqWindow.getStartTime());
 
                        // adjust start time bound to check point
 
@@ -169,28 +175,21 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
 
                                private final long fDispatchTime = getDispatchTime().getValue();
                                private final LttngTraceState fTraceModel = getTraceModel();
-                               private LttngSyntheticEvent[] fresult = new LttngSyntheticEvent[1];
 
                                /*
                                 * (non-Javadoc)
                                 * 
-                                * @see org.eclipse.linuxtools.lttng.control.LttngEventRequest#handleData ()
+                                * @see org.eclipse.linuxtools.lttng.control.LttngEventRequest#handleData()
                                 */
                                @Override
-                               public void handleData() {
-                                       LttngEvent[] events = getData();
-
-                                       // Tracer.trace("Sep: " + events[0].getTimestamp());
-
-                                       if (events.length > 0) {
-                                               handleIncomingData(events[0]);
+                               public void handleData(LttngEvent event) {
+                                       super.handleData(event);
+                                       if (event != null) {
+                                               handleIncomingData(event);
                                        } else {
                                                TraceDebug.debug("handle data received with no data");
-                                               // handleProviderDone(getTraceModel());
-                                               // done();
                                        }
                                }
-
                                /*
                                 * (non-Javadoc)
                                 * 
@@ -200,10 +199,9 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                                public void done() {
                                        // mark this sub-request as completed
                                        super.done();
-                                       handleProviderDone();
-                                       // super.done();
+                                       handleProviderDone(getTraceModel());
                                }
-
+                               
                                /**
                                 * Trigger the Analysis and sequential control of the events.
                                 * 
@@ -212,43 +210,29 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                                private void handleIncomingData(LttngEvent e) {
                                        long eventTime = e.getTimestamp().getValue();
 
-                                       TmfTrace<LttngEvent> inTrace = e.getParentTrace();
+                                       TmfTrace<LttngEvent> inTrace =  e.getParentTrace();
                                        if (!(inTrace == getTrace())) {
-                                               // System.out.println("Event from a different trace discarded");
                                                return;
                                        }
-
+                                       
                                        // queue the new event data and an ACK
                                        updateSynEvent(e);
 
                                        // If time at or above requested time, update application
                                        if (eventTime >= fDispatchTime) {
-                                               // Load synthetic event as the result data
-                                               fresult[0] = syntheticEvent;
-
-                                               // BEFORE UPDATE : update to the before state-update handlers
+                                               // Before update
                                                syntheticEvent.setSequenceInd(SequenceInd.BEFORE);
-                                               // queueResult(syntheticEvent);
-                                               // queueResult(syntheticAckIndicator);
-                                               fmainRequest.setData(fresult);
-                                               fmainRequest.handleData();
-                                               // result[0] = syntheticAckIndicator;
-                                               // fmainRequest.setData(result);
-                                               // fmainRequest.handleData();
-
-                                               // STATE UPDATE: local handlers
+                                               fmainRequest.handleData(syntheticEvent);
+                                               fmainRequest.handleData(syntheticAckIndicator);
+
+                                               // Update state locally
                                                syntheticEvent.setSequenceInd(SequenceInd.UPDATE);
                                                fstateUpdateProcessor.process(syntheticEvent, fTraceModel);
 
-                                               // AFTER UPDATE: update to the after state-update handlers
+                                               // After Update
                                                syntheticEvent.setSequenceInd(SequenceInd.AFTER);
-                                               // queueResult(syntheticEvent);
-                                               // queueResult(syntheticAckIndicator);
-                                               fmainRequest.setData(fresult);
-                                               fmainRequest.handleData();
-                                               // result[0] = syntheticAckIndicator;
-                                               // fmainRequest.setData(result);
-                                               // fmainRequest.handleData();
+                                               fmainRequest.handleData(syntheticEvent);
+                                               fmainRequest.handleData(syntheticAckIndicator);
 
                                                // increment once per dispatch
                                                incrementSynEvenCount();
@@ -264,16 +248,18 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                                }
 
                                /**
-                                * Create a synthetic event from the received new reference, if the reference is the same there is no
-                                * need for a new instance
+                                * Create a synthetic event from the received new reference, if
+                                * the reference is the same there is no need for a new instance
                                 * 
-                                * if this is the first event for this request, call start handler
+                                * if this is the first event for this request, call start
+                                * handler
                                 * 
                                 * @param e
                                 * @return
                                 */
                                private LttngSyntheticEvent updateSynEvent(LttngEvent e) {
-                                       if (syntheticEvent == null || syntheticEvent.getBaseEvent() != e) {
+                                       if (syntheticEvent == null
+                                                       || syntheticEvent.getBaseEvent() != e) {
                                                syntheticEvent = new LttngSyntheticEvent(e);
                                                syntheticAckIndicator = new LttngSyntheticEvent(e);
                                                syntheticAckIndicator.setSequenceInd(SequenceInd.ACK);
@@ -292,7 +278,7 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                                        return syntheticEvent;
                                }
                        };
-
+                                               
                        // preserve the associated sub request to control it e.g.
                        // cancellation
                        fEventProviderRequests.put(traceManager, subRequest);
@@ -319,30 +305,18 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                startIndEvent.setSequenceInd(SequenceInd.STARTREQ);
 
                // Notify application
-               LttngSyntheticEvent[] result = new LttngSyntheticEvent[1];
-               result[0] = startIndEvent;
-               fmainRequest.setData(result);
-               fmainRequest.handleData();
-               // result[0] = fStatusEventAck;
-               // fmainRequest.setData(result);
-               // fmainRequest.handleData();
-
-               // try {
-               // queueResult(startIndEvent);
-               // queueResult(fStatusEventAck);
-               // } catch (InterruptedException e) {
-               // // TODO: cancel this request
-               // e.printStackTrace();
-               // }
+               fmainRequest.handleData(startIndEvent);
+               fmainRequest.handleData(fStatusEventAck);
 
                // Notify state event processor
                fstateUpdateProcessor.process(startIndEvent, null);
        }
 
        /**
-        * Notify listeners, no more events for the current request will be distributed e.g. update view.
+        * Notify listeners, no more events for the current request will be
+        * distributed e.g. update view.
         */
-       public synchronized void handleProviderDone() {
+       public synchronized void handleProviderDone(LttngTraceState traceModel) {
                // TODO: The use of a thread per main request and thread per sub-request
                // requires
                // to make sure the proper main request is marked completed. So a
@@ -359,44 +333,16 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                        }
                }
 
-               // Notify application. One notification per trace so the last state of each trace can be
-               // drawn
-               LttngTraceState traceModel;
-               for (IStateTraceManager traceMgr : fEventProviderRequests.keySet()) {
-                       traceModel = traceMgr.getStateModel();
-
-                       LttngSyntheticEvent finishEvent = new LttngSyntheticEvent(fStatusEvent);
-                       // finishEvent.setTraceModel(traceModel);
-                       // finishEvent.setParentTrace((TmfTrace<LttngEvent>) traceModel.getContext().getTraceIdRef());
-                       finishEvent.setSequenceInd(SequenceInd.ENDREQ);
-                       finishEvent.setTraceModel(traceModel);
-
-                       LttngSyntheticEvent[] result = new LttngSyntheticEvent[1];
-                       // End Request indication
-                       result[0] = finishEvent;
-                       fmainRequest.setData(result);
-                       fmainRequest.handleData();
-
-                       // // End Request processed indication
-                       // result[0] = fStatusEventAck;
-                       // fmainRequest.setData(result);
-                       // fmainRequest.handleData();
-               }
+               // All sub-requests are marked completed so the main request can be
+               // completed as well
+               // Notify application,
+               LttngSyntheticEvent finishEvent = new LttngSyntheticEvent(fStatusEvent);
+               finishEvent.setSequenceInd(SequenceInd.ENDREQ);
+               finishEvent.setTraceModel(traceModel);
 
-               // All sub-requests are marked completed so the main request can be completed as well
+               fmainRequest.handleData(finishEvent);
+               fmainRequest.handleData(fStatusEventAck);
                fmainRequest.done();
-
-               // try {
-               // queueResult(finishEvent);
-               // queueResult(fStatusEventAck);
-               // // End the loop in the main request
-               // queueResult(LttngSyntheticEvent.NullEvent);
-               // } catch (InterruptedException e) {
-               // // System.out.println(getName() +
-               // // ":handleProviderDone() failed to queue request");
-               // // TODO: Cancel the request
-               // // e.printStackTrace();
-               // }
        }
 
        /**
@@ -453,18 +399,21 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
         * @param experiment
         */
        private synchronized void updateExperimentNode(LTTngTreeNode experiment) {
-               if (experiment != null && experiment.getValue() instanceof TmfExperiment<?>) {
+               if (experiment != null
+                               && experiment.getValue() instanceof TmfExperiment<?>) {
                        fExperiment = experiment;
                } else {
                        TraceDebug
-                                       .debug("Experiment received is not instance of TmfExperiment: " + experiment.getClass().getName());
+                                       .debug("Experiment received is not instance of TmfExperiment: "
+                                                       + experiment.getClass().getName());
                }
        }
 
        /*
         * (non-Javadoc)
         * 
-        * @see org.eclipse.linuxtools.tmf.component.TmfDataProvider#sendRequest(org.
+        * @see
+        * org.eclipse.linuxtools.tmf.component.TmfDataProvider#sendRequest(org.
         * eclipse.linuxtools.tmf.request.TmfDataRequest)
         */
        @Override
@@ -504,14 +453,4 @@ public class LttngSyntheticEventProvider extends TmfEventProvider<LttngSynthetic
                return null;
        }
 
-       // @Override
-       // public LttngSyntheticEvent getNext(ITmfContext context) {
-       // return super.getNext(context);
-       // }
-
-       // @Override
-       // public void queueResult(LttngSyntheticEvent data) {
-       // super.queueResult(data);
-       // }
-
 }
This page took 0.028384 seconds and 5 git commands to generate.