tmf : Make waitForInitialization() return a boolean
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Wed, 24 Feb 2016 18:23:08 +0000 (13:23 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 2 Mar 2016 21:51:35 +0000 (16:51 -0500)
waitForInitialization() should return a boolean that will indicate
wether the initialization went well or not. If true, there should be
state systems available.

Change-Id: Id9d053322ff86c93dedb8c0897924fa31720ebfe
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/67285
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsModule.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/StatisticsUpdateJob.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/statesystem/TmfStateSystemViewer.java

index 6e932a08bf8ff6f5482a5bf402116dc8d367cf7d..425124b0be11f1042259278f171559a58fdb6f9c 100644 (file)
@@ -82,7 +82,9 @@ public class MemoryUsageViewer extends TmfCommonXLineChartViewer {
             if (getTrace() == null || fModule == null) {
                 return;
             }
-            fModule.waitForInitialization();
+            if (!fModule.waitForInitialization()) {
+                return;
+            }
             ITmfStateSystem ss = fModule.getStateSystem();
             /* Don't wait for the module completion, when it's ready, we'll know */
             if (ss == null) {
index 60a866f550fd57ff4fd8f55cb14394d6ea6eb183..8a849eafefbc21f4554bd5615cb37189c1a689e4 100644 (file)
@@ -43,7 +43,6 @@ import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemCont
 import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXLineChartViewer;
@@ -362,8 +361,8 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
             if (!status.isOK()) {
                 return;
             }
-            if (module instanceof TmfStateSystemAnalysisModule) {
-                ((TmfStateSystemAnalysisModule) module).waitForInitialization();
+            if (!module.waitForInitialization()) {
+                return;
             }
             for (ITmfStateSystem ssq : module.getStateSystems()) {
                 ss = ssq;
index c39fe80775f0ed035c2aaf824e330cd2fdf5691d..c6f46ae00d82514e84442eb31e5a0fadf4ab148f 100644 (file)
@@ -51,7 +51,6 @@ import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
@@ -275,8 +274,8 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
             if (!status.isOK()) {
                 return;
             }
-            if (module instanceof TmfStateSystemAnalysisModule) {
-                ((TmfStateSystemAnalysisModule) module).waitForInitialization();
+            if (!module.waitForInitialization()) {
+                return;
             }
             for (ITmfStateSystem ssq : module.getStateSystems()) {
                 ssq.waitUntilBuilt();
index 141293a7bc535fd89a4989e6149b6ed14fb22790..48b4a0be866086dbb48a171dcf7e4329f6217cd7 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.tmf.core.tests.statesystem;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.concurrent.TimeUnit;
@@ -106,7 +107,7 @@ public class ExperimentStateSystemModuleTest {
     }
 
     /**
-     * Make sure that the state system is initialized after calling 
+     * Make sure that the state system is initialized after calling
      * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
      */
     @Test
@@ -114,7 +115,7 @@ public class ExperimentStateSystemModuleTest {
         assertNull(fModule.getStateSystem());
         fModule.schedule();
 
-        fModule.waitForInitialization();
+        assertTrue("Initialization succeeded", fModule.waitForInitialization());
         assertNotNull(fModule.getStateSystem());
     }
 
index 56dc6ce7e488eafb166e5089cd296f7f46261d83..1ccf3445c9f3df1c186b2098ca108f7bd63f872e 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.tmf.core.tests.statesystem;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.Map;
@@ -86,7 +87,7 @@ public class StateSystemAnalysisModuleTest {
     }
 
     /**
-     * Make sure that the state system is initialized after calling 
+     * Make sure that the state system is initialized after calling
      * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
      */
     @Test
@@ -94,7 +95,7 @@ public class StateSystemAnalysisModuleTest {
         assertNull(module.getStateSystem());
         module.schedule();
 
-        module.waitForInitialization();
+        assertTrue("Initialization succeeded", module.waitForInitialization());
         assertNotNull(module.getStateSystem());
     }
 
index e831f5cf4cd988c69d3627b61e47e555551ecc8e..e28eba90b9c303e2654458392425950128b20629 100644 (file)
@@ -43,10 +43,15 @@ public interface ITmfAnalysisModuleWithStateSystems extends IAnalysisModule {
 
     /**
      * Block the calling thread until the analysis module has been initialized.
-     * After this method returns, {@link #getStateSystem()} should not contain
-     * any null elements
+     * If the initialization succeeded, {@link #getStateSystems()} should return
+     * all state systems of this analysis and calling
+     * {@link #getStateSystem(String)} should not return a null value. If it
+     * returns false, it is not safe to assume the state systems will be
+     * present.
+     *
+     * @return True whether the initialization succeeded, false otherwise
      *
      * @since 2.0
      */
-    void waitForInitialization();
+    boolean waitForInitialization();
 }
index da07ddf71b90f7d806e8064b6ffa5d39f66401db..b53cfcd7ae493fed25e8c282fb423ecb9a1025d2 100644 (file)
@@ -77,6 +77,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
     @Nullable private TmfTimeRange fTimeRange = null;
 
     private int fNbRead = 0;
+    private boolean fInitializationSucceeded;
 
     /**
      * State system backend types
@@ -105,7 +106,8 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      *            The trace for which you want the state system
      * @param moduleId
      *            The ID of the state system analysis module
-     * @return The state system, or null if there was no match
+     * @return The state system, or null if there was no match or the module was
+     *         not initialized correctly
      */
     public static @Nullable ITmfStateSystem getStateSystem(ITmfTrace trace, String moduleId) {
         TmfStateSystemAnalysisModule module =
@@ -117,8 +119,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             }
             IStatus status = module.schedule();
             if (status.isOK()) {
-                module.waitForInitialization();
-                return module.getStateSystem();
+                return module.waitForInitialization() ? module.getStateSystem() : null;
             }
         }
         return null;
@@ -162,11 +163,17 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         return fStateSystem;
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public void waitForInitialization() {
+    public boolean waitForInitialization() {
         try {
             fInitialized.await();
-        } catch (InterruptedException e) {}
+        } catch (InterruptedException e) {
+            return false;
+        }
+        return fInitializationSucceeded;
     }
 
     // ------------------------------------------------------------------------
@@ -199,6 +206,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             ITmfTrace trace = getTrace();
             if (trace == null) {
                 // Analysis was cancelled in the meantime
+                fInitializationSucceeded = false;
                 fInitialized.countDown();
                 return false;
             }
@@ -229,6 +237,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
                 break;
             }
         } catch (TmfTraceException e) {
+            fInitializationSucceeded = false;
             fInitialized.countDown();
             return false;
         }
@@ -274,6 +283,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
                         id, htFile, version);
                 fHtBackend = backend;
                 fStateSystem = StateSystemFactory.newStateSystem(backend, false);
+                fInitializationSucceeded = true;
                 fInitialized.countDown();
                 return;
             } catch (IOException e) {
@@ -439,6 +449,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
          * The state system object is now created, we can consider this module
          * "initialized" (components can retrieve it and start doing queries).
          */
+        fInitializationSucceeded = true;
         fInitialized.countDown();
 
         /*
index d1281311c63254517038eb8df67510a086a8dada..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,12 +66,16 @@ public class TmfStatisticsModule extends TmfAbstractAnalysisModule
 
     /**
      * Wait until the analyses/state systems underneath are ready to be queried.
+     * @since 2.0
      */
     @Override
-    public void waitForInitialization() {
+    public boolean waitForInitialization() {
         try {
             fInitialized.await();
-        } catch (InterruptedException e) {}
+        } catch (InterruptedException e) {
+            return false;
+        }
+        return fInitializationSucceeded;
     }
 
     // ------------------------------------------------------------------------
@@ -113,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;
         }
@@ -121,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();
 
         /*
index 1b8e9cbdff2354f4d9173fc4e8d2b5e78846c31d..31c6480ef925ecd2f1b4fb7792c8c62eeedb2055 100644 (file)
@@ -77,7 +77,9 @@ class StatisticsUpdateJob extends Job {
     protected IStatus run(IProgressMonitor monitor) {
 
         /* Wait until the analysis is ready to be queried */
-        fStatsMod.waitForInitialization();
+        if (!fStatsMod.waitForInitialization()) {
+            return Status.CANCEL_STATUS;
+        }
         ITmfStatistics stats = fStatsMod.getStatistics();
         if (stats == null) {
             /* It should have worked, but didn't */
index 05e9fcfb8645fb3d1ad2a71ef61a591a54771eca..cbf738f5931b23d0933224c33a41871b2ad2ae03 100644 (file)
@@ -935,7 +935,10 @@ public class CallStackView extends AbstractTimeGraphView {
         AbstractCallStackAnalysis module = it.next();
         /* This analysis is not automatic, we need to schedule it on-demand */
         module.schedule();
-        module.waitForInitialization();
+        if (!module.waitForInitialization()) {
+            /* The initialization did not succeed */
+            return null;
+        }
         return module;
     }
 
index e822c93959b750c27b1e22c4126d21e212207fa5..067cfb7aa07fb99a3159ed0a5279c7d12cc43e3b 100644 (file)
@@ -211,7 +211,9 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
         for (ITmfAnalysisModuleWithStateSystems module : modules) {
             /* Just schedule the module, the data will be filled when available */
             module.schedule();
-            module.waitForInitialization();
+            if (!module.waitForInitialization()) {
+                continue;
+            }
             for (ITmfStateSystem ss : module.getStateSystems()) {
                 traceEntry.addChild(new StateSystemEntry(ss));
             }
This page took 0.032251 seconds and 5 git commands to generate.