Skip to content
Permalink
Browse files
code review for task-cancellation mode
  • Loading branch information
ahgittin committed Jan 20, 2016
1 parent aed0786 commit 54cba8a657f151f93eb3cb504ccbb94c6d1fc9c7
Showing 3 changed files with 5 additions and 3 deletions.
@@ -576,6 +576,7 @@ public boolean cancel(TaskCancellationMode mode) {
}
}
}
// TODO this is inefficient; might want to keep an index on submitted-by
for (Task<?> t: execMgmt.getAllTasks()) {
if (task.equals(t.getSubmittedByTask())) {
if (mode.isAllowedToInterruptAllSubmittedTasks() || BrooklynTaskTags.isTransient(t)) {
@@ -740,7 +741,7 @@ static Object invokeCallback(Object callable, Task<?> task) {
try {
return ((Callable<?>)callable).call();
} catch (Throwable t) {
throw Throwables.propagate(t);
throw Exceptions.propagate(t);
}
}
if (callable instanceof Runnable) { ((Runnable)callable).run(); return null; }
@@ -294,6 +294,7 @@ public final synchronized boolean cancel(boolean mayInterruptIfRunning) {
: TaskCancellationMode.DO_NOT_INTERRUPT);
}

@Override @Beta
public synchronized boolean cancel(TaskCancellationMode mode) {
if (isDone()) return false;
if (log.isTraceEnabled()) {
@@ -267,14 +267,14 @@ public void doTestCancellationModeAndSubmitted(
waitForMessages(Predicates.compose(MathPredicates.greaterThanOrEqual(2), CollectionFunctionals.sizeFunction()), TIMEOUT);
Asserts.assertEquals(MutableSet.copyOf(messages), MutableSet.of("1-wait", "2-wait"));

Time.sleep(Duration.millis(400));

if (cancellationMode==null) {
((TaskInternal<?>)t).cancel();
} else if (cancellationMode instanceof Boolean) {
t.cancel((Boolean)cancellationMode);
} else if (cancellationMode instanceof TaskCancellationMode) {
((TaskInternal<?>)t).cancel((TaskCancellationMode)cancellationMode);
} else {
throw new IllegalStateException("Invalid cancellationMode: "+cancellationMode);
}

// the cancelled task always reports cancelled and done

0 comments on commit 54cba8a

Please sign in to comment.