From 7e634be6b4d5802ef6d66f642229d6e9fc5f8f7e Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 7 Feb 2013 17:14:40 -0500 Subject: [PATCH] tmf: Move some logic outside of HistoryBuilder 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 Reviewed-on: https://git.eclipse.org/r/10280 Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse Tested-by: Hudson CI --- .../tmf/core/statesystem/HistoryBuilder.java | 27 ++++++++++++------- .../statesystem/AbstractStateChangeInput.java | 5 ++++ .../core/statesystem/IStateChangeInput.java | 9 +++++++ .../core/statesystem/StateSystemManager.java | 24 ++++++++++------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java index edd2aac2eb..055fc2f7ad 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java @@ -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); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractStateChangeInput.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractStateChangeInput.java index f3e32bf201..b8a3a08070 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractStateChangeInput.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractStateChangeInput.java @@ -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. */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateChangeInput.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateChangeInput.java index 95a8f03053..c19eb7317a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateChangeInput.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateChangeInput.java @@ -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 diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java index 205bdfa1ce..4d8f8e0cdf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java @@ -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(); } } -- 2.34.1