tmf: Consolidate all state systems in ITmfTrace
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 19 Nov 2012 20:40:48 +0000 (15:40 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 10 Dec 2012 15:36:00 +0000 (10:36 -0500)
In the initial design, a trace would have only one single
state system. ITmfTrace.getStateSystem() would do the job.

Then, the need for different state systems for different trace
types arose. Up until now, we've used a hybrid approach, where
we keep the interface method the same, but a given user/view
could access a specific state system by casting the trace
in the specific type. So far so good.

But now, we are reaching the point where we can need to define
*many* state systems for a single trace type (ie, Matthew's
CPU usage view). I think we now need to centralize all of a
trace's state systems in the ITmfTrace interface itself.

This patch changes ITmfTrace's getStateSystem() to add the
state's ID as parameter (state systems already define a unique
ID, so we can reuse that one). It also adds a listStateSystems()
method to list the current registered ones for this trace.

The implementation in TmfTrace uses a HashMap. It's very simple,
and gives a maximum amount of flexibility ; sub-classes can
decide to overwrite a superclass' state history, decide to run
them or not, etc.

Change-Id: I6c819ad8987767015543dc54b613ec3cdc6ea50d
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/8767
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesPresentationProvider.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java

index 7f412fe775df15457fab931847b83a85f82a0946..3ce5be1d82674db22584da77fde68d14309b2415 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
 
 /**
@@ -76,6 +77,8 @@ public class CtfKernelTrace extends CtfTmfTrace {
 
     @Override
     protected void buildStateSystem() throws TmfTraceException {
+        super.buildStateSystem();
+
         /* Set up the path to the history tree file we'll use */
         IResource resource = this.getResource();
         String supplDirectory = null;
@@ -90,17 +93,8 @@ public class CtfKernelTrace extends CtfTmfTrace {
         final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME);
         final IStateChangeInput htInput = new CtfKernelStateInput(this);
 
-        this.ss = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false);
-    }
-
-    @Override
-    public synchronized void dispose() {
-        /* Clean up the state system */
-        if (ss != null) {
-            ss.dispose();
-        }
-        super.dispose();
+        ITmfStateSystem ss = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false);
+        fStateSystems.put(STATE_ID, ss);
     }
 
-
 }
index cc5f51f153074ce6bc7f7342e40d1255f0addac1..1ab8fddef87fe03ced75053ccc4b09a5ceb7d6cf 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Map;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -104,7 +105,7 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
         Map<String, String> retMap = new LinkedHashMap<String, String>();
         if (event instanceof ControlFlowEvent) {
             ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();
-            ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+            ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
             int tid = entry.getThreadId();
 
             try {
index 3a04186cdfa22d6aefcb78fcae2f5fb3b50449ea..f25f82523c41181ea03f2a20c6aca85ad63075ea 100644 (file)
@@ -508,7 +508,7 @@ public class ControlFlowView extends TmfView {
             }
             if (trace instanceof CtfKernelTrace) {
                 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
-                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem();
+                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
                 if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {
                     List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD);  //$NON-NLS-1$
                     for (int currentThreadQuark : currentThreadQuarks) {
@@ -614,7 +614,7 @@ public class ControlFlowView extends TmfView {
             if (aTrace instanceof CtfKernelTrace) {
                 ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>();
                 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) aTrace;
-                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem();
+                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
                 if (!ssq.waitUntilBuilt()) {
                     return;
                 }
@@ -723,7 +723,7 @@ public class ControlFlowView extends TmfView {
     }
 
     private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, IProgressMonitor monitor) {
-        ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+        ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
         long start = ssq.getStartTime();
         long end = ssq.getCurrentEndTime() + 1;
         long resolution = Math.max(1, (end - start) / fDisplayWidth);
@@ -751,7 +751,7 @@ public class ControlFlowView extends TmfView {
         if (endTime <= startTime) {
             return null;
         }
-        ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+        ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
         List<ITimeEvent> eventList = null;
         try {
             int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);
index 3e3012bdba1844111614efe5e5ca8fb02ce99d8c..d41c7373395a1c8ea56a191ff27a0706d545a672 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -165,19 +166,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 if (status == StateValues.CPU_STATUS_IRQ) {
                     // In IRQ state get the IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
                     int cpu = entry.getId();
 
-                    ITmfStateSystem ss = entry.getTrace().getStateSystem();
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
 
                         for (int irqQuark : irqQuarks) {
                             if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) {
-                                ITmfStateInterval value = ssq.querySingleState(event.getTime(), irqQuark);
+                                ITmfStateInterval value = ss.querySingleState(event.getTime(), irqQuark);
                                 if (!value.getStateValue().isNull()) {
-                                    int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
+                                    int irq = Integer.parseInt(ss.getAttributeName(irqQuark));
                                     retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq));
                                 }
                                 break;
@@ -195,19 +195,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
                     // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
                     int cpu = entry.getId();
 
-                    ITmfStateSystem ss = entry.getTrace().getStateSystem();
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
 
                         for (int softIrqQuark : softIrqQuarks) {
                             if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) {
-                                ITmfStateInterval value = ssq.querySingleState(event.getTime(), softIrqQuark);
+                                ITmfStateInterval value = ss.querySingleState(event.getTime(), softIrqQuark);
                                 if (!value.getStateValue().isNull()) {
-                                    int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
+                                    int softIrq = Integer.parseInt(ss.getAttributeName(softIrqQuark));
                                     retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq));
                                 }
                                 break;
@@ -225,7 +224,7 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL){
                     // In running state get the current tid
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
 
                     try {
                         retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.ABSOLUTE, Resolution.NANOSEC));
index f411f3793401ddd01f993da250a1c206954f3b7f..9328860ee57bedbee3aeb33c4b8d50b6bb11b532 100644 (file)
@@ -268,7 +268,7 @@ public class ResourcesView extends TmfView {
             }
             long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
             for (TraceEntry traceEntry : fZoomEntryList) {
-                if (!traceEntry.fKernelTrace.getStateSystem().waitUntilBuilt()) {
+                if (!traceEntry.fKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID).waitUntilBuilt()) {
                     return;
                 }
                 for (ITimeGraphEntry child : traceEntry.getChildren()) {
@@ -497,7 +497,7 @@ public class ResourcesView extends TmfView {
             }
             if (aTrace instanceof CtfKernelTrace) {
                 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) aTrace;
-                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem();
+                ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
                 if (!ssq.waitUntilBuilt()) {
                     return;
                 }
@@ -547,7 +547,7 @@ public class ResourcesView extends TmfView {
                 return;
             }
             CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();
-            ITmfStateSystem ssq = ctfKernelTrace.getStateSystem();
+            ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID);
             long startTime = ssq.getStartTime();
             long endTime = ssq.getCurrentEndTime() + 1;
             long resolution = (endTime - startTime) / fDisplayWidth;
@@ -562,7 +562,7 @@ public class ResourcesView extends TmfView {
     private static List<ITimeEvent> getEventList(ResourcesEntry entry,
             long startTime, long endTime, long resolution, boolean includeNull,
             IProgressMonitor monitor) {
-        ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+        ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
         startTime = Math.max(startTime, ssq.getStartTime());
         endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);
         if (endTime <= startTime) {
index 9998a2063f529f05d4fe507a43c56ec634b00192..576934fbaaff5c478ec2b6d923a786cfc87a18d8 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.junit.After;
 import org.junit.Before;
@@ -93,7 +92,6 @@ public class CtfTmfTraceTest {
         assertEquals(1000, result.getCacheSize());
         assertEquals(0L, result.getNbEvents());
         assertEquals(0L, result.getStreamingInterval());
-        assertNull(result.getStateSystem());
         assertNull(result.getResource());
         assertEquals(1000, result.getQueueSize());
         assertNull(result.getType());
@@ -283,15 +281,6 @@ public class CtfTmfTraceTest {
         assertNotNull(result);
     }
 
-    /**
-     * Run the IStateSystemQuerier getStateSystem() method test.
-     */
-    @Test
-    public void testGetStateSystem() {
-        ITmfStateSystem result = fixture.getStateSystem();
-        assertNull(result);
-    }
-
     /**
      * Run the long getStreamingInterval() method test.
      */
index c174c0a2006f1472312f96605a92cf275fd10a2b..34e51611c7b58fa2d9c8d74ac0b5ad2832daec1b 100644 (file)
@@ -17,6 +17,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Collection;
 import java.util.Vector;
 
 import junit.framework.TestCase;
@@ -33,6 +34,8 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
@@ -170,6 +173,28 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile());
     }
 
+    // ------------------------------------------------------------------------
+    // State system and statistics methods
+    // ------------------------------------------------------------------------
+
+    public void testGetStatistics() {
+        /* There should not be any experiment-specific statistics */
+        ITmfStatistics stats = fExperiment.getStatistics();
+        assertNull(stats);
+    }
+
+    public void testGetStateSystem() {
+        /* There should not be any experiment-specific state system */
+        ITmfStateSystem ss = fExperiment.getStateSystem("something");
+        assertNull(ss);
+    }
+
+    public void testListStateSystem() {
+        Collection<String> sss = fExperiment.listStateSystems();
+        assertNotNull(sss);
+        assertEquals(0, sss.size());
+    }
+
     // ------------------------------------------------------------------------
     // seekEvent by location
     // ------------------------------------------------------------------------
index b104fddfde0c13054e1bb5e3800caa8e327bc8b1..1b957a841643692c9cb83f5daa5dccc206df80ad 100644 (file)
@@ -17,6 +17,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Collection;
 import java.util.Vector;
 
 import junit.framework.TestCase;
@@ -33,6 +34,8 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
@@ -521,6 +524,28 @@ public class TmfTraceTest extends TestCase {
         trace.dispose();
     }
 
+    // ------------------------------------------------------------------------
+    // State system and statistics methods
+    // ------------------------------------------------------------------------
+
+    public void testGetStatistics() {
+        /* Should be null in unit tests */
+        ITmfStatistics stats = fTrace.getStatistics();
+        assertNull(stats);
+    }
+
+    public void testGetStateSystem() {
+        /* There should be no state system registered so far */
+        ITmfStateSystem ss = fTrace.getStateSystem("something");
+        assertNull(ss);
+    }
+
+    public void testListStateSystem() {
+        Collection<String> sss = fTrace.listStateSystems();
+        assertNotNull(sss);
+        assertEquals(0, sss.size());
+    }
+
     // ------------------------------------------------------------------------
     // seekEvent on location (note: does not reliably set the rank)
     // ------------------------------------------------------------------------
index f1b6427a27e356611cb8afc730aca4a755bc4364..f3ce15fd65268e5f12a8c8ba06451fb30fea3181 100644 (file)
@@ -19,7 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
@@ -46,9 +45,6 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     //        Fields
     //-------------------------------------------
 
-    /** Reference to the state system assigned to this trace */
-    protected ITmfStateSystem ss = null;
-
     /* Reference to the CTF Trace */
     private CTFTrace fTrace;
 
@@ -246,14 +242,6 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         return event;
     }
 
-    /**
-     * @since 2.0
-     */
-    @Override
-    public ITmfStateSystem getStateSystem() {
-        return this.ss;
-    }
-
     /**
      * gets the CTFtrace that this is wrapping
      * @return the CTF trace
index b42a9d96fe658adee577e3e59130c0d2d8a13519..340cfdf9489dec353110ac9db7b8f1ef9705c52b 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
+import java.util.Collection;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
@@ -180,10 +182,24 @@ public interface ITmfTrace extends ITmfDataProvider {
     public ITmfStatistics getStatistics();
 
     /**
-     * @return The state system that is associated with this trace
+     * Retrieve a state system that belongs to this trace
+     *
+     * @param id
+     *            The ID of the state system to retrieve.
+     * @return The state system that is associated with this trace and ID, or
+     *         'null' if such a match doesn't exist.
+     * @since 2.0
+     */
+    public ITmfStateSystem getStateSystem(String id);
+
+    /**
+     * Return the list of existing state systems registered with this trace.
+     *
+     * @return A Collection view of the available state systems. The collection
+     *         could be empty, but should not be null.
      * @since 2.0
      */
-    public ITmfStateSystem getStateSystem();
+    public Collection<String> listStateSystems();
 
     // ------------------------------------------------------------------------
     // Trace characteristics getters
index e59637fb1fc664a5fb8cec767175b40cb0002cff..af8a94c98b3d955daaace05ebd79ee070152b617 100644 (file)
@@ -14,6 +14,9 @@
 package org.eclipse.linuxtools.tmf.core.trace;
 
 import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -102,6 +105,16 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
     // The current selected range
     private TmfTimeRange fCurrentRange = TmfTimeRange.NULL_RANGE;
 
+    /**
+     * The collection of state systems that are registered with this trace. Each
+     * sub-class can decide to add its (one or many) state system to this map
+     * during their {@link #buildStateSystem()}.
+     *
+     * @since 2.0
+     */
+    protected final Map<String, ITmfStateSystem> fStateSystems =
+            new HashMap<String, ITmfStateSystem>();
+
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
@@ -293,7 +306,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
     protected void buildStateSystem() throws TmfTraceException {
         /*
          * Nothing is done in the base implementation, please specify
-         * how/if to build a state system in derived classes.
+         * how/if to register a new state system in derived classes.
          */
         return;
     }
@@ -312,6 +325,12 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
         if (fStatistics != null) {
             fStatistics.dispose();
         }
+
+        /* Clean up the state systems */
+        for (ITmfStateSystem ss : fStateSystems.values()) {
+            ss.dispose();
+        }
+
         super.dispose();
     }
 
@@ -385,12 +404,16 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
      * @since 2.0
      */
     @Override
-    public ITmfStateSystem getStateSystem() {
-        /*
-         * By default, no state system is used. Sub-classes can specify their
-         * own behaviour.
-         */
-        return null;
+    public final ITmfStateSystem getStateSystem(String id) {
+        return fStateSystems.get(id);
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final Collection<String> listStateSystems() {
+        return fStateSystems.keySet();
     }
 
     // ------------------------------------------------------------------------
This page took 0.036188 seconds and 5 git commands to generate.