Class CancellationToken


  • @ThreadSafe
    public class CancellationToken
    extends java.lang.Object
    Represents 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 CancellationToken NONE
      A 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
      boolean isCancellationRequested()  
      <T> void register​(java.util.concurrent.CompletableFuture<T> future)
      Registers the given Future to the token.
      void requestCancellation()
      Cancels all registered futures.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • CancellationToken

        public CancellationToken()
        Creates a new instance of the CancellationToken class.
    • 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:
        toString in class java.lang.Object
      • isCancellationRequested

        public boolean isCancellationRequested()