tmf: Add dispose methods to the state and stats backends
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / statesystem / historytree / HistoryTreeBackend.java
index 0e119a95c70cf85fc03808d5989ade07d5f44240..d13598022ffa00f75dfa24b7d2503f552c26e2f0 100644 (file)
@@ -36,6 +36,9 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
     protected final HistoryTree sht;
     private final HT_IO treeIO;
 
+    /** Indicates if the history tree construction is done */
+    protected boolean isFinishedBuilding = false;
+
     /**
      * Construtor for new history files. Use this when creating a new history
      * from scratch.
@@ -89,6 +92,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
     public HistoryTreeBackend(File existingStateFile) throws IOException {
         sht = new HistoryTree(existingStateFile);
         treeIO = sht.getTreeIO();
+        isFinishedBuilding = true;
     }
 
     @Override
@@ -114,6 +118,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
     @Override
     public void finishedBuilding(long endTime) {
         sht.closeTree(endTime);
+        isFinishedBuilding = true;
     }
 
     @Override
@@ -136,6 +141,20 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
         treeIO.deleteFile();
     }
 
+    @Override
+    public void dispose() {
+        if (isFinishedBuilding) {
+            treeIO.closeFile();
+        } else {
+            /*
+             * The build is being interrupted, delete the file we partially
+             * built since it won't be complete, so shouldn't be re-used in the
+             * future (.deleteFile() will close the file first)
+             */
+            treeIO.deleteFile();
+        }
+    }
+
     @Override
     public void doQuery(List<ITmfStateInterval> stateInfo, long t)
             throws TimeRangeException {
This page took 0.02535 seconds and 5 git commands to generate.