public class ConcurrentSubscription extends java.lang.Object implements PublisherSource.Subscription
PublisherSource.Subscription and guards against multiple calls of Cancellable.cancel().
This class exists to enforce the
Reactive Streams, 2.7
rule. It also allows a custom Cancellable to be used in the event that there maybe multiple cancel
operations which are linked, but we still need to prevent concurrent invocation of the Cancellable.cancel()
and Cancellable.cancel() methods.
Be aware with invalid input to request(long) we don't attempt to enforce concurrency and rely upon the
subscription to enforce the specification
3.9 rule.
IGNORE_CANCEL| Modifier | Constructor and Description |
|---|---|
protected |
ConcurrentSubscription(PublisherSource.Subscription subscription)
New instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Sends a hint to the producer of the associated asynchronous execution that the consumer related to this
Cancellable is not interested in the outcome of the execution. |
void |
request(long n)
Requests
n more items from the associated PublisherSource for the associated
PublisherSource.Subscriber. |
static ConcurrentSubscription |
wrap(PublisherSource.Subscription subscription)
Wrap a
PublisherSource.Subscription to make it thread safe when concurrent access may exists between
PublisherSource.Subscription.request(long) and Cancellable.cancel(). |
protected ConcurrentSubscription(PublisherSource.Subscription subscription)
subscription - PublisherSource.Subscription to wrap.public static ConcurrentSubscription wrap(PublisherSource.Subscription subscription)
PublisherSource.Subscription to make it thread safe when concurrent access may exists between
PublisherSource.Subscription.request(long) and Cancellable.cancel().subscription - The subscription to wrap.PublisherSource.Subscription that will enforce the threading constraints in a concurrent environment.public void request(long n)
PublisherSource.Subscriptionn more items from the associated PublisherSource for the associated
PublisherSource.Subscriber.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
request in interface PublisherSource.Subscriptionn - Number of items to request.public void cancel()
CancellableCancellable is not interested in the outcome of the execution.cancel in interface Cancellable