use of org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal in project tracecompass by tracecompass.
the class TmfCheckpointIndexer method buildIndex.
// ------------------------------------------------------------------------
// ITmfTraceIndexer - buildIndex
// ------------------------------------------------------------------------
@Override
public void buildIndex(final long offset, final TmfTimeRange range, final boolean waitForCompletion) {
long indexingOffset = offset;
TmfTimeRange indexingTimeRange = range;
// Don't do anything if we are already indexing
synchronized (fTraceIndex) {
if (fIsIndexing) {
return;
}
fIsIndexing = true;
}
// Restore previously built index values
if (!fTraceIndex.isCreatedFromScratch() && !fBuiltOnce && fTraceIndex.getNbEvents() > 0) {
indexingOffset = fTraceIndex.getNbEvents();
indexingTimeRange = new TmfTimeRange(fTraceIndex.getTimeRange().getStartTime(), TmfTimestamp.BIG_CRUNCH);
// $NON-NLS-1$ //$NON-NLS-2$
TmfCoreTracer.traceIndexer("restoring index. nbEvents: " + fTraceIndex.getNbEvents() + " time range: " + fTraceIndex.getTimeRange());
// Set some trace attributes that depends on indexing
TmfTraceUpdatedSignal signal = new TmfTraceUpdatedSignal(this, fTrace, new TmfTimeRange(fTraceIndex.getTimeRange().getStartTime(), fTraceIndex.getTimeRange().getEndTime()), indexingOffset);
fTrace.broadcast(signal);
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
TmfCoreTracer.traceIndexer("buildIndex. offset: " + indexingOffset + " (requested " + offset + ")" + " time range: " + range);
// The monitoring job
// $NON-NLS-1$ //$NON-NLS-2$
TmfIndexingJob job = new TmfIndexingJob("Indexing " + fTrace.getName() + "...");
job.setSystem(fBuiltOnce);
fBuiltOnce = true;
job.schedule();
// Build a background request for all the trace data. The index is
// updated as we go by readNextEvent().
fIndexingRequest = new TmfEventRequest(ITmfEvent.class, indexingTimeRange, indexingOffset, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
// Update the trace status at regular intervals
if ((getNbRead() % fCheckpointInterval) == 0) {
updateTraceStatus();
}
}
@Override
public void handleSuccess() {
updateTraceStatus();
}
@Override
public void handleCompleted() {
job.cancel();
fTraceIndex.setTimeRange(fTrace.getTimeRange());
fTraceIndex.setNbEvents(fTrace.getNbEvents());
super.handleCompleted();
fIsIndexing = false;
// $NON-NLS-1$ //$NON-NLS-2$
TmfCoreTracer.traceIndexer("Build index request completed. nbEvents: " + fTraceIndex.getNbEvents() + " time range: " + fTraceIndex.getTimeRange());
}
@Override
public void fail(Exception e) {
super.fail(e);
job.setException(e);
}
private void updateTraceStatus() {
if (fTrace.getNbEvents() > 0) {
signalNewTimeRange(fTrace.getStartTime(), fTrace.getEndTime());
}
}
};
// Submit the request and wait for completion if required
fTrace.sendRequest(fIndexingRequest);
if (waitForCompletion) {
try {
fIndexingRequest.waitForCompletion();
} catch (final InterruptedException e) {
}
}
}
Aggregations