Class SingleSubscriberHolder<T>

Type Parameters:
T - the type of the Subscriber

public class SingleSubscriberHolder<T> extends Object
A subscriber container that accepts only a single, one-time subscriber registration.
  • Constructor Details

    • SingleSubscriberHolder

      @Deprecated(forRemoval=true, since="4.0.9") public SingleSubscriberHolder()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use create() instead.
      This constructor should not be exposed.
  • Method Details

    • create

      public static <T> SingleSubscriberHolder<T> create()
      Create a new instance.
      Type Parameters:
      T - type of the subscriber
      a new instance to use as a subscriber holder
    • register

      public boolean register(Flow.Subscriber<? super T> subscriber)
      Register a new subscriber.

      In case the subscriber registration fails (e.g. the holder already holds a previously registered subscriber or the holder has been closed), the newly registered subscriber is notified about the error by invoking it's subscriber.onError method.

      subscriber - subscriber to be registered in the holder.
      true if the subscriber was successfully registered, false otherwise.
    • close

      public void close(Consumer<Flow.Subscriber<? super T>> completionHandler)
      Mark the subscriber holder as closed.

      Invoking this method will ensure that any new attempts to register a new subscriber would fail.

      In case this holder holds a subscriber and the close method has not been invoked yet, the supplied completionHandler is invoked using the value of the registered subscriber as an input parameter. This means that the supplied completion handler is guaranteed to be invoked at most once.

      completionHandler - completion handler to be invoked to process any completion logic on a registered subscriber, provided there is a registered subscriber and it has not been previously passed to a completion handler (e.g. in a previous invocation of this method).
    • cancel

      public void cancel()
      Hard cancel - nothing is sent to the subscriber but subscription is considered as canceled.
    • get

      Get the stored subscriber.

      This method blocks indefinitely until a subscriber is registered or the holder has been closed.

      registered subscriber.
      ExecutionException - if the subscriber retrieval has failed (e.g. because this holder has been closed before a subscriber has been registered).
      InterruptedException - if the current thread was interrupted
    • isClosed

      public boolean isClosed()
      Check if this subscriber holder has been closed.
      true if the holder is closed, false otherwise.