tmf: Move some logic outside of HistoryBuilder
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 7 Feb 2013 22:14:40 +0000 (17:14 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 12 Feb 2013 21:39:22 +0000 (16:39 -0500)
Move the input.assignTargetSS() call outside of HistoryBuilder's
constructor. This will allow more flexibility for input/backend
types that need to instantiate their objects in a different
order than the typical "kernel input -> ss -> history tree"
trinity does (for example, partial histories).

Change-Id: I2d07b44e39e55475bd6bdfde8641d2985b7c145f
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/10280
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Hudson CI
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/statesystem/AbstractStateChangeInput.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateChangeInput.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java

index edd2aac2eb78026de3e320848ce5764e4818421b..055fc2f7ad30a1c26232db49e0f466a64385a4b3 100644 (file)
@@ -50,29 +50,36 @@ public class HistoryBuilder extends TmfComponent {
     private boolean started = true; /* Don't handle signals until we're ready */
 
     /**
-     * Instantiate a new HistoryBuilder helper.
+     * Instantiate a new HistoryBuilder helper. The input -> ss -> backend
+     * relationships should have been set up already.
      *
      * @param stateChangeInput
-     *            The input plugin to use. This is required.
+     *            The input plugin to use
+     * @param ss
+     *            The state system object that will receive the state changes
+     *            from the input
      * @param backend
-     *            The back-end storage to use.
+     *            The back-end storage to use, which will receive the intervals
+     *            from the ss
      * @param buildManually
      *            Should we build this history in-band or not. True means we
      *            will start the building ourselves and block the caller until
      *            construction is done. False (out-of-band) means we will start
-     *            listening for the signal and return immediately. Another
-     *            signal will be sent when finished.
+     *            listening for the signal and return immediately.
      */
-    public HistoryBuilder(IStateChangeInput stateChangeInput,
+    public HistoryBuilder(IStateChangeInput stateChangeInput, StateSystem ss,
             IStateHistoryBackend backend, boolean buildManually) {
-        if (stateChangeInput == null || backend == null) {
+        if (stateChangeInput == null || backend == null || ss == null) {
             throw new IllegalArgumentException();
         }
+        if (stateChangeInput.getAssignedStateSystem() != ss) {
+            /* Logic check to make sure the input is setup properly */
+            throw new RuntimeException();
+        }
+
         sci = stateChangeInput;
         hb = backend;
-        ss = new StateSystem(hb);
-
-        sci.assignTargetStateSystem(ss);
+        this.ss = ss;
 
         if (buildManually) {
             TmfSignalManager.deregister(this);
index f3e32bf20157ad6650397c643cf2df1c19f891f0..b8a3a080707c6965f00405b49738d985033a865d 100644 (file)
@@ -90,6 +90,11 @@ public abstract class AbstractStateChangeInput implements IStateChangeInput {
         eventHandlerThread.start();
     }
 
+    @Override
+    public ITmfStateSystem getAssignedStateSystem() {
+        return ss;
+    }
+
     @Override
     public void dispose() {
         /* Insert a null event in the queue to stop the event handler's thread. */
index 95a8f0305378381a0bebec508a381863f381557b..c19eb7317a1d5eb714920c97732be2ec0d7ecea2 100644 (file)
@@ -68,6 +68,15 @@ public interface IStateChangeInput {
      */
     public void assignTargetStateSystem(ITmfStateSystemBuilder ssb);
 
+    /**
+     * Return the currently assigned target state system.
+     *
+     * @return Reference to the currently assigned state system, or null if no
+     *         SS is assigned yet
+     * @since 2.0
+     */
+    public ITmfStateSystem getAssignedStateSystem();
+
     /**
      * Send an event to this input plugin for processing. The implementation
      * should check the contents, and call the state-modifying methods of its
index 205bdfa1ceb0e4ad60424a75e8dc1d4376d73e5f..4d8f8e0cdf84a085ea6466aecfdb6a5c5fe797e7 100644 (file)
@@ -16,6 +16,7 @@ import java.io.File;
 import java.io.IOException;
 
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder;
+import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.InMemoryBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.NullBackend;
@@ -64,7 +65,6 @@ public abstract class StateSystemManager extends TmfComponent {
     public static ITmfStateSystem loadStateHistory(File htFile,
             IStateChangeInput htInput, boolean buildManually)
             throws TmfTraceException {
-        ITmfStateSystem ss;
         IStateHistoryBackend htBackend;
 
         /* If the target file already exists, do not rebuild it uselessly */
@@ -74,7 +74,7 @@ public abstract class StateSystemManager extends TmfComponent {
             /* Load an existing history */
             try {
                 htBackend = new HistoryTreeBackend(htFile);
-                ss = HistoryBuilder.openExistingHistory(htBackend);
+                ITmfStateSystem ss = HistoryBuilder.openExistingHistory(htBackend);
                 return ss;
             } catch (IOException e) {
                 /*
@@ -92,9 +92,10 @@ public abstract class StateSystemManager extends TmfComponent {
             return null;
         }
         try {
-            htBackend = new ThreadedHistoryTreeBackend(htFile,
-                    htInput.getStartTime(), QUEUE_SIZE);
-            builder = new HistoryBuilder(htInput, htBackend, buildManually);
+            htBackend = new ThreadedHistoryTreeBackend(htFile, htInput.getStartTime(), QUEUE_SIZE);
+            StateSystem ss = new StateSystem(htBackend);
+            htInput.assignTargetStateSystem(ss);
+            builder = new HistoryBuilder(htInput, ss, htBackend, buildManually);
         } catch (IOException e) {
             /*
              * If it fails here however, it means there was a problem writing to
@@ -120,9 +121,11 @@ public abstract class StateSystemManager extends TmfComponent {
      */
     public static ITmfStateSystem newNullHistory(IStateChangeInput input) {
         IStateHistoryBackend backend = new NullBackend();
-        HistoryBuilder builder = new HistoryBuilder(input, backend, true);
-        ITmfStateSystem ss = builder.getStateSystemQuerier();
-        return ss;
+        StateSystem ss = new StateSystem(backend);
+        input.assignTargetStateSystem(ss);
+
+        HistoryBuilder builder = new HistoryBuilder(input, ss, backend, true);
+        return builder.getStateSystemQuerier();
     }
 
     /**
@@ -144,7 +147,10 @@ public abstract class StateSystemManager extends TmfComponent {
     public static ITmfStateSystem newInMemHistory(IStateChangeInput input,
             boolean buildManually) {
         IStateHistoryBackend backend = new InMemoryBackend(input.getStartTime());
-        HistoryBuilder builder = new HistoryBuilder(input, backend, buildManually);
+        StateSystem ss = new StateSystem(backend);
+        input.assignTargetStateSystem(ss);
+
+        HistoryBuilder builder = new HistoryBuilder(input, ss, backend, buildManually);
         return builder.getStateSystemQuerier();
     }
 }
This page took 0.063074 seconds and 5 git commands to generate.