Class ConcurrentSubscription
java.lang.Object
io.servicetalk.concurrent.internal.ConcurrentSubscription
- All Implemented Interfaces:
Cancellable,PublisherSource.Subscription
This class prevents concurrent invocation of
PublisherSource.Subscription methods and preserves the
Reactive Streams, 2.7
rule when there is a possibility of concurrency.-
Field Summary
Fields inherited from interface io.servicetalk.concurrent.Cancellable
IGNORE_CANCEL -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConcurrentSubscription(PublisherSource.Subscription subscription) New instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Sends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellableis not interested in the outcome of the execution.voidrequest(long n) Requestsnmore items from the associatedPublisherSourcefor the associatedPublisherSource.Subscriber.static ConcurrentSubscriptionwrap(PublisherSource.Subscription subscription) Wrap aPublisherSource.Subscriptionto make it thread safe when concurrent access may exists betweenPublisherSource.Subscription.request(long)andCancellable.cancel().
-
Constructor Details
-
ConcurrentSubscription
New instance.- Parameters:
subscription-PublisherSource.Subscriptionto wrap.
-
-
Method Details
-
wrap
Wrap aPublisherSource.Subscriptionto make it thread safe when concurrent access may exists betweenPublisherSource.Subscription.request(long)andCancellable.cancel().- Parameters:
subscription- The subscription to wrap.- Returns:
- A
PublisherSource.Subscriptionthat will enforce the threading constraints in a concurrent environment.
-
request
public void request(long n) Description copied from interface:PublisherSource.SubscriptionRequestsnmore items from the associatedPublisherSourcefor the associatedPublisherSource.Subscriber.See Reactive Streams specifications for the rules about how and when this method will be invoked.
- Specified by:
requestin interfacePublisherSource.Subscription- Parameters:
n- Number of items to request.
-
cancel
public void cancel()Description copied from interface:CancellableSends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellableis not interested in the outcome of the execution.- Specified by:
cancelin interfaceCancellable
-