From 09ec275eb5dc0fb14f7941cb168ce85792a9e12f Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 24 Jan 2014 16:06:28 -0500 Subject: [PATCH] tmf: Add a waitForInitialization() to the state system module With this, views and other components can be notified when the underlying state system is instantiated and ready to be queried. Change-Id: I0802d95b3311b1124803b55b3c5dd617e26afa48 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/21069 Tested-by: Hudson CI Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse Tested-by: Patrick Tasse --- .../StateSystemAnalysisModuleTest.java | 28 +++++++++++++------ .../TmfStateSystemAnalysisModule.java | 27 +++++++++++++++++- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java index cea19e4c92..29684b8d45 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java @@ -44,14 +44,18 @@ public class StateSystemAnalysisModuleTest { /** ID of the test state system analysis module */ public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.analysis.sstest"; - private TmfTraceStub fTrace; + private TmfStateSystemAnalysisModule module; /** * Setup test trace */ @Before public void setupTraces() { - fTrace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace(); + TmfTraceStub trace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace(); + TmfSignalManager.deregister(trace); + trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null)); + + module = (TmfStateSystemAnalysisModule) trace.getAnalysisModule(MODULE_SS); } /** @@ -67,12 +71,7 @@ public class StateSystemAnalysisModuleTest { */ @Test public void testSsModule() { - TmfSignalManager.deregister(fTrace); - fTrace.traceOpened(new TmfTraceOpenedSignal(this, fTrace, null)); - - TmfStateSystemAnalysisModule module = (TmfStateSystemAnalysisModule) fTrace.getAnalysisModule(MODULE_SS); - ITmfStateSystem ss = null; - ss = module.getStateSystem(); + ITmfStateSystem ss = module.getStateSystem(); assertNull(ss); module.schedule(); if (module.waitForCompletion(new NullProgressMonitor())) { @@ -83,4 +82,17 @@ public class StateSystemAnalysisModuleTest { } } + /** + * Make sure that the state system is initialized after calling  + * {@link TmfStateSystemAnalysisModule#waitForInitialization()}. + */ + @Test + public void testInitialization() { + assertNull(module.getStateSystem()); + module.schedule(); + + module.waitForInitialization(); + assertNotNull(module.getStateSystem()); + } + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java index f1cdb21399..ec784190a1 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java @@ -16,6 +16,7 @@ package org.eclipse.linuxtools.tmf.core.statesystem; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.concurrent.CountDownLatch; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -57,6 +58,8 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo private static final String EXTENSION = ".ht"; //$NON-NLS-1$ + private final CountDownLatch fInitialized = new CountDownLatch(1); + @Nullable private ITmfStateSystemBuilder fStateSystem; @Nullable private ITmfStateProvider fStateProvider; @Nullable private IStateHistoryBackend fHtBackend; @@ -113,6 +116,17 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo return fStateSystem; } + /** + * Block the calling thread until the analysis module has been initialized. + * After this method returns, {@link #getStateSystem()} should not return + * null anymore. + */ + public void waitForInitialization() { + try { + fInitialized.await(); + } catch (InterruptedException e) {} + } + // ------------------------------------------------------------------------ // TmfAbstractAnalysisModule // ------------------------------------------------------------------------ @@ -183,6 +197,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo try { fHtBackend = new HistoryTreeBackend(htFile, version); fStateSystem = new StateSystem(fHtBackend, false); + fInitialized.countDown(); return; } catch (IOException e) { /* @@ -338,8 +353,18 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo fStateProvider = provider; fRequest = request; + /* + * The state system object is now created, we can consider this module + * "initialized" (components can retrieve it and start doing queries). + */ + fInitialized.countDown(); + + /* + * Block the executeAnalysis() construction is complete (so that the + * progress monitor displays that it is running). + */ try { - fRequest.waitForCompletion(); + request.waitForCompletion(); } catch (InterruptedException e) { e.printStackTrace(); } -- 2.34.1