From: Alexandre Montplaisir Date: Mon, 6 Jan 2014 20:12:42 +0000 (-0500) Subject: tmf: Tweak ITmfStateSystemAnalysisModule X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=5237a9316a05ddb77ce3ecb1a8e84d814b2461aa;hp=83842d7dc2b0b37abe5ed5a098997d3cfd6d171e;p=deliverable%2Ftracecompass.git tmf: Tweak ITmfStateSystemAnalysisModule - Decouple it from TmfStateSystemAnalysisModule, rename it to ITmfAnalysisModuleWithStateSystems. An analysis module could expose state systems independently of using the abstract class or not. - Change the Map return to separate methods. I'm not very happy about getStateSystemId(), but the State System Explorer currently needs it. Ideally, the ID could be stored in the state system itself, so that this method would not be needed. Change-Id: I1fcf20384c00b47578309451691f59fd0f438053 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/20247 Tested-by: Hudson CI Reviewed-by: Genevieve Bastien IP-Clean: Genevieve Bastien Tested-by: Genevieve Bastien --- diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java new file mode 100644 index 0000000000..0830d97dca --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2013 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.statesystem; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * Interface for analysis modules providing state systems. + * + * @author Geneviève Bastien + * @since 3.0 + */ +@NonNullByDefault +public interface ITmfAnalysisModuleWithStateSystems { + + /** + * Return a specific state system provided by this analysis. + * + * @param id + * The ID of the state system + * @return The state system corresponding to the given ID, null if there is + * no match. + */ + @Nullable + ITmfStateSystem getStateSystem(String id); + + /** + * FIXME The ID's should be saved in the state system themselves + * (ITmfStateSystem.getId()), so this will eventually not be needed. + * + * Return the ID of a given state system. + * + * @param ss + * The state system for which you want the ID, null if there is + * no match. + * @return The corresponding state system + */ + @Nullable + String getStateSystemId(ITmfStateSystem ss); + + /** + * Return all the state systems provided by this analysis module, in + * Iterable format. + * + * @return The state systems + */ + Iterable getStateSystems(); + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystemAnalysisModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystemAnalysisModule.java deleted file mode 100644 index dfa2cbc48d..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystemAnalysisModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Geneviève Bastien - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.statesystem; - -import java.util.Map; - -/** - * Interface for analysis modules providing state systems - * - * @author Geneviève Bastien - * @since 3.0 - */ -public interface ITmfStateSystemAnalysisModule { - - /** - * Return a map of all state systems this analysis is owner of. The key is - * the ID of the state system and the value is the state system itself. - * - * @return A map of state sytems - */ - Map getStateSystems(); - -} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java index 6f4b11fe52..a5692ac4fd 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java @@ -13,8 +13,7 @@ package org.eclipse.linuxtools.tmf.core.statesystem; import java.io.File; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.annotation.NonNull; @@ -35,11 +34,12 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; * @since 3.0 */ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisModule - implements ITmfStateSystemAnalysisModule { + implements ITmfAnalysisModuleWithStateSystems { - private ITmfStateSystem fStateSystem = null; private static final String EXTENSION = ".ht"; //$NON-NLS-1$ + private ITmfStateSystem fStateSystem = null; + /** * State system backend types * @@ -136,10 +136,27 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo fStateSystem.dispose(); } + // ------------------------------------------------------------------------ + // ITmfAnalysisModuleWithStateSystems + // ------------------------------------------------------------------------ + + @Override + public ITmfStateSystem getStateSystem(@NonNull String id) { + if (id.equals(getId())) { + return fStateSystem; + } + return null; + } + + @Override + public String getStateSystemId(@NonNull ITmfStateSystem ss) { + return getId(); + } + + @SuppressWarnings("null") @Override - public Map getStateSystems() { - Map map = new HashMap<>(); - map.put(getId(), fStateSystem); - return map; + @NonNull + public Iterable getStateSystems() { + return Collections.singleton(fStateSystem); } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index 308474630e..1a13b316c2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -26,7 +26,7 @@ import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; @@ -209,7 +209,7 @@ public interface ITmfTrace extends ITmfEventProvider { * @return The map of state systems * @since 2.0 * @deprecated State systems now should be provided by analysis and use - * {@link ITmfStateSystemAnalysisModule} and retrieve the modules + * {@link ITmfAnalysisModuleWithStateSystems} and retrieve the modules * with {@link TmfTrace#getAnalysisModules(Class)} with Class * being TmfStateSystemAnalysisModule.class */ @@ -229,7 +229,7 @@ public interface ITmfTrace extends ITmfEventProvider { * The already-built state system * @since 2.0 * @deprecated State systems now should be provided by analysis and use - * {@link ITmfStateSystemAnalysisModule} + * {@link ITmfAnalysisModuleWithStateSystems} */ @Deprecated void registerStateSystem(String id, ITmfStateSystem ss); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java index b10a235d22..3dda677959 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java @@ -40,7 +40,7 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; @@ -172,40 +172,41 @@ public class TmfStateSystemExplorer extends TmfView { * We will first do all the queries for this trace, then update that * sub-tree in the UI thread. */ - Map modules = currentTrace.getAnalysisModules(ITmfStateSystemAnalysisModule.class); + Map modules = currentTrace.getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class); final Map sss = new HashMap<>(); final Map> fullStates = new LinkedHashMap<>(); - for (Entry entry : modules.entrySet()) { + for (Entry entry : modules.entrySet()) { /* * FIXME: For now, this view is a way to execute and display * state system. But with phase 2 of analysis API, we won't want * to run state system that have not been requested. We will * leave the title, but there won't be anything underneath. */ - ITmfStateSystemAnalysisModule module = entry.getValue(); + ITmfAnalysisModuleWithStateSystems module = entry.getValue(); if (module instanceof IAnalysisModule) { IAnalysisModule mod = (IAnalysisModule) module; mod.schedule(); mod.waitForCompletion(new NullProgressMonitor()); } - for (Entry ssEntry : module.getStateSystems().entrySet()) { - String ssName = ssEntry.getKey(); - ITmfStateSystem ss = ssEntry.getValue(); + for (ITmfStateSystem ss : module.getStateSystems()) { + if (ss == null) { + continue; + } + String ssName = module.getStateSystemId(ss); sss.put(ssName, ss); - if (ss != null) { - if (ts == -1 || ts < ss.getStartTime() || ts > ss.getCurrentEndTime()) { - ts = ss.getStartTime(); - } - try { - fullStates.put(ssName, ss.queryFullState(ts)); - } catch (TimeRangeException e) { - /* We already checked the limits ourselves */ - throw new IllegalStateException(); - } catch (StateSystemDisposedException e) { - /* Probably shutting down, cancel and return */ - return; - } + + if (ts == -1 || ts < ss.getStartTime() || ts > ss.getCurrentEndTime()) { + ts = ss.getStartTime(); + } + try { + fullStates.put(ssName, ss.queryFullState(ts)); + } catch (TimeRangeException e) { + /* We already checked the limits ourselves */ + throw new IllegalStateException(); + } catch (StateSystemDisposedException e) { + /* Probably shutting down, cancel and return */ + return; } } } @@ -290,18 +291,17 @@ public class TmfStateSystemExplorer extends TmfView { /* For each trace... */ for (int traceNb = 0; traceNb < traces.length; traceNb++) { - Map modules = traces[traceNb].getAnalysisModules(ITmfStateSystemAnalysisModule.class); + Map modules = traces[traceNb].getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class); /* For each state system associated with this trace... */ int ssNb = 0; - for (Entry module : modules.entrySet()) { + for (Entry module : modules.entrySet()) { /* * Even though we only use the value, it just feels safer to * iterate the same way as before to keep the order the same. */ - for (Entry ssEntry : module.getValue().getStateSystems().entrySet()) { - final ITmfStateSystem ss = ssEntry.getValue(); + for (final ITmfStateSystem ss : module.getValue().getStateSystems()) { final int traceNb1 = traceNb; final int ssNb1 = ssNb; if (ss != null) {