tmf: Add method to replace a statesystem's ongoing state
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 28 Feb 2013 23:01:27 +0000 (18:01 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 4 Mar 2013 16:10:16 +0000 (11:10 -0500)
Replace the vestigial TransientState.changeOngoingStateInfo()
(which was never used so far) with a similar method that can
generate a current state from an array of intervals.

For now, this this potentially dangerous method is only exposed
to classes extending StateSystem.

This will be useful for the partial history, but also for anybody
wanting to do funky stuff with the state system.

Change-Id: Ieebe6dfceb57c1437d81fd9a97c6be10040afeb4
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/10760
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>

org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java

index cd82f921198913a07891bc704d6c6458d1203808..03c60a064f00e0eb1692fdd0d553952e2751e613 100644 (file)
@@ -475,6 +475,18 @@ public class StateSystem implements ITmfStateSystemBuilder {
         transState.changeOngoingStateValue(attributeQuark, newValue);
     }
 
+    /**
+     * Modify the whole "ongoing state" (state values + start times). This can
+     * be used when "seeking" a state system to a different point in the trace
+     * (and restoring the known stateInfo at this location). Use with care!
+     *
+     * @param newStateIntervals
+     *            The new List of state values to use as ongoing state info
+     */
+    protected void replaceOngoingState(List<ITmfStateInterval> newStateIntervals) {
+        transState.replaceOngoingState(newStateIntervals);
+   }
+
     //--------------------------------------------------------------------------
     //        Regular query methods (sent to the back-end)
     //--------------------------------------------------------------------------
index 1fae851b79620611a11ad2f56d6e8c8b38fc4d94..bc8cad3e4d19a16fb2fd467db1278c0126616be9 100644 (file)
@@ -46,9 +46,9 @@ class TransientState {
     private boolean isActive;
     private long latestTime;
 
-    private ArrayList<ITmfStateValue> ongoingStateInfo;
-    private final ArrayList<Long> ongoingStateStartTimes;
-    private final ArrayList<Byte> stateValueTypes;
+    private List<ITmfStateValue> ongoingStateInfo;
+    private List<Long> ongoingStateStartTimes;
+    private List<Byte> stateValueTypes;
 
     TransientState(IStateHistoryBackend backend) {
         this.backend = backend;
@@ -104,19 +104,27 @@ class TransientState {
     }
 
     /**
-     * Batch method of changeOngoingStateValue(), updates the complete
-     * ongoingStateInfo in one go. BE VERY CAREFUL WITH THIS! Especially with
-     * the sizes of both arrays.
+     * More advanced version of {@link #changeOngoingStateValue}. Replaces the
+     * complete {@link #ongoingStateInfo} in one go, and updates the
+     * {@link #ongoingStateStartTimes} and {@link #stateValuesTypes}
+     * accordingly. BE VERY CAREFUL WITH THIS!
      *
-     * Note that the new ongoingStateInfo will be a shallow copy of
-     * newStateInfo, so that last one must be already instantiated and all.
-     *
-     * @param newStateInfo
-     *            The List of StateValues to replace the old ongoingStateInfo
-     *            one.
+     * @param newStateIntervals
+     *            The List of intervals that will represent the new
+     *            "ongoing state". Their end times don't matter, we will only
+     *            check their value and start times.
      */
-    void changeOngoingStateInfo(ArrayList<ITmfStateValue> newStateInfo) {
-        this.ongoingStateInfo = newStateInfo;
+    synchronized void replaceOngoingState(List<ITmfStateInterval> newStateIntervals) {
+        int size = newStateIntervals.size();
+        ongoingStateInfo = new ArrayList<ITmfStateValue>(size);
+        ongoingStateStartTimes = new ArrayList<Long>(size);
+        stateValueTypes = new ArrayList<Byte>(size);
+
+        for (ITmfStateInterval interval : newStateIntervals) {
+            ongoingStateInfo.add(interval.getStateValue());
+            ongoingStateStartTimes.add(interval.getStartTime());
+            stateValueTypes.add(interval.getStateValue().getType());
+        }
     }
 
     /**
This page took 0.0409310000000001 seconds and 5 git commands to generate.