Class Cancellation

java.lang.Object
com.hedera.hashgraph.sdk.Cancellation

public final class Cancellation extends Object
A caller's request to end an exchange early, as observed by an HttpTransport.

A transport observes one; it never creates one. Only CancellationSource can fire it, so a third-party transport handed a Cancellation cannot cancel the caller's own operation.

Spelled Cancellation rather than CancellationSignal to avoid colliding with android.os.CancellationSignal.

  • Constructor Details

  • Method Details

    • none

      public static Cancellation none()
      The value for a call with no caller-supplied cancellation. Never null, and never fires.
      Returns:
      a cancellation that is never cancelled
    • isCancelled

      public boolean isCancelled()
      Whether the caller has cancelled.

      Returns true before any onCancel(Runnable) callback runs.

      Returns:
      true if cancelled
    • onCancel

      public CancellationRegistration onCancel(Runnable callback)
      Observe the cancellation.

      The callback runs synchronously on the thread that cancelled and must not block. Registering on an instance that has already been cancelled runs the callback immediately rather than never.

      A transport must release its registration when the exchange ends — see CancellationRegistration.

      Parameters:
      callback - the observer to run when the cancellation fires
      Returns:
      a handle that stops the observation