/** * Marks task as cancelled. * <p> * Returns true if cancellation was successful, false otherwise. */ public boolean cancel(String reason, Runnable listener) { final boolean cancelled; synchronized (this) { assert reason != null; if (cancellationReason == null) { cancellationReason = reason; cancellationListener = listener; cancelled = true; } else { // Already cancelled by somebody else cancelled = false; } } if (cancelled) { task.cancel(reason); } return cancelled; }
/** * Marks task as cancelled. * <p> * Returns true if cancellation was successful, false otherwise. */ public boolean cancel(String reason, Runnable listener) { final boolean cancelled; synchronized (this) { assert reason != null; if (cancellationReason == null) { cancellationReason = reason; cancellationListener = listener; cancelled = true; } else { // Already cancelled by somebody else cancelled = false; } } if (cancelled) { task.cancel(reason); } return cancelled; }
/** * Marks task as cancelled. * <p> * Returns true if cancellation was successful, false otherwise. */ public boolean cancel(String reason, Runnable listener) { final boolean cancelled; synchronized (this) { assert reason != null; if (cancellationReason == null) { cancellationReason = reason; cancellationListener = listener; cancelled = true; } else { // Already cancelled by somebody else cancelled = false; } } if (cancelled) { task.cancel(reason); } return cancelled; }
/** * Marks task as cancelled. * <p> * Returns true if cancellation was successful, false otherwise. */ public boolean cancel(String reason, Runnable listener) { final boolean cancelled; synchronized (this) { assert reason != null; if (cancellationReason == null) { cancellationReason = reason; cancellationListener = listener; cancelled = true; } else { // Already cancelled by somebody else cancelled = false; } } if (cancelled) { task.cancel(reason); } return cancelled; }
/** * Marks task as cancelled. * <p> * Returns a set of nodes with child tasks where this task should be cancelled if cancellation was successful, null otherwise. */ public Set<String> cancel(String reason, Consumer<Set<String>> listener) { Set<String> nodes; synchronized (this) { assert reason != null; if (cancellationReason == null) { cancellationReason = reason; cancellationListener = listener; nodes = Collections.unmodifiableSet(nodesWithChildTasks); } else { // Already cancelled by somebody else nodes = null; } } if (nodes != null) { task.cancel(reason); } return nodes; }