Package io.pravega.common.concurrent
Class CancellationToken
- java.lang.Object
-
- io.pravega.common.concurrent.CancellationToken
-
@ThreadSafe public class CancellationToken extends java.lang.ObjectRepresents a token that can be passed around to various services or components to indicate when a task should be cancelled.
-
-
Field Summary
Fields Modifier and Type Field Description static CancellationTokenNONEA CancellationToken that can be used as a placeholder for "no token to pass".
-
Constructor Summary
Constructors Constructor Description CancellationToken()Creates a new instance of the CancellationToken class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisCancellationRequested()<T> voidregister(java.util.concurrent.CompletableFuture<T> future)Registers the given Future to the token.voidrequestCancellation()Cancels all registered futures.java.lang.StringtoString()
-
-
-
Field Detail
-
NONE
public static final CancellationToken NONE
A CancellationToken that can be used as a placeholder for "no token to pass". This token instance cannot be cancelled.
-
-
Method Detail
-
register
public <T> void register(java.util.concurrent.CompletableFuture<T> future)
Registers the given Future to the token.- Type Parameters:
T- Return type of the future.- Parameters:
future- The Future to register.
-
requestCancellation
public void requestCancellation()
Cancels all registered futures.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isCancellationRequested
public boolean isCancellationRequested()
-
-