Class AsyncIterablePublisher<T>
- java.lang.Object
-
- org.reactivestreams.example.unicast.AsyncIterablePublisher<T>
-
- All Implemented Interfaces:
Publisher<T>
- Direct Known Subclasses:
HelperPublisher,InfiniteHelperPublisher,InfiniteIncrementNumberPublisher,NumberIterablePublisher
public class AsyncIterablePublisher<T> extends java.lang.Object implements Publisher<T>
AsyncIterablePublisher is an implementation of Reactive Streams `Publisher` which executes asynchronously, using a provided `Executor` and produces elements from a given `Iterable` in a "unicast" configuration to its `Subscribers`. NOTE: The code below uses a lot of try-catches to show the reader where exceptions can be expected, and where they are forbidden.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAsyncIterablePublisher.Cancel(package private) static classAsyncIterablePublisher.Request(package private) static classAsyncIterablePublisher.Send(package private) static interfaceAsyncIterablePublisher.Signal(package private) static classAsyncIterablePublisher.Subscribe(package private) classAsyncIterablePublisher.SubscriptionImpl
-
Field Summary
Fields Modifier and Type Field Description private intbatchSizeprivate static intDEFAULT_BATCHSIZEprivate java.lang.Iterable<T>elementsprivate java.util.concurrent.Executorexecutor
-
Constructor Summary
Constructors Constructor Description AsyncIterablePublisher(java.lang.Iterable<T> elements, int batchSize, java.util.concurrent.Executor executor)AsyncIterablePublisher(java.lang.Iterable<T> elements, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsubscribe(Subscriber<? super T> s)RequestPublisherto start streaming data.
-
-
-
Field Detail
-
DEFAULT_BATCHSIZE
private static final int DEFAULT_BATCHSIZE
- See Also:
- Constant Field Values
-
elements
private final java.lang.Iterable<T> elements
-
executor
private final java.util.concurrent.Executor executor
-
batchSize
private final int batchSize
-
-
Method Detail
-
subscribe
public void subscribe(Subscriber<? super T> s)
Description copied from interface:PublisherRequestPublisherto start streaming data.This is a "factory method" and can be called multiple times, each time starting a new
Subscription.Each
Subscriptionwill work for only a singleSubscriber.A
Subscribershould only subscribe once to a singlePublisher.If the
Publisherrejects the subscription attempt or otherwise fails it will signal the error viaSubscriber.onError(Throwable).- Specified by:
subscribein interfacePublisher<T>- Parameters:
s- theSubscriberthat will consume signals from thisPublisher
-
-