Class ConcurrentSubscription
- java.lang.Object
-
- io.servicetalk.concurrent.internal.ConcurrentSubscription
-
- All Implemented Interfaces:
Cancellable,PublisherSource.Subscription
public class ConcurrentSubscription extends java.lang.Object implements PublisherSource.Subscription
This class prevents concurrent invocation ofPublisherSource.Subscriptionmethods 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
Constructors Modifier Constructor Description protectedConcurrentSubscription(PublisherSource.Subscription subscription)New instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()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 Detail
-
ConcurrentSubscription
protected ConcurrentSubscription(PublisherSource.Subscription subscription)
New instance.- Parameters:
subscription-PublisherSource.Subscriptionto wrap.
-
-
Method Detail
-
wrap
public static ConcurrentSubscription wrap(PublisherSource.Subscription subscription)
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
-
-