ITmfStateSystem.waitUntilBuilt() will now block the calling
thread until the state system underneath is finished building.
This will be immediately useful for statistics (intermediate
queries are useless, we need to wait until it's ready anyway).
It's implemented using a CountDownLatch, similar to the
.waitForCompletion() in event requests.
Change-Id: I98420acc3ca2903d76a315259f25dca7d88b8d42
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/8427
Tested-by: Hudson CI
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
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;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
private final TransientState transState;
private final IStateHistoryBackend backend;
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
*
/**
* General constructor
*
/* We're opening an existing file */
this.attributeTree = new AttributeTree(this, backend.supplyAttributeTreeReader());
transState.setInactive();
/* 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();
*/
attributeTree.writeSelf(attributeTreeFile, attributeTreeFilePos);
}
*/
attributeTree.writeSelf(attributeTreeFile, attributeTreeFilePos);
}
+ finishedLatch.countDown(); /* Mark the history as finished building */
}
//--------------------------------------------------------------------------
}
//--------------------------------------------------------------------------
*/
public long getCurrentEndTime();
*/
public long getCurrentEndTime();
+ /**
+ * While it's possible to query a state history that is being built,
+ * sometimes we might want to wait until the construction is finished before
+ * we start doing queries.
+ *
+ * This method blocks the calling thread until the history back-end is done
+ * building. If it's already built (ie, opening a pre-existing file) this
+ * should return immediately. It's an alternative to listening to the
+ * {@link org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted}
+ * signal.
+ */
+ public void waitUntilBuilt();
+
/**
* Return the current total amount of attributes in the system. This is also
* equal to the quark that will be assigned to the next attribute that's
/**
* Return the current total amount of attributes in the system. This is also
* equal to the quark that will be assigned to the next attribute that's