segStore: Add a close method to ISegmentStore
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 17 May 2016 14:21:38 +0000 (10:21 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 18 May 2016 15:16:39 +0000 (11:16 -0400)
This method will close the segment store backend at the end of the analysis or
delete the files that were created if the analysis did not create correctly.

This method will be useful when there is multiple segment store backends, so
that each one can take care of its own saving actions and cleanup.

Change-Id: I7c2bd4c21b9141b0b4f0f3eed2495895299d3dc8
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/72931
Reviewed-by: Hudson CI
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisEventBasedModule.java
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/AbstractSegmentStoreAnalysisModule.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/ISegmentStore.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternSegmentStoreModule.java

index d66c5cc42fb6ba79c1e69b2fa85527ec60d112b0..004c62bc934ccfead777dcf06a0eb28f65126a58 100644 (file)
@@ -105,5 +105,29 @@ public abstract class AbstractSegmentStoreAnalysisEventBasedModule extends Abstr
         public ISegmentStore<ISegment> getSegmentStore() {
             return fSegmentStore;
         }
+
+        @Override
+        public void handleSuccess() {
+            super.handleSuccess();
+            closeSegmentStore(false);
+        }
+
+        @Override
+        public void handleFailure() {
+            super.handleFailure();
+            closeSegmentStore(true);
+        }
+
+        @Override
+        public void handleCancel() {
+            super.handleCancel();
+            closeSegmentStore(true);
+        }
+
+        private void closeSegmentStore(boolean deleteFiles) {
+            fSegmentStore.close(deleteFiles);
+        }
+
     }
+
 }
index 5426b07077ffafd05d124f4af10263202079ce97..c17c06a4122bdde0574cdc639269af4ca2a33e25 100644 (file)
@@ -105,6 +105,9 @@ public abstract class AbstractSegmentStoreAnalysisModule extends TmfAbstractAnal
      * segments are found by parsing the events of a trace, the event request
      * would be done in this method.
      *
+     * Note: After this method, the segment store should be completed, so it
+     * should also close the segment store at the end of the analysis
+     *
      * @param segmentStore
      *            The segment store to fill
      * @param monitor
index 774dac2833a1005776ccaf0538c622483062c6df..2e4be6a6594251bffd946911cbfe5bcc9b64f08e 100644 (file)
@@ -59,4 +59,17 @@ public interface ISegmentStore<E extends ISegment> extends Collection<E> {
      * with it.
      */
     void dispose();
+
+    /**
+     * Method to close off the segment store. This happens for example when we
+     * are done reading an off-line trace. Implementers can use this method to
+     * save the segment store on disk
+     *
+     * @param deleteFiles
+     *            Whether to delete any file that was created while building the
+     *            segment store
+     */
+    default void close(boolean deleteFiles) {
+
+    }
 }
index 97037ac90481f44e68757af7f361fefd73f46cbb..aac5d322c163dccb8eee646385f18956ad76cc86 100644 (file)
@@ -65,11 +65,16 @@ public class XmlPatternSegmentStoreModule extends AbstractSegmentStoreAnalysisMo
         if (trace == null) {
             /* This analysis was cancelled in the meantime */
             segmentStoreReady(false);
+            segments.close(true);
             return false;
         }
-        waitForSegmentStoreCompletion();
-        segments.addAll(getSegments());
-        return true;
+        if (waitForSegmentStoreCompletion()) {
+            segments.addAll(getSegments());
+            segments.close(false);
+            return true;
+        }
+        segments.close(true);
+        return false;
     }
 
     @Override
This page took 0.028595 seconds and 5 git commands to generate.