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 Cancellation
check()
Check if cancellation has been requested.boolean
isCancelable()
Check if this instance can ever return anything other thanNOPE
.static Canceller
newCanceller()
Create a newCanceller
which is trivially empty.Canceller
withCondition(String reason, BooleanSupplier condition)
Return a newCanceller
based on a boolean predicate.Canceller
withShortCircuit()
Canceller
withTimeout(String reason, long duration, TimeUnit unit)
Return a newCanceller
based on time duration.
-
-
-
Method Detail
-
newCanceller
public static Canceller newCanceller()
Create a newCanceller
which is trivially empty. The returnedCanceller
will 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 forROOT
and short circuits thereof.
-
check
public Cancellation check()
Check if cancellation has been requested. This method should be invoked periodically, and the returnedCancellation
should be inspected and reacted upon.- Returns:
- an instance of
Cancellation
.
-
withCondition
public Canceller withCondition(String reason, BooleanSupplier condition)
Return a newCanceller
based on a boolean predicate. The returned instance will relay a positive cancellation request when either the supplied boolean predicate istrue
or thisCanceller
is 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 newCanceller
based on time duration. The returned instance will relay a positive cancellation request when either the duration expires or thisCanceller
is 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
.
-
-