tmf: Add a StateSystemDisposedException
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / statesystem / StateSystem.java
index 527f7eee64f222f6aa384c81fd72b8caad122688..e6baedbd04a5ec00eb650b7b449319d3f4d4920b 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.linuxtools.internal.tmf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
@@ -56,6 +57,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
     private final CountDownLatch finishedLatch = new CountDownLatch(1);
 
     private boolean buildCancelled = false;
+    private boolean isDisposed = false;
 
     /**
      * General constructor
@@ -95,6 +97,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
 
     @Override
     public synchronized void dispose() {
+        isDisposed = true;
         if (transState.isActive()) {
             transState.setInactive();
             buildCancelled = true;
@@ -460,7 +463,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
 
     @Override
     public synchronized List<ITmfStateInterval> queryFullState(long t)
-            throws TimeRangeException {
+            throws TimeRangeException, StateSystemDisposedException {
+        if (isDisposed) {
+            throw new StateSystemDisposedException();
+        }
+
         List<ITmfStateInterval> stateInfo = new ArrayList<ITmfStateInterval>(
                 attributeTree.getNbAttributes());
 
@@ -496,9 +503,13 @@ public class StateSystem implements ITmfStateSystemBuilder {
 
     @Override
     public ITmfStateInterval querySingleState(long t, int attributeQuark)
-            throws AttributeNotFoundException, TimeRangeException {
-        ITmfStateInterval ret;
+            throws AttributeNotFoundException, TimeRangeException,
+            StateSystemDisposedException {
+        if (isDisposed) {
+            throw new StateSystemDisposedException();
+        }
 
+        ITmfStateInterval ret;
         if (transState.hasInfoAboutStateOf(t, attributeQuark)) {
             ret = transState.getOngoingInterval(attributeQuark);
         } else {
@@ -520,7 +531,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
     @Override
     public ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
             throws StateValueTypeException, AttributeNotFoundException,
-            TimeRangeException {
+            TimeRangeException, StateSystemDisposedException {
         Integer curStackDepth = querySingleState(t, stackAttributeQuark).getStateValue().unboxInt();
 
         if (curStackDepth == -1) {
@@ -542,7 +553,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
     @Override
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2) throws TimeRangeException,
-            AttributeNotFoundException {
+            AttributeNotFoundException, StateSystemDisposedException {
+        if (isDisposed) {
+            throw new StateSystemDisposedException();
+        }
+
         List<ITmfStateInterval> intervals;
         ITmfStateInterval currentInterval;
         long ts, tEnd;
@@ -578,7 +593,12 @@ public class StateSystem implements ITmfStateSystemBuilder {
     @Override
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2, long resolution, IProgressMonitor monitor)
-            throws TimeRangeException, AttributeNotFoundException {
+            throws TimeRangeException, AttributeNotFoundException,
+            StateSystemDisposedException {
+        if (isDisposed) {
+            throw new StateSystemDisposedException();
+        }
+
         List<ITmfStateInterval> intervals;
         ITmfStateInterval currentInterval;
         long ts, tEnd;
This page took 0.025005 seconds and 5 git commands to generate.