From: Jean-Christian Kouame Date: Wed, 24 Feb 2016 18:23:08 +0000 (-0500) Subject: tmf : Make waitForInitialization() return a boolean X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=c81ffdf267abf79b180902bcba20e3b76d3a39ef;p=deliverable%2Ftracecompass.git tmf : Make waitForInitialization() return a boolean 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 Reviewed-on: https://git.eclipse.org/r/67285 Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java b/lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java index 6e932a08bf..425124b0be 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java @@ -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) { diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java index 60a866f550..8a849eafef 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java @@ -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; diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java index c39fe80775..c6f46ae00d 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java @@ -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(); diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java index 141293a7bc..48b4a0be86 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java @@ -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()); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java index 56dc6ce7e4..1ccf3445c9 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java @@ -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()); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java index e831f5cf4c..e28eba90b9 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java @@ -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(); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java index da07ddf71b..b53cfcd7ae 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java @@ -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(); /* diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsModule.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsModule.java index d1281311c6..5755f15082 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsModule.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfStatisticsModule.java @@ -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(); /* diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/StatisticsUpdateJob.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/StatisticsUpdateJob.java index 1b8e9cbdff..31c6480ef9 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/StatisticsUpdateJob.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/StatisticsUpdateJob.java @@ -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 */ diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java index 05e9fcfb86..cbf738f593 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java @@ -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; } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/statesystem/TmfStateSystemViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/statesystem/TmfStateSystemViewer.java index e822c93959..067cfb7aa0 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/statesystem/TmfStateSystemViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/statesystem/TmfStateSystemViewer.java @@ -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)); }