tmf: Allow waiting for a state system's completion
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / statesystem / StateSystem.java
index c4b7029f415a10c6acc1265489df12804a10b841..b302e49d568efc239ab281388c409864a1052aa7 100644 (file)
@@ -18,6 +18,7 @@ import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -51,6 +52,9 @@ public class StateSystem implements ITmfStateSystemBuilder {
     private final TransientState transState;
     private final IStateHistoryBackend backend;
 
+    /* Latch tracking if the state history is done building or not */
+    private final CountDownLatch finishedLatch = new CountDownLatch(1);
+
     /**
      * General constructor
      *
@@ -73,6 +77,16 @@ public class StateSystem implements ITmfStateSystemBuilder {
             /* We're opening an existing file */
             this.attributeTree = new AttributeTree(this, backend.supplyAttributeTreeReader());
             transState.setInactive();
+            finishedLatch.countDown(); /* The history is already built */
+        }
+    }
+
+    @Override
+    public void waitUntilBuilt() {
+        try {
+            finishedLatch.await();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
         }
     }
 
@@ -147,6 +161,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
              */
             attributeTree.writeSelf(attributeTreeFile, attributeTreeFilePos);
         }
+        finishedLatch.countDown(); /* Mark the history as finished building */
     }
 
     //--------------------------------------------------------------------------
This page took 0.024858 seconds and 5 git commands to generate.