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.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
Constructors Modifier Constructor Description protected
ConcurrentSubscription(PublisherSource.Subscription subscription)
New instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Sends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellable
is not interested in the outcome of the execution.void
request(long n)
Requestsn
more items from the associatedPublisherSource
for the associatedPublisherSource.Subscriber
.static ConcurrentSubscription
wrap(PublisherSource.Subscription subscription)
Wrap aPublisherSource.Subscription
to 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.Subscription
to wrap.
-
-
Method Detail
-
wrap
public static ConcurrentSubscription wrap(PublisherSource.Subscription subscription)
Wrap aPublisherSource.Subscription
to make it thread safe when concurrent access may exists betweenPublisherSource.Subscription.request(long)
andCancellable.cancel()
.- Parameters:
subscription
- The subscription to wrap.- Returns:
- A
PublisherSource.Subscription
that will enforce the threading constraints in a concurrent environment.
-
request
public void request(long n)
Description copied from interface:PublisherSource.Subscription
Requestsn
more items from the associatedPublisherSource
for the associatedPublisherSource.Subscriber
.See Reactive Streams specifications for the rules about how and when this method will be invoked.
- Specified by:
request
in interfacePublisherSource.Subscription
- Parameters:
n
- Number of items to request.
-
cancel
public void cancel()
Description copied from interface:Cancellable
Sends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellable
is not interested in the outcome of the execution.- Specified by:
cancel
in interfaceCancellable
-
-