Module stormpot

Class StackCompletion

java.lang.Object
stormpot.internal.StackCompletion
All Implemented Interfaces:
Flow.Publisher<Void>, ForkJoinPool.ManagedBlocker, Completion

public final class StackCompletion extends Object implements Completion
An implementation of Completion based on a wait-free stack. This implementation also supports a callback mechanism that trigger every time an await(Timeout) or block() call is about to block.
  • Constructor Details

    • StackCompletion

      public StackCompletion()
      Create an unfinished completion with no StackCompletion.OnAwait callback.
    • StackCompletion

      public StackCompletion(boolean completed)
      Create a possibly finished completion with no StackCompletion.OnAwait callback.
      Parameters:
      completed - true if the completion should be initialized in the finished state, otherwise false.
    • StackCompletion

      public StackCompletion(StackCompletion.OnAwait onAwait)
      Create an unfinished completion with the given StackCompletion.OnAwait callback.
      Parameters:
      onAwait - The callback to notify for blocking, may be null.
  • Method Details

    • complete

      public void complete()
      Complete this completion and notify all waiters and subscribers.
    • subscribe

      public void subscribe(Flow.Subscriber<? super Void> subscriber)
      Specified by:
      subscribe in interface Flow.Publisher<Void>
    • propagateTo

      public void propagateTo(StackCompletion other)
      Complete the given completion when this completion completes. If the given completion completes first, then their subscription to this completion is cancelled.
      Parameters:
      other - The completion to propagate to.
    • await

      public boolean await(Timeout timeout) throws InterruptedException
      Description copied from interface: Completion
      Causes the current thread to wait until the completion is finished, or the thread is interrupted, or the specified waiting time elapses.

      If the task represented by this completion has already completed, the method immediately returns true.

      If the current thread already has its interrupted status set upon entry to this method, or the thread is interrupted while waiting, then an InterruptedException is thrown and the current threads interrupted status is cleared.

      If the specified waiting time elapses, then the method returns false.

      Specified by:
      await in interface Completion
      Parameters:
      timeout - The timeout delimiting the maximum time to wait for the task to complete. Timeouts with zero or negative values will cause the method to return immediately.
      Returns:
      true if the task represented by this completion completed within the specified waiting time, or was already complete upon entry to this method; or false if the specified Timeout elapsed before the task could finish.
      Throws:
      InterruptedException - if the current thread is interrupted while waiting.
    • block

      public boolean block() throws InterruptedException
      Specified by:
      block in interface ForkJoinPool.ManagedBlocker
      Throws:
      InterruptedException
    • isReleasable

      public boolean isReleasable()
      Specified by:
      isReleasable in interface ForkJoinPool.ManagedBlocker
    • isCompleted

      public boolean isCompleted()
      Description copied from interface: Completion
      Immediately return whether the completion has completed or not.
      Specified by:
      isCompleted in interface Completion
      Returns:
      true if this completion has completed, otherwise false.