Module io.helidon.common.reactive
Package io.helidon.common.reactive
Class SingleSubscriberHolder<T>
java.lang.Object
io.helidon.common.reactive.SingleSubscriberHolder<T>
- Type Parameters:
T
- the type of theSubscriber
A subscriber container that accepts only a single, one-time subscriber registration.
-
Constructor Summary
ConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Hard cancel - nothing is sent to the subscriber but subscription is considered as canceled.void
close
(Consumer<Flow.Subscriber<? super T>> completionHandler) Mark the subscriber holder as closed.static <T> SingleSubscriberHolder
<T> create()
Create a new instance.Flow.Subscriber
<? super T> get()
Get the stored subscriber.boolean
isClosed()
Check if this subscriber holder has been closed.boolean
register
(Flow.Subscriber<? super T> subscriber) Register a new subscriber.
-
Constructor Details
-
SingleSubscriberHolder
Deprecated, for removal: This API element is subject to removal in a future version.usecreate()
instead.This constructor should not be exposed.
-
-
Method Details
-
create
Create a new instance.- Type Parameters:
T
- type of the subscriber- Returns:
- a new instance to use as a subscriber holder
-
register
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'ssubscriber.onError
method.- Parameters:
subscriber
- subscriber to be registered in the holder.- Returns:
true
if the subscriber was successfully registered,false
otherwise.
-
close
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.- Parameters:
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.
- Returns:
- registered subscriber.
- Throws:
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.- Returns:
true
if the holder is closed,false
otherwise.
-
create()
instead.