T - the type of the Subscriberpublic class SingleSubscriberHolder<T> extends Object
| Constructor and Description |
|---|
SingleSubscriberHolder() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Hard cancel - nothing is send to the subscriber but subscription is considered as canceled.
|
void |
close(Consumer<Flow.Subscriber<? super T>> completionHandler)
Mark the subscriber holder as closed.
|
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.
|
public boolean register(Flow.Subscriber<? super T> 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.public void close(Consumer<Flow.Subscriber<? super T>> completionHandler)
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 tryProcess 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).public void cancel()
public Flow.Subscriber<? super T> get() throws InterruptedException, ExecutionException
This method blocks indefinitely until a subscriber is registered or the holder has been closed.
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 interruptedpublic boolean isClosed()
true if the holder is closed, false otherwise.Copyright © 2018–2019 Oracle Corporation. All rights reserved.