Package com.azure.android.core.util
Class CancellationToken
- java.lang.Object
-
- com.azure.android.core.util.CancellationToken
-
public final class CancellationToken extends java.lang.ObjectType representing a token to cancel one or more operations.
-
-
Field Summary
Fields Modifier and Type Field Description static CancellationTokenNONEAn empty CancellationToken that cannot be cancelled.
-
Constructor Summary
Constructors Constructor Description CancellationToken()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Communicates a request for cancellation.booleanisCancellationRequested()Gets whether cancellation has been requested for this token by callingcancel().voidregisterOnCancel(java.lang.Runnable onCancel)Registers aRunnablethat will be called when this CancellationToken is canceled.voidregisterOnCancel(java.lang.String id, java.lang.Runnable onCancel)Registers aRunnablethat will be called when this CancellationToken is canceled.voidunregisterOnCancel(java.lang.String id)Unregister theRunnablethat was registered usingregisterOnCancel(String, Runnable).
-
-
-
Field Detail
-
NONE
public static final CancellationToken NONE
An empty CancellationToken that cannot be cancelled.
-
-
Method Detail
-
cancel
public void cancel()
Communicates a request for cancellation.
-
isCancellationRequested
public boolean isCancellationRequested()
Gets whether cancellation has been requested for this token by callingcancel().- Returns:
trueif cancellation has been requested, otherwise.
-
registerOnCancel
public void registerOnCancel(java.lang.Runnable onCancel)
Registers aRunnablethat will be called when this CancellationToken is canceled. This operation of registering theRunnableis non-blocking and thread-safe. If the token is already in the cancelled state then the provided Runnable will be immediately executed. This is O(1) in best case and O(k) in worst, where k is number of concurrent threads in case of race.- Parameters:
onCancel- TheRunnableto be executed when the CancellationToken is canceled.
-
registerOnCancel
public void registerOnCancel(java.lang.String id, java.lang.Runnable onCancel)Registers aRunnablethat will be called when this CancellationToken is canceled. This operation of registering theRunnableis non-blocking and thread-safe. If the token is already in the cancelled state then the provided Runnable will be immediately executed. This is O(1) in best case and O(k) in worst, where k is number of concurrent threads in case of race in registering Callback.- Parameters:
id- The registration id for theRunnableto register.onCancel- TheRunnableto be executed when the CancellationToken is canceled.
-
unregisterOnCancel
public void unregisterOnCancel(java.lang.String id)
Unregister theRunnablethat was registered usingregisterOnCancel(String, Runnable). This unregister operation is non-blocking and thread-safe.- Parameters:
id- The id of theRunnableto unregister.
-
-