T - the published item typepublic class SubmissionPublisher<T> extends Object implements Flow.Publisher<T>, AutoCloseable
Flow.Publisher that asynchronously issues submitted
(non-null) items to current subscribers until it is closed.| Constructor and Description |
|---|
SubmissionPublisher()
Creates a new SubmissionPublisher using the current thread for delivery
to subscribers, with maximum buffer capacity of
Flow.defaultBufferSize(). |
SubmissionPublisher(Executor executor,
int maxBufferCapacity)
Creates a new SubmissionPublisher using the given Executor for
async delivery to subscribers, with the given maximum buffer size
for each subscriber.
|
SubmissionPublisher(int maxBufferCapacity)
Creates a new SubmissionPublisher using the current thread for delivery
to subscribers, with the given maximum buffer size for each subscriber.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
closeExceptionally(Throwable error)
Unless already closed, issues
onError signals to current
subscribers with the given error, and disallows subsequent
attempts to publish. |
int |
getNumberOfSubscribers()
Returns the number of current subscribers.
|
boolean |
hasSubscribers()
Returns true if this publisher has any subscribers.
|
void |
offer(T item,
BiPredicate<Flow.Subscriber<? super T>,? super T> onDrop)
Publishes the given item to each current subscriber.
|
void |
submit(T item)
Publishes the given item to each current subscriber.
|
void |
subscribe(Flow.Subscriber<? super T> subscriber)
Adds the given Subscriber.
|
public SubmissionPublisher(Executor executor, int maxBufferCapacity)
executor - the executor to use for async delivery,
supporting creation of at least one independent threadmaxBufferCapacity - the maximum capacity for each
subscriber's bufferIllegalArgumentException - if maxBufferCapacity not
positivepublic SubmissionPublisher(int maxBufferCapacity)
maxBufferCapacity - the maximum capacity for each
subscriber's bufferIllegalArgumentException - if maxBufferCapacity notpublic SubmissionPublisher()
Flow.defaultBufferSize().public void subscribe(Flow.Subscriber<? super T> subscriber)
subscribe in interface Flow.Publisher<T>subscriber - the subscriberNullPointerException - if subscriber is nullpublic void submit(T item)
item - the (non-null) item to publishNullPointerException - if item is nullpublic void offer(T item, BiPredicate<Flow.Subscriber<? super T>,? super T> onDrop)
item - the (non-null) item to publishonDrop - not supported in the current implementationNullPointerException - if item is nullpublic void closeExceptionally(Throwable error)
onError signals to current
subscribers with the given error, and disallows subsequent
attempts to publish. Future subscribers also receive the given
error. Upon return, this method does NOT guarantee
that all subscribers have yet completed.error - the onError argument sent to subscribersNullPointerException - if error is nullpublic void close()
close in interface AutoCloseablepublic int getNumberOfSubscribers()
public boolean hasSubscribers()
Copyright © 2018–2019 Oracle Corporation. All rights reserved.