use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfSyntheticEventProviderStub method armRequest.
@Override
public ITmfContext armRequest(final ITmfEventRequest request) {
// Get the TmfSyntheticEventStub provider
final ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
final ITmfEventProvider provider = eventProviders[0];
final TmfTimeRange range = request.getRange();
final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
handleIncomingData(event);
}
};
provider.sendRequest(subRequest);
// Return a dummy context
return new TmfContext();
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventsCache method populateCache.
private synchronized void populateCache(final int index) {
/* Check if the current job will fetch the requested event:
* 1. The job must exist
* 2. It must be running (i.e. not completed)
* 3. The requested index must be within the cache range
*
* If the job meets these conditions, we simply exit.
* Otherwise, we create a new job but we might have to cancel
* an existing job for an obsolete range.
*/
if (job != null) {
if (job.getState() != Job.NONE) {
if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) {
return;
}
// The new index is out of the requested range
// Kill the job and start a new one
job.cancel();
}
}
// Populate the cache starting at the index that is one block less
// of cache size than the requested index. The cache will hold two
// consecutive blocks of cache size, centered on the requested index.
fCacheStartIndex = Math.max(0, index - fCacheSize);
fCacheEndIndex = fCacheStartIndex;
job = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"Fetching Events") {
private int startIndex = fCacheStartIndex;
private int skipCount = 0;
@Override
protected IStatus run(final IProgressMonitor monitor) {
int nbRequested;
if (fFilter == null) {
nbRequested = fCache.length;
} else {
nbRequested = ITmfEventRequest.ALL_DATA;
int i = startIndex / fCacheSize;
if (i < fFilterIndex.size()) {
skipCount = startIndex - (i * fCacheSize);
startIndex = fFilterIndex.get(i);
}
}
TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startIndex, nbRequested, TmfEventRequest.ExecutionType.FOREGROUND) {
private int count = 0;
private long rank = startIndex;
private TmfCollapseFilter collapseFilter = fCollapseFilterEnabled ? new TmfCollapseFilter() : null;
@Override
public void handleData(ITmfEvent event) {
// If the job is canceled, cancel the request so waitForCompletion() will unlock
if (monitor.isCanceled()) {
cancel();
return;
}
super.handleData(event);
if ((fFilter == null) || fFilter.matches(event)) {
if (collapseFilter == null || collapseFilter.matches(event)) {
if (skipCount-- <= 0) {
synchronized (TmfEventsCache.this) {
if (monitor.isCanceled()) {
return;
}
fCache[count] = new CachedEvent(event, rank);
count++;
fCacheEndIndex++;
}
if (fFilter != null) {
fTable.cacheUpdated(false);
}
}
} else if ((count > 0) && (skipCount <= 0)) {
fCache[count - 1].repeatCount++;
}
}
if (count >= fCache.length) {
cancel();
} else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) {
// -1 for header row, -2 for top and bottom filter status rows
cancel();
}
rank++;
}
};
((ITmfEventProvider) fTrace).sendRequest(request);
try {
request.waitForCompletion();
} catch (InterruptedException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Wait for completion interrupted for populateCache ", e);
Thread.currentThread().interrupt();
}
fTable.cacheUpdated(true);
// Flag the UI thread that the cache is ready
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
// job.setSystem(true);
job.setPriority(Job.SHORT);
job.schedule();
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventRequestTest method testWaitForStartAfterCancel.
/**
* Test calling waitForStart() after the request has beend cancelled. It
* should not block.
*/
@Test
public void testWaitForStartAfterCancel() throws InterruptedException {
final boolean[] flags = new boolean[4];
TmfEventRequest request = setupTestRequest(flags);
request.start();
request.cancel();
request.waitForStart();
assertTrue("isCompleted", request.isCompleted());
assertFalse("isFailed", request.isFailed());
assertTrue("isCancelled", request.isCancelled());
assertTrue("handleCompleted", flags[0]);
assertFalse("handleSuccess", flags[1]);
assertFalse("handleFailure", flags[2]);
assertTrue("handleCancel", flags[3]);
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventRequestTest method testTmfEventRequestTimeRangeNbRequested.
@Test
public void testTmfEventRequestTimeRangeNbRequested() {
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromSeconds(0), TmfTimestamp.BIG_CRUNCH);
TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range, 100);
assertEquals("getDataType", ITmfEvent.class, request.getDataType());
assertEquals("StartTime", TmfTimestamp.fromSeconds(0), request.getRange().getStartTime());
assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime());
assertEquals("getIndex", 0, request.getIndex());
assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
assertFalse("isCompleted", request.isCompleted());
assertFalse("isFailed", request.isFailed());
assertFalse("isCancelled", request.isCancelled());
assertEquals("getNbRead", 0, request.getNbRead());
assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventRequestTest method testCancel.
// ------------------------------------------------------------------------
// cancel
// ------------------------------------------------------------------------
@Test
public void testCancel() {
final boolean[] flags = new boolean[4];
TmfEventRequest request = setupTestRequest(flags);
request.cancel();
assertTrue("isCompleted", request.isCompleted());
assertFalse("isFailed", request.isFailed());
assertTrue("isCancelled", request.isCancelled());
assertTrue("handleCompleted", flags[0]);
assertFalse("handleSuccess", flags[1]);
assertFalse("handleFailure", flags[2]);
assertTrue("handleCancel", flags[3]);
}
Aggregations