tmf: Early-exit event search methods if monitor is cancelled
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 12 Jul 2016 00:39:46 +0000 (20:39 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 12 Jul 2016 19:54:25 +0000 (15:54 -0400)
Prevents from sending a request at all if the job is already
cancelled when the methods get called.

Fixes a spurious test failure, but also covers for the case
where the job could be cancelled very quickly.

Change-Id: I7dd17fd32663ad6985ad4572541e896e9173dc7d
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/77106
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceUtils.java

index 64b08c135ca1a755e48c6c401ffc00188f3bc8c8..a76e671d728410b18e6086ad35bdf8bfbe675679 100644 (file)
@@ -205,6 +205,10 @@ public final class TmfTraceUtils {
      */
     public static @Nullable ITmfEvent getNextEventMatching(ITmfTrace trace, long startRank,
             Predicate<ITmfEvent> predicate, @Nullable IProgressMonitor monitor) {
+        if (monitor != null && monitor.isCanceled()) {
+            return null;
+        }
+
         /* rank + 1 because we do not want to include the start event itself in the search */
         EventMatchingRequest req = new EventMatchingRequest(startRank + 1, predicate, false);
         trace.sendRequest(req);
@@ -244,6 +248,9 @@ public final class TmfTraceUtils {
      */
     public static @Nullable ITmfEvent getPreviousEventMatching(ITmfTrace trace, long startRank,
             Predicate<ITmfEvent> predicate, @Nullable IProgressMonitor monitor) {
+        if (monitor != null && monitor.isCanceled()) {
+            return null;
+        }
         /*
          * We are going to do a series of queries matching the trace's cache
          * size in length (which should minimize on-disk seeks), then iterate on
This page took 0.025427 seconds and 5 git commands to generate.