ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / statesystem / backends / partial / PartialHistoryBackend.java
index 34e6129a0d2fa4eef91114f128483916e86a2269..f225edeb528b892a1ba64e326ac69671b59888de 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
  * 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
@@ -19,20 +19,21 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.concurrent.CountDownLatch;
 
-import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
+import org.eclipse.linuxtools.statesystem.core.backend.IStateHistoryBackend;
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.statesystem.core.interval.TmfStateInterval;
+import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
-import org.eclipse.linuxtools.tmf.core.interval.TmfStateInterval;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.statesystem.AbstractStateChangeInput;
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
-import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -59,23 +60,22 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
      * A partial history needs the state input plugin to re-generate state
      * between checkpoints.
      */
-    private final IStateChangeInput partialInput;
+    private final @NonNull ITmfStateProvider partialInput;
 
     /**
      * Fake state system that is used for partially rebuilding the states (when
      * going from a checkpoint to a target query timestamp).
      */
-    private final PartialStateSystem partialSS;
+    private final @NonNull PartialStateSystem partialSS;
 
     /** Reference to the "real" state history that is used for storage */
-    private final IStateHistoryBackend innerHistory;
+    private final @NonNull IStateHistoryBackend innerHistory;
 
     /** Checkpoints map, <Timestamp, Rank in the trace> */
-    private final TreeMap<Long, Long> checkpoints =
-            new TreeMap<Long, Long>();
+    private final @NonNull TreeMap<Long, Long> checkpoints = new TreeMap<>();
 
     /** Latch tracking if the initial checkpoint registration is done */
-    private final CountDownLatch checkpointsReady = new CountDownLatch(1);
+    private final @NonNull CountDownLatch checkpointsReady = new CountDownLatch(1);
 
     private final long granularity;
 
@@ -98,14 +98,12 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
      *            Configuration parameter indicating how many trace events there
      *            should be between each checkpoint
      */
-    public PartialHistoryBackend(IStateChangeInput partialInput, PartialStateSystem pss,
+    public PartialHistoryBackend(ITmfStateProvider partialInput, PartialStateSystem pss,
             IStateHistoryBackend realBackend, long granularity) {
-        if (granularity <= 0 || partialInput == null || pss == null) {
+        if (granularity <= 0 || partialInput == null || pss == null ||
+                partialInput.getAssignedStateSystem() != pss) {
             throw new IllegalArgumentException();
         }
-        if (partialInput.getAssignedStateSystem() != pss) {
-            throw new RuntimeException();
-        }
 
         final long startTime = realBackend.getStartTime();
 
@@ -186,6 +184,8 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
 
     @Override
     public void dispose() {
+        partialInput.dispose();
+        partialSS.dispose();
         innerHistory.dispose();
     }
 
@@ -218,8 +218,8 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
                  * caused by the event(s) happening exactly at 'checkpointTime',
                  * if any. We must not include those events in the query.
                  */
-                new TmfTimestamp(checkpointTime + 1, -9),
-                new TmfTimestamp(t, -9));
+                new TmfTimestamp(checkpointTime + 1, ITmfTimestamp.NANOSECOND_SCALE),
+                new TmfTimestamp(t, ITmfTimestamp.NANOSECOND_SCALE));
         ITmfEventRequest request = new PartialStateSystemRequest(partialInput, range);
         partialInput.getTrace().sendRequest(request);
 
@@ -238,8 +238,8 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
             for (int i = 0; i < currentStateInfo.size(); i++) {
                 long start = 0;
                 ITmfStateValue val = null;
-                start = partialSS.getOngoingStartTime(i);
-                val = partialSS.queryOngoingState(i);
+                start = ((ITmfStateSystem) partialSS).getOngoingStartTime(i);
+                val = ((ITmfStateSystem) partialSS).queryOngoingState(i);
 
                 ITmfStateInterval interval = new TmfStateInterval(start, t, i, val);
                 currentStateInfo.set(i, interval);
@@ -284,25 +284,22 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
     // ------------------------------------------------------------------------
 
     private class CheckpointsRequest extends TmfEventRequest {
-
-        /** The amount of events queried at a time through the requests */
-        private final static int chunkSize = 50000;
-
         private final ITmfTrace trace;
         private final Map<Long, Long> checkpts;
         private long eventCount;
         private long lastCheckpointAt;
 
-        public CheckpointsRequest(IStateChangeInput input, Map<Long, Long> checkpoints) {
+        public CheckpointsRequest(ITmfStateProvider input, Map<Long, Long> checkpoints) {
             super(input.getExpectedEventType(),
                     TmfTimeRange.ETERNITY,
-                    TmfDataRequest.ALL_DATA,
-                    chunkSize,
-                    ITmfDataRequest.ExecutionType.BACKGROUND);
+                    0,
+                    ITmfEventRequest.ALL_DATA,
+                    ITmfEventRequest.ExecutionType.FOREGROUND);
             checkpoints.clear();
             this.trace = input.getTrace();
             this.checkpts = checkpoints;
-            eventCount = lastCheckpointAt = 0;
+            eventCount = 0;
+            lastCheckpointAt = 0;
 
             /* Insert a checkpoint at the start of the trace */
             checkpoints.put(input.getStartTime(), 0L);
@@ -311,7 +308,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
         @Override
         public void handleData(final ITmfEvent event) {
             super.handleData(event);
-            if (event != null && event.getTrace() == trace) {
+            if (event.getTrace() == trace) {
                 eventCount++;
 
                 /* Check if we need to register a new checkpoint */
@@ -330,17 +327,15 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
     }
 
     private class PartialStateSystemRequest extends TmfEventRequest {
-
-        private final static int chunkSize = 50000;
-        private final IStateChangeInput sci;
+        private final ITmfStateProvider sci;
         private final ITmfTrace trace;
 
-        PartialStateSystemRequest(IStateChangeInput sci, TmfTimeRange range) {
+        PartialStateSystemRequest(ITmfStateProvider sci, TmfTimeRange range) {
             super(sci.getExpectedEventType(),
                     range,
-                    TmfDataRequest.ALL_DATA,
-                    chunkSize,
-                    ITmfDataRequest.ExecutionType.BACKGROUND);
+                    0,
+                    ITmfEventRequest.ALL_DATA,
+                    ITmfEventRequest.ExecutionType.BACKGROUND);
             this.sci = sci;
             this.trace = sci.getTrace();
         }
@@ -348,7 +343,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
         @Override
         public void handleData(final ITmfEvent event) {
             super.handleData(event);
-            if (event != null && event.getTrace() == trace) {
+            if (event.getTrace() == trace) {
                 sci.processEvent(event);
             }
         }
@@ -360,12 +355,11 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
              * all events have been handled by the state system before doing
              * queries on it.
              */
-            if (partialInput instanceof AbstractStateChangeInput) {
-                ((AbstractStateChangeInput) partialInput).waitForEmptyQueue();
+            if (partialInput instanceof AbstractTmfStateProvider) {
+                ((AbstractTmfStateProvider) partialInput).waitForEmptyQueue();
             }
             super.handleCompleted();
         }
 
-
     }
 }
This page took 0.029644 seconds and 5 git commands to generate.