Class Canceller
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.file.cancel.Canceller
-
public class Canceller extends java.lang.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.static Canceller
newCanceller()
Create a newCanceller
which is trivially empty.Canceller
withCondition(java.lang.String reason, java.util.function.BooleanSupplier condition)
Return a newCanceller
based on a boolean predicate.Canceller
withShortCircuit()
Canceller
withTimeout(java.lang.String reason, long duration, java.util.concurrent.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
.
-
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(java.lang.String reason, java.util.function.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(java.lang.String reason, long duration, java.util.concurrent.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
.
-
-