public class JerseyPublisher<T> extends Object implements Flow.Publisher<T>
Flow.Publisher corresponding to reactive streams specification.
Delegates to SubmissionPublisher repackaged from jsr166 on JDK 8 or to JDK SubmissionPublisher.
| Modifier and Type | Class and Description |
|---|---|
static class |
JerseyPublisher.PublisherStrategy |
class |
JerseyPublisher.SubscriberWrapper<T> |
| Constructor and Description |
|---|
JerseyPublisher()
Creates a new JerseyPublisher using the
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with maximum buffer capacity of and default JerseyPublisher.PublisherStrategy,
which is JerseyPublisher.PublisherStrategy.BEST_EFFORT. |
JerseyPublisher(Executor executor)
Creates a new JerseyPublisher using the given
Executor for async delivery to subscribers, with the default
maximum buffer size of and default JerseyPublisher.PublisherStrategy, which is
JerseyPublisher.PublisherStrategy.BEST_EFFORT. |
JerseyPublisher(Executor executor,
int maxBufferCapacity,
JerseyPublisher.PublisherStrategy strategy)
Creates a new JerseyPublisher using the given
Executor for async delivery to subscribers, with the given
maximum buffer size for each subscriber and given JerseyPublisher.PublisherStrategy. |
JerseyPublisher(Executor executor,
JerseyPublisher.PublisherStrategy strategy)
Creates a new JerseyPublisher using the given
Executor for async delivery to subscribers, with the default
maximum buffer size of and given JerseyPublisher.PublisherStrategy. |
JerseyPublisher(int maxBufferCapacity)
Creates a new JerseyPublisher using the
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with specified maximum buffer capacity and default JerseyPublisher.PublisherStrategy, which is
JerseyPublisher.PublisherStrategy.BEST_EFFORT. |
JerseyPublisher(JerseyPublisher.PublisherStrategy strategy)
Creates a new JerseyPublisher using the
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with maximum buffer capacity of and given JerseyPublisher.PublisherStrategy. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Unless already closed, issues
onComplete() signals to current subscribers, and disallows subsequent
attempts to publish. |
void |
close(boolean cascading)
Same as
close() but with control as to whether registered subscribers should be
closed or not. |
void |
closeExceptionally(Throwable error)
Issues onError signals to current subscribers with the given error, and disallows subsequent attempts to publish.
|
CompletableFuture<Void> |
consume(Consumer<? super T> consumer)
Processes all published items using the given Consumer function.
|
int |
estimateMaximumLag()
Returns an estimate of the maximum number of items produced but not yet consumed among all current subscribers.
|
long |
estimateMinimumDemand()
Returns an estimate of the minimum number of items requested but not yet produced, among all current subscribers.
|
Throwable |
getClosedException()
Returns the exception associated with
closeExceptionally(java.lang.Throwable), or null if not closed or if closed normally. |
int |
getMaxBufferCapacity()
Returns the maximum per-subscriber buffer capacity.
|
int |
publish(T item)
Publishes the given item to all current subscribers by invoking its
onNext() method using Executor
provided as constructor parameter (or the default Executor if not provided). |
void |
subscribe(Flow.Subscriber<? super T> subscriber)
Adds the given Subscriber if possible.
|
public JerseyPublisher()
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with maximum buffer capacity of and default JerseyPublisher.PublisherStrategy,
which is JerseyPublisher.PublisherStrategy.BEST_EFFORT.public JerseyPublisher(JerseyPublisher.PublisherStrategy strategy)
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with maximum buffer capacity of and given JerseyPublisher.PublisherStrategy.strategy - publisher delivering strategypublic JerseyPublisher(Executor executor)
Executor for async delivery to subscribers, with the default
maximum buffer size of and default JerseyPublisher.PublisherStrategy, which is
JerseyPublisher.PublisherStrategy.BEST_EFFORT.executor - Executor the executor to use for async delivery,
supporting creation of at least one independent threadNullPointerException - if executor is nullIllegalArgumentException - if maxBufferCapacity not positivepublic JerseyPublisher(Executor executor, JerseyPublisher.PublisherStrategy strategy)
Executor for async delivery to subscribers, with the default
maximum buffer size of and given JerseyPublisher.PublisherStrategy.executor - Executor the executor to use for async delivery,
supporting creation of at least one independent threadstrategy - publisher delivering strategyNullPointerException - if executor is nullIllegalArgumentException - if maxBufferCapacity not positivepublic JerseyPublisher(int maxBufferCapacity)
ForkJoinPool.commonPool() for async delivery to subscribers
(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
each task), with specified maximum buffer capacity and default JerseyPublisher.PublisherStrategy, which is
JerseyPublisher.PublisherStrategy.BEST_EFFORT.maxBufferCapacity - the maximum capacity for each
subscriber's buffer (the enforced capacity may be rounded up to
the nearest power of two and/or bounded by the largest value
supported by this implementation; method getMaxBufferCapacity()
returns the actual value)public JerseyPublisher(Executor executor, int maxBufferCapacity, JerseyPublisher.PublisherStrategy strategy)
Executor for async delivery to subscribers, with the given
maximum buffer size for each subscriber and given JerseyPublisher.PublisherStrategy.executor - Executor the executor to use for async delivery,
supporting creation of at least one independent threadmaxBufferCapacity - the maximum capacity for each
subscriber's buffer (the enforced capacity may be rounded up to
the nearest power of two and/or bounded by the largest value
supported by this implementation; method getMaxBufferCapacity()
returns the actual value)strategy - publisher delivering strategyNullPointerException - if executor is nullIllegalArgumentException - if maxBufferCapacity not positivepublic void subscribe(Flow.Subscriber<? super T> subscriber)
Flow.PublisheronError
method is invoked with an IllegalStateException.
Otherwise, the Subscriber's onSubscribe method is
invoked with a new Flow.Subscription. Subscribers may
enable receiving items by invoking the request
method of this Subscription, and may unsubscribe by
invoking its cancel method.subscribe in interface Flow.Publisher<T>subscriber - the subscriberpublic CompletableFuture<Void> consume(Consumer<? super T> consumer)
onComplete(), or completed exceptionally upon any error, or an
exception is thrown by the Consumer, or the returned CompletableFuture is cancelled, in which case no further
items are processed.consumer - function to process all published dataCompletableFuture that is completed normally when the publisher signals onComplete,
and exceptionally upon any error or cancellationNullPointerException - if consumer is nullpublic int publish(T item)
onNext() method using Executor
provided as constructor parameter (or the default Executor if not provided).
Concrete behaviour is specified by JerseyPublisher.PublisherStrategy selected upon JerseyPublisher creation.
item - the (non-null) item to publish.IllegalStateException - if closedNullPointerException - if item is nullRejectedExecutionException - if thrown by Executorpublic void close()
onComplete() signals to current subscribers, and disallows subsequent
attempts to publish. Upon return, this method does NOT guarantee that all subscribers have yet
completed.public void close(boolean cascading)
close() but with control as to whether registered subscribers should be
closed or not.cascading - Boolean controlling whether to close subscribers or not.public void closeExceptionally(Throwable error)
error - the onError argument sent to subscribersNullPointerException - if error is nullpublic int estimateMaximumLag()
public long estimateMinimumDemand()
public Throwable getClosedException()
closeExceptionally(java.lang.Throwable), or null if not closed or if closed normally.nullpublic int getMaxBufferCapacity()
Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.