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) {
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;
if (!status.isOK()) {
return;
}
- if (module instanceof TmfStateSystemAnalysisModule) {
- ((TmfStateSystemAnalysisModule) module).waitForInitialization();
+ if (!module.waitForInitialization()) {
+ return;
}
for (ITmfStateSystem ssq : module.getStateSystems()) {
ss = ssq;
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;
if (!status.isOK()) {
return;
}
- if (module instanceof TmfStateSystemAnalysisModule) {
- ((TmfStateSystemAnalysisModule) module).waitForInitialization();
+ if (!module.waitForInitialization()) {
+ return;
}
for (ITmfStateSystem ssq : module.getStateSystems()) {
ssq.waitUntilBuilt();
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;
}
/**
- * Make sure that the state system is initialized after calling
+ * Make sure that the state system is initialized after calling
* {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
*/
@Test
assertNull(fModule.getStateSystem());
fModule.schedule();
- fModule.waitForInitialization();
+ assertTrue("Initialization succeeded", fModule.waitForInitialization());
assertNotNull(fModule.getStateSystem());
}
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;
}
/**
- * Make sure that the state system is initialized after calling
+ * Make sure that the state system is initialized after calling
* {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
*/
@Test
assertNull(module.getStateSystem());
module.schedule();
- module.waitForInitialization();
+ assertTrue("Initialization succeeded", module.waitForInitialization());
assertNotNull(module.getStateSystem());
}
/**
* 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();
}
@Nullable private TmfTimeRange fTimeRange = null;
private int fNbRead = 0;
+ private boolean fInitializationSucceeded;
/**
* State system backend types
* 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 =
}
IStatus status = module.schedule();
if (status.isOK()) {
- module.waitForInitialization();
- return module.getStateSystem();
+ return module.waitForInitialization() ? module.getStateSystem() : null;
}
}
return null;
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;
}
// ------------------------------------------------------------------------
ITmfTrace trace = getTrace();
if (trace == null) {
// Analysis was cancelled in the meantime
+ fInitializationSucceeded = false;
fInitialized.countDown();
return false;
}
break;
}
} catch (TmfTraceException e) {
+ fInitializationSucceeded = false;
fInitialized.countDown();
return false;
}
id, htFile, version);
fHtBackend = backend;
fStateSystem = StateSystemFactory.newStateSystem(backend, false);
+ fInitializationSucceeded = true;
fInitialized.countDown();
return;
} catch (IOException e) {
* 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();
/*
/** The trace's statistics */
private ITmfStatistics fStatistics = null;
+ private boolean fInitializationSucceeded;
private final TmfStateSystemAnalysisModule totalsModule = new TmfStatisticsTotalsModule();
private final TmfStateSystemAnalysisModule eventTypesModule = new TmfStatisticsEventTypesModule();
/**
* 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;
}
// ------------------------------------------------------------------------
ITmfTrace trace = getTrace();
if (trace == null) {
/* This analysis was cancelled in the meantime */
+ fInitializationSucceeded = false;
fInitialized.countDown();
return false;
}
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();
/*
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 */
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;
}
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));
}