package org.eclipse.linuxtools.tmf.core.trace;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.Vector;
+import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
* Locating a specific checkpoint is trivial for both rank (rank % interval) and
* timestamp (bsearch in the array).
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
- * @see ITmfTraceIndexer
* @see ITmfTrace
* @see ITmfEvent
*/
// Attributes
// ------------------------------------------------------------------------
- /**
- * The event trace to index
- */
+ // The event trace to index
private final ITmfTrace<ITmfEvent> fTrace;
- /**
- * The interval between checkpoints
- */
- protected final int fCheckpointInterval;
+ // The interval between checkpoints
+ private final int fCheckpointInterval;
/**
* The trace index. It is composed of checkpoints taken at intervals of
* fCheckpointInterval events.
*/
- protected final Vector<TmfCheckpoint> fTraceIndex;
+ private final List<TmfCheckpoint> fTraceIndex;
// ------------------------------------------------------------------------
// Construction
public TmfCheckpointIndexer(final ITmfTrace<ITmfEvent> trace, final int interval) {
fTrace = trace;
fCheckpointInterval = interval;
- fTraceIndex = new Vector<TmfCheckpoint>();
+ fTraceIndex = new ArrayList<TmfCheckpoint>();
}
// ------------------------------------------------------------------------
final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY,
TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
{
- ITmfTimestamp startTime = null;
- ITmfTimestamp lastTime = null;
+ private ITmfTimestamp startTime = null;
+ private ITmfTimestamp lastTime = null;
@Override
public void handleData(final ITmfEvent event) {
public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) {
// A null timestamp indicates to seek the first event
- if (timestamp == null)
+ if (timestamp == null) {
return fTrace.seekEvent(0);
+ }
// Find the checkpoint at or before the requested timestamp.
// In the very likely event that the timestamp is not at a checkpoint
public ITmfContext seekIndex(final long rank) {
// A rank < 0 indicates to seek the first event
- if (rank < 0)
+ if (rank < 0) {
return fTrace.seekEvent(0);
+ }
// Find the checkpoint at or before the requested rank.
final int index = (int) rank / fCheckpointInterval;
/**
* Position the trace at the given checkpoint
*
- * @param index
- * the checkpoint index
+ * @param checkpoint the checkpoint index
* @return the corresponding context
*/
- private ITmfContext seekCheckpoint(int index) {
+ private ITmfContext seekCheckpoint(final int checkpoint) {
ITmfLocation<?> location;
+ int index = checkpoint;
synchronized (fTraceIndex) {
if (!fTraceIndex.isEmpty()) {
if (index >= fTraceIndex.size()) {
index = fTraceIndex.size() - 1;
}
- location = fTraceIndex.elementAt(index).getLocation();
+ location = fTraceIndex.get(index).getLocation();
} else {
location = null;
}
return context;
}
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ /**
+ * @return the trace index
+ */
+ protected List<TmfCheckpoint> getTraceIndex() {
+ return fTraceIndex;
+ }
}