Class Canceller
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.file.cancel.Canceller
-
public class Canceller extends Object
Represents a way to check for a cancellation request. Users of this class (possibly cancelable, long-running operations) should periodically check whether a cancellation request has been received.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Cancellationcheck()Check if cancellation has been requested.booleanisCancelable()Check if this instance can ever return anything other thanNOPE.static CancellernewCanceller()Create a newCancellerwhich is trivially empty.CancellerwithCondition(String reason, BooleanSupplier condition)Return a newCancellerbased on a boolean predicate.CancellerwithShortCircuit()CancellerwithTimeout(String reason, long duration, TimeUnit unit)Return a newCancellerbased on time duration.
-
-
-
Method Detail
-
newCanceller
public static Canceller newCanceller()
Create a newCancellerwhich is trivially empty. The returnedCancellerwill never relay a positive cancellation request.- Returns:
- an instance of
Canceller.
-
isCancelable
public boolean isCancelable()
Check if this instance can ever return anything other thanNOPE. This will be only be false forROOTand short circuits thereof.
-
check
public Cancellation check()
Check if cancellation has been requested. This method should be invoked periodically, and the returnedCancellationshould be inspected and reacted upon.- Returns:
- an instance of
Cancellation.
-
withCondition
public Canceller withCondition(String reason, BooleanSupplier condition)
Return a newCancellerbased on a boolean predicate. The returned instance will relay a positive cancellation request when either the supplied boolean predicate istrueor thisCancelleris cancelled.- Parameters:
reason- The reason associated to the boolean condition.condition- A boolean predicate.- Returns:
- a new instance of
Canceller.
-
withTimeout
public Canceller withTimeout(String reason, long duration, TimeUnit unit)
Return a newCancellerbased on time duration. The returned instance will relay a positive cancellation request when either the duration expires or thisCancelleris cancelled.- Parameters:
reason- The reason associated to the boolean condition.duration- The duration for the timeout.unit- The time unit for the duration.- Returns:
- a new instance of
Canceller.
-
-