tmf : Make waitForInitialization() return a boolean
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / statistics / TmfStatisticsModule.java
index 746a892da3832c27b436b1862e3a457c7c2362f6..5755f15082a4676e6909030b9ab62c96b57c520d 100644 (file)
@@ -40,6 +40,7 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
 
     /** The trace's statistics */
     private ITmfStatistics fStatistics = null;
+    private boolean fInitializationSucceeded;
 
     private final TmfStateSystemAnalysisModule totalsModule = new TmfStatisticsTotalsModule();
     private final TmfStateSystemAnalysisModule eventTypesModule = new TmfStatisticsEventTypesModule();
@@ -65,11 +66,16 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
 
     /**
      * Wait until the analyses/state systems underneath are ready to be queried.
+     * @since 2.0
      */
-    public void waitForInitialization() {
+    @Override
+    public boolean waitForInitialization() {
         try {
             fInitialized.await();
-        } catch (InterruptedException e) {}
+        } catch (InterruptedException e) {
+            return false;
+        }
+        return fInitializationSucceeded;
     }
 
     // ------------------------------------------------------------------------
@@ -112,6 +118,7 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
         ITmfTrace trace = getTrace();
         if (trace == null) {
             /* This analysis was cancelled in the meantime */
+            fInitializationSucceeded = false;
             fInitialized.countDown();
             return false;
         }
@@ -120,26 +127,32 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
         IStatus status2 = eventTypesModule.schedule();
         if (!(status1.isOK() && status2.isOK())) {
             cancelSubAnalyses();
+            fInitializationSucceeded = false;
             fInitialized.countDown();
             return false;
         }
 
         /* Wait until the two modules are initialized */
-        totalsModule.waitForInitialization();
-        eventTypesModule.waitForInitialization();
+        if (!totalsModule.waitForInitialization() || !eventTypesModule.waitForInitialization()) {
+            fInitializationSucceeded = false;
+            fInitialized.countDown();
+            return false;
+        }
 
         ITmfStateSystem totalsSS = totalsModule.getStateSystem();
         ITmfStateSystem eventTypesSS = eventTypesModule.getStateSystem();
 
         if (totalsSS == null || eventTypesSS == null) {
             /* This analysis was cancelled in the meantime */
+            fInitializationSucceeded = false;
             fInitialized.countDown();
-            return false;
+            throw new IllegalStateException("TmfStatisticsModule : Sub-modules initialization succeeded but there is a null state system."); //$NON-NLS-1$
         }
 
         fStatistics = new TmfStateStatistics(totalsSS, eventTypesSS);
 
         /* fStatistics is now set, consider this module initialized */
+        fInitializationSucceeded = true;
         fInitialized.countDown();
 
         /*
@@ -189,10 +202,16 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
     }
 
     @Override
-    public Iterable<ITmfStateSystem> getStateSystems() {
-        List<ITmfStateSystem> list = new LinkedList<>();
-        list.add(totalsModule.getStateSystem());
-        list.add(eventTypesModule.getStateSystem());
+    public @NonNull Iterable<@NonNull ITmfStateSystem> getStateSystems() {
+        List<@NonNull ITmfStateSystem> list = new LinkedList<>();
+        ITmfStateSystem totalsStateSystem = totalsModule.getStateSystem();
+        if (totalsStateSystem != null) {
+            list.add(totalsStateSystem);
+        }
+        ITmfStateSystem eventTypesStateSystem = eventTypesModule.getStateSystem();
+        if (eventTypesStateSystem != null) {
+            list.add(eventTypesStateSystem);
+        }
         return list;
     }
 }
This page took 0.025919 seconds and 5 git commands to generate.