tmf: Add a waitForInitialization() to the state system module
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / TmfStateSystemAnalysisModule.java
index f1cdb21399afb833761c611030ec53a2b4e5d941..ec784190a1c83b8cbc5b85e77213ade14280b1e2 100644 (file)
@@ -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();
         }
This page took 0.027088 seconds and 5 git commands to generate.