tmf: Tweak ITmfStateSystemAnalysisModule
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 6 Jan 2014 20:12:42 +0000 (15:12 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 7 Jan 2014 21:25:57 +0000 (16:25 -0500)
- 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 <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/20247
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfAnalysisModuleWithStateSystems.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystemAnalysisModule.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemExplorer.java

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 (file)
index 0000000..0830d97
--- /dev/null
@@ -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<ITmfStateSystem> 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 (file)
index dfa2cbc..0000000
+++ /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<String, ITmfStateSystem> getStateSystems();
-
-}
index 6f4b11fe52d14c8415d17000cbcbc419dcdc3740..a5692ac4fddc750b603d00abd1fa9d7889fa7a38 100644 (file)
@@ -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<String, ITmfStateSystem> getStateSystems() {
-        Map<String, ITmfStateSystem> map = new HashMap<>();
-        map.put(getId(), fStateSystem);
-        return map;
+    @NonNull
+    public Iterable<ITmfStateSystem> getStateSystems() {
+        return Collections.singleton(fStateSystem);
     }
 }
index 308474630ed7341612a3f49e473e9d28622f8f70..1a13b316c2d845b931172f7ac620120a0f5c0d8e 100644 (file)
@@ -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);
index b10a235d2264f7b3b4ff8d7a0c9f8d1fe1dbc523..3dda6779599c2790110f8d5e85ac0e46672c70c7 100644 (file)
@@ -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<String, ITmfStateSystemAnalysisModule> modules = currentTrace.getAnalysisModules(ITmfStateSystemAnalysisModule.class);
+            Map<String, ITmfAnalysisModuleWithStateSystems> modules = currentTrace.getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class);
             final Map<String, ITmfStateSystem> sss = new HashMap<>();
             final Map<String, List<ITmfStateInterval>> fullStates =
                     new LinkedHashMap<>();
-            for (Entry<String, ITmfStateSystemAnalysisModule> entry : modules.entrySet()) {
+            for (Entry<String, ITmfAnalysisModuleWithStateSystems> 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<String, ITmfStateSystem> 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<String, ITmfStateSystemAnalysisModule> modules = traces[traceNb].getAnalysisModules(ITmfStateSystemAnalysisModule.class);
+            Map<String, ITmfAnalysisModuleWithStateSystems> modules = traces[traceNb].getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class);
 
             /* For each state system associated with this trace... */
             int ssNb = 0;
-            for (Entry<String, ITmfStateSystemAnalysisModule> module : modules.entrySet()) {
+            for (Entry<String, ITmfAnalysisModuleWithStateSystems> 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<String, ITmfStateSystem> 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) {
This page took 0.031621 seconds and 5 git commands to generate.