TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, OFFSET, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(range, 0, NB_EVENTS, BLOCK_SIZE) {
@Override
- public void handlePartialResult() {
+ public void handleData() {
TmfEvent[] events = getData();
for (TmfEvent e : events) {
requestedEvents.add(e);
TmfEvent[] result = new TmfEvent[events.size()];
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
events.removeAllElements();
}
event = fStream.getNextEvent(context);
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
request.done();
}
};
import java.io.RandomAccessFile;
import java.util.Map;
-import org.eclipse.linuxtools.tmf.stream.AbstractTmfEventStream;
+import org.eclipse.linuxtools.tmf.stream.TmfEventStream;
import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
/**
* <p>
* TODO: Implement me. Please.
*/
-public class TmfEventStreamStub extends AbstractTmfEventStream {
+public class TmfEventStreamStub extends TmfEventStream {
// ========================================================================
// Attributes
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfComponent</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfComponent {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfTransform</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfTransform extends TmfComponent {
+
+ /**
+ *
+ */
+ public void transformData() {
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf;
+
+/**
+ * <b><u>TmfViewer</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfViewer extends TmfComponent {
+
+}
* <p>
* This is just an empty base class for the data meant to navigate in the
* framework.
+ * <p>
+ * TODO: Implement me. Please.
*/
public abstract class TmfData {
- public abstract boolean isNullRef();
-
}
* used as e.g. a location marker in the event stream to distinguish between
* otherwise identical events.
*/
-public class TmfEvent {
+public class TmfEvent extends TmfData {
// ========================================================================
// Attributes
* request is completed (e.g. for a specific range of events) or it
* can choose to process the events asynchronously (e.g. for streaming).
*
- * @param waitForCompletion Suspend the client thread until the request completes or is cancelled
+ * @param waitForCompletion Suspend the client thread until the request completes
*/
public void processRequest(TmfDataRequest<T> request, boolean waitForCompletion);
* Typical usage:
*<pre><code><i>TmfTimeWindow range = new TmfTimewindow(...);
*TmfDataRequest<DataType[]> request = new TmfDataRequest<DataType[]>(range, 0, NB_EVENTS, BLOCK_SIZE) {
- * @Override
- * public void handlePartialResult() {
+ * public void handleData() {
* DataType[] data = request.getData();
* for (DataType e : data) {
* // do something
* }
* }
+ * public void handleSuccess() {
+ * // do something
+ * }
+ * }
+ * public void handleFailure() {
+ * // do something
+ * }
+ * }
+ * public void handleCancel() {
+ * // do something
+ * }
+ * }
*};
*fProcessor.process(request, true);
*</i></code></pre>
* The main issue is the slicing of the result in blocks and continuous
* streams. This would require using a thread executor and to carefully
* look at setData() and getData().
+ *
+ * TODO: Implement request failures (codes, etc...)
*/
public class TmfDataRequest<V> {
// Attributes
// ========================================================================
- private final TmfTimeRange fRange; // The requested events timestamp range
+ private final TmfTimeRange fRange; // The requested events timestamp range
private final int fIndex; // The event index to get
private final long fOffset; // The synchronization offset to apply
private final int fNbRequestedItems; // The number of items to read (-1 == the whole range)
private Object lock = new Object();
private boolean fRequestCompleted = false;
+ private boolean fRequestFailed = false;
private boolean fRequestCanceled = false;
private V[] fData; // Data object
return fRequestCompleted;
}
+ /**
+ * @return indicates if the request is canceled
+ */
+ public boolean isFailed() {
+ return fRequestFailed;
+ }
+
/**
* @return indicates if the request is canceled
*/
}
/**
- * handlePartialResult()
+ * Handle a block of incoming data. This method is called every time
+ * a block of data becomes available.
*
* - Data items are received in the order they appear in the stream.
* - Called by the request processor, in its execution thread, every time a
*
* @param events - an array of events
*/
- public void handlePartialResult() {
+ public void handleData() {
}
+ /**
+ * Handle the completion of the request. It is called when there is no more
+ * data available either because:
+ * - the request completed normally
+ * - the request failed
+ * - the request was canceled
+ *
+ * As a convenience, handleXXXX methods are provided. They are meant to be
+ * overridden by the application if it needs to handle these conditions.
+ */
public void handleCompleted() {
+ if (fRequestFailed) {
+ handleFailure();
+ }
+ else if (fRequestCanceled) {
+ handleCancel();
+ }
+ handleSuccess();
+ }
+
+ public void handleSuccess() {
+ }
+
+ public void handleFailure() {
+ }
+
+ public void handleCancel() {
}
/**
}
/**
- * Complete the request. Called by the request processor upon completion.
+ * Called by the request processor upon completion.
*/
public void done() {
synchronized(lock) {
}
/**
- * Cancel the request.
+ * Called by the request processor upon failure.
+ */
+ public void fail() {
+ synchronized(lock) {
+ fRequestFailed = true;
+ done();
+ }
+ }
+
+ /**
+ * Called by the request processor upon cancellation.
*/
public void cancel() {
synchronized(lock) {
fRequestCanceled = true;
- fRequestCompleted = true;
- lock.notify();
+ done();
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.stream;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Vector;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;
-
-/**
- * <b><u>AbstractTmfEventStream</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public abstract class AbstractTmfEventStream implements ITmfEventStream {
-
- // ========================================================================
- // Constants
- // ========================================================================
-
- // The default number of events to cache
- public static final int DEFAULT_CACHE_SIZE = 1000;
-
- // ========================================================================
- // Attributes
- // ========================================================================
-
- // The stream name
- private final String fName;
-
- // The stream parser
- private final ITmfEventParser fParser;
-
- // The cache size
- private final int fCacheSize;
-
- // The set of event stream checkpoints (for random access)
- private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
-
- // The number of events collected
- private int fNbEvents = 0;
-
- // The time span of the event stream
- private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
-
- // The listeners
- private Set<TmfTrace> fListeners = new HashSet<TmfTrace>();
-
- // ========================================================================
- // Constructors
- // ========================================================================
-
- /**
- * @param filename
- * @param parser
- * @param cacheSize
- * @throws FileNotFoundException
- */
- protected AbstractTmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
- fName = filename;
- fParser = parser;
- fCacheSize = cacheSize;
- }
-
- /**
- * @param filename
- * @param parser
- * @throws FileNotFoundException
- */
- protected AbstractTmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
- this(filename, parser, DEFAULT_CACHE_SIZE);
- }
-
- // ========================================================================
- // Accessors
- // ========================================================================
-
- /**
- * @return
- */
- public int getCacheSize() {
- return fCacheSize;
- }
-
- /**
- * @return
- */
- public String getName() {
- return fName;
- }
-
- /**
- * @return
- */
- public synchronized int getNbEvents() {
- return fNbEvents;
- }
-
- /**
- * @return
- */
- public synchronized TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
- public StreamContext seekEvent(TmfTimestamp timestamp) {
-
- // First, find the right checkpoint
- int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
-
- // In the very likely event that the checkpoint was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and get the event.
- if (index < 0) {
- index = Math.max(0, -(index + 2));
- }
-
- // Position the stream at the checkpoint
- Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(location);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext.location);
-
- // And get the event
- TmfEvent event = getNextEvent(nextEventContext);
- while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
- currentEventContext.location = nextEventContext.location;
- event = getNextEvent(nextEventContext);
- }
-
- return currentEventContext;
- }
-
- public StreamContext seekEvent(int position) {
-
- // Position the stream at the previous checkpoint
- int index = position / fCacheSize;
- Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(location);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext.location);
-
- // And locate the event (if it exists)
- int current = index * fCacheSize;
- TmfEvent event = getNextEvent(nextEventContext);
- while (event != null && current < position) {
- currentEventContext.location = nextEventContext.location;
- event = getNextEvent(nextEventContext);
- current++;
- }
-
- return currentEventContext;
- }
-
- public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
-
- // Position the stream and update the context object
- StreamContext ctx = seekEvent(timestamp);
- context.location = ctx.location;
-
- return getNextEvent(context);
- }
-
- public TmfEvent getEvent(StreamContext context, int position) {
-
- // Position the stream and update the context object
- StreamContext ctx = seekEvent(position);
- context.location = ctx.location;
-
- return getNextEvent(context);
- }
-
- public synchronized TmfEvent getNextEvent(StreamContext context) {
- try {
- seekLocation(context.location);
- TmfEvent event = fParser.getNextEvent(this);
- context.location = getCurrentLocation();
- return event;
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public synchronized void addListener(TmfTrace listener) {
- fListeners.add(listener);
- }
-
- public synchronized void removeListener(TmfTrace listener) {
- fListeners.remove(listener);
- }
-
- private synchronized void notifyListeners() {
- for (TmfTrace listener : fListeners) {
- listener.handleEvent(new TmfStreamUpdateEvent(this));
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
- */
- public void indexStream(boolean waitForCompletion) {
- IndexingJob job = new IndexingJob(fName);
- job.schedule();
- if (waitForCompletion) {
- try {
- job.join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- private class IndexingJob extends Job {
-
- public IndexingJob(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- protected IStatus run(IProgressMonitor monitor) {
-
- int nbEvents = 0;
- TmfTimestamp startTime = new TmfTimestamp();
- TmfTimestamp lastTime = new TmfTimestamp();
-
- monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
-
- try {
- StreamContext nextEventContext;
- synchronized(this) {
- nextEventContext = seekLocation(null);
- }
- StreamContext currentEventContext = new StreamContext(nextEventContext.location);
- TmfEvent event = getNextEvent(nextEventContext);
- if (event != null) {
- startTime = event.getTimestamp();
- lastTime = event.getTimestamp();
- }
-
- while (event != null) {
- lastTime = event.getTimestamp();
- if ((nbEvents++ % fCacheSize) == 0) {
- TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
- synchronized(this) {
- fCheckpoints.add(bookmark);
- fNbEvents = nbEvents;
- fTimeRange = new TmfTimeRange(startTime, lastTime);
- }
- notifyListeners();
- monitor.worked(1);
- // Check monitor *after* fCheckpoints has been updated
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- }
-
- currentEventContext.location = nextEventContext.location;
- event = getNextEvent(nextEventContext);
- }
- }
- finally {
- synchronized(this) {
- fNbEvents = nbEvents;
- fTimeRange = new TmfTimeRange(startTime, lastTime);
- }
- notifyListeners();
- monitor.done();
- }
-
- return Status.OK_STATUS;
- }
- }
-
- public void indexStream(final String filename) {
-
-// ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
-// try {
-// dialog.run(true, true, new IRunnableWithProgress() {
-// @Override
-// public void run(IProgressMonitor monitor)
-// throws InvocationTargetException, InterruptedException {
-// monitor.beginTask("Indexing " + filename,
-// IProgressMonitor.UNKNOWN);
-//
-// try {
-// seekLocation(null);
-// TmfTimestamp startTime = new TmfTimestamp();
-// TmfTimestamp lastTime = new TmfTimestamp();
-// Object location = getCurrentLocation();
-//
-// TmfEvent event = getNextEvent();
-// if (event != null) {
-// startTime = event.getTimestamp();
-// while (event != null) {
-// lastTime = event.getTimestamp();
-// if ((fNbEvents++ % fCacheSize) == 0) {
-// if (monitor.isCanceled()) {
-// throw new CancellationException();
-// }
-// TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(
-// lastTime, location);
-// fCheckpoints.add(bookmark);
-// monitor.worked(1);
-// }
-// location = getCurrentLocation();
-// event = getNextEvent();
-// }
-// fTimeRange = new TmfTimeRange(startTime, lastTime);
-// }
-// seekLocation(null);
-// } catch (IOException e) {
-// } finally {
-// monitor.done();
-// }
-// }
-//
-// });
-// } catch (InvocationTargetException e1) {
-// // TODO Auto-generated catch block
-// e1.printStackTrace();
-// } catch (InterruptedException e1) {
-// // TODO Auto-generated catch block
-// e1.printStackTrace();
-// }
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.stream;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
+
+/**
+ * <b><u>TmfEventStream</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public abstract class TmfEventStream implements ITmfEventStream {
+
+ // ========================================================================
+ // Constants
+ // ========================================================================
+
+ // The default number of events to cache
+ public static final int DEFAULT_CACHE_SIZE = 1000;
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ // The stream name
+ private final String fName;
+
+ // The stream parser
+ private final ITmfEventParser fParser;
+
+ // The cache size
+ private final int fCacheSize;
+
+ // The set of event stream checkpoints (for random access)
+ private Vector<TmfStreamCheckpoint> fCheckpoints = new Vector<TmfStreamCheckpoint>();
+
+ // The number of events collected
+ private int fNbEvents = 0;
+
+ // The time span of the event stream
+ private TmfTimeRange fTimeRange = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigBang);
+
+ // The listeners
+ private Set<TmfTrace> fListeners = new HashSet<TmfTrace>();
+
+ // ========================================================================
+ // Constructors
+ // ========================================================================
+
+ /**
+ * @param filename
+ * @param parser
+ * @param cacheSize
+ * @throws FileNotFoundException
+ */
+ protected TmfEventStream(String filename, ITmfEventParser parser, int cacheSize) throws FileNotFoundException {
+ fName = filename;
+ fParser = parser;
+ fCacheSize = cacheSize;
+ }
+
+ /**
+ * @param filename
+ * @param parser
+ * @throws FileNotFoundException
+ */
+ protected TmfEventStream(String filename, ITmfEventParser parser) throws FileNotFoundException {
+ this(filename, parser, DEFAULT_CACHE_SIZE);
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ /**
+ * @return
+ */
+ public int getCacheSize() {
+ return fCacheSize;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * @return
+ */
+ public synchronized int getNbEvents() {
+ return fNbEvents;
+ }
+
+ /**
+ * @return
+ */
+ public synchronized TmfTimeRange getTimeRange() {
+ return fTimeRange;
+ }
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ public StreamContext seekEvent(TmfTimestamp timestamp) {
+
+ // First, find the right checkpoint
+ int index = Collections.binarySearch(fCheckpoints, new TmfStreamCheckpoint(timestamp, 0));
+
+ // In the very likely event that the checkpoint was not found, bsearch
+ // returns its negated would-be location (not an offset...). From that
+ // index, we can then position the stream and get the event.
+ if (index < 0) {
+ index = Math.max(0, -(index + 2));
+ }
+
+ // Position the stream at the checkpoint
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+ // And get the event
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ }
+
+ return currentEventContext;
+ }
+
+ public StreamContext seekEvent(int position) {
+
+ // Position the stream at the previous checkpoint
+ int index = position / fCacheSize;
+ Object location = (index < fCheckpoints.size()) ? fCheckpoints.elementAt(index).getLocation() : null;
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(location);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+
+ // And locate the event (if it exists)
+ int current = index * fCacheSize;
+ TmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && current < position) {
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ current++;
+ }
+
+ return currentEventContext;
+ }
+
+ public TmfEvent getEvent(StreamContext context, TmfTimestamp timestamp) {
+
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(timestamp);
+ context.location = ctx.location;
+
+ return getNextEvent(context);
+ }
+
+ public TmfEvent getEvent(StreamContext context, int position) {
+
+ // Position the stream and update the context object
+ StreamContext ctx = seekEvent(position);
+ context.location = ctx.location;
+
+ return getNextEvent(context);
+ }
+
+ public synchronized TmfEvent getNextEvent(StreamContext context) {
+ try {
+ seekLocation(context.location);
+ TmfEvent event = fParser.getNextEvent(this);
+ context.location = getCurrentLocation();
+ return event;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public synchronized void addListener(TmfTrace listener) {
+ fListeners.add(listener);
+ }
+
+ public synchronized void removeListener(TmfTrace listener) {
+ fListeners.remove(listener);
+ }
+
+ private synchronized void notifyListeners() {
+ for (TmfTrace listener : fListeners) {
+ listener.handleEvent(new TmfStreamUpdateEvent(this));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#indexStream()
+ */
+ public void indexStream(boolean waitForCompletion) {
+ IndexingJob job = new IndexingJob(fName);
+ job.schedule();
+ if (waitForCompletion) {
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private class IndexingJob extends Job {
+
+ public IndexingJob(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ int nbEvents = 0;
+ TmfTimestamp startTime = new TmfTimestamp();
+ TmfTimestamp lastTime = new TmfTimestamp();
+
+ monitor.beginTask("Indexing " + fName, IProgressMonitor.UNKNOWN);
+
+ try {
+ StreamContext nextEventContext;
+ synchronized(this) {
+ nextEventContext = seekLocation(null);
+ }
+ StreamContext currentEventContext = new StreamContext(nextEventContext.location);
+ TmfEvent event = getNextEvent(nextEventContext);
+ if (event != null) {
+ startTime = event.getTimestamp();
+ lastTime = event.getTimestamp();
+ }
+
+ while (event != null) {
+ lastTime = event.getTimestamp();
+ if ((nbEvents++ % fCacheSize) == 0) {
+ TmfStreamCheckpoint bookmark = new TmfStreamCheckpoint(lastTime, currentEventContext.location);
+ synchronized(this) {
+ fCheckpoints.add(bookmark);
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners();
+ monitor.worked(1);
+ // Check monitor *after* fCheckpoints has been updated
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+ currentEventContext.location = nextEventContext.location;
+ event = getNextEvent(nextEventContext);
+ }
+ }
+ finally {
+ synchronized(this) {
+ fNbEvents = nbEvents;
+ fTimeRange = new TmfTimeRange(startTime, lastTime);
+ }
+ notifyListeners();
+ monitor.done();
+ }
+
+ return Status.OK_STATUS;
+ }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.trace;
+
+import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.request.ITmfRequestHandler;
+import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
+
+/**
+ * <b><u>TmfExperiment</u></b>
+ * <p>
+ * TmfExperiment presents a time-ordered, unified view of a set of
+ * TmfTraces that are part of a tracing experiment.
+ * <p>
+ * TODO: Implement me. PLease.
+ */
+public class TmfExperiment implements ITmfRequestHandler<TmfEvent> {
+
+ // ========================================================================
+ // Attributes
+ // ========================================================================
+
+ // ========================================================================
+ // Constructors/Destructors
+ // ========================================================================
+
+ public TmfExperiment() {
+ }
+
+ // ========================================================================
+ // Accessors
+ // ========================================================================
+
+ // ========================================================================
+ // Operators
+ // ========================================================================
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.eventlog.ITmfRequestHandler#processRequest(org.eclipse.linuxtools.tmf.eventlog.TmfDataRequest, boolean)
+ */
+ public void processRequest(TmfDataRequest<TmfEvent> request, boolean waitForCompletion) {
+ }
+
+ // ========================================================================
+ // Helper functions
+ // ========================================================================
+
+}
import org.eclipse.linuxtools.tmf.stream.ITmfEventStream.StreamContext;
/**
- * <b><u>TmfEventLog</u></b>
+ * <b><u>TmfTrace</u></b>
* <p>
- * TmfEventLog represents a time-ordered set of events tied to a single event
+ * TmfTrace represents a time-ordered set of events tied to a single event
* stream. It keeps track of the global information about the event log:
* <ul>
* <li> the epoch, a reference timestamp for the whole log (t0)
TmfEvent[] result = new TmfEvent[events.size()];
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
events.removeAllElements();
}
// To avoid an unnecessary read passed the last event requested
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
request.done();
}
};
TmfEvent[] result = new TmfEvent[events.size()];
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
events.removeAllElements();
}
// To avoid an unnecessary read passed the last event requested
events.toArray(result);
request.setData(result);
- request.handlePartialResult();
+ request.handleData();
request.done();
}
};