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 class
AsyncIterablePublisher.Cancel
(package private) static class
AsyncIterablePublisher.Request
(package private) static class
AsyncIterablePublisher.Send
(package private) static interface
AsyncIterablePublisher.Signal
(package private) static class
AsyncIterablePublisher.Subscribe
(package private) class
AsyncIterablePublisher.SubscriptionImpl
-
Field Summary
Fields Modifier and Type Field Description private int
batchSize
private static int
DEFAULT_BATCHSIZE
private java.lang.Iterable<T>
elements
private java.util.concurrent.Executor
executor
-
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 void
subscribe(Subscriber<? super T> s)
RequestPublisher
to 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:Publisher
RequestPublisher
to start streaming data.This is a "factory method" and can be called multiple times, each time starting a new
Subscription
.Each
Subscription
will work for only a singleSubscriber
.A
Subscriber
should only subscribe once to a singlePublisher
.If the
Publisher
rejects the subscription attempt or otherwise fails it will signal the error viaSubscriber.onError(Throwable)
.- Specified by:
subscribe
in interfacePublisher<T>
- Parameters:
s
- theSubscriber
that will consume signals from thisPublisher
-
-