Class AsyncSubscriber<T>
java.lang.Object
org.reactivestreams.example.unicast.AsyncSubscriber<T>
- All Implemented Interfaces:
Runnable, Subscriber<T>
AsyncSubscriber is an implementation of Reactive Streams `Subscriber`,
it runs asynchronously (on an Executor), requests one element
at a time, and invokes a user-defined method to process each element.
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 ClassesModifier and TypeClassDescriptionprivate static enumprivate static classprivate static classprivate static classprivate static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final Executorprivate final ConcurrentLinkedQueue<AsyncSubscriber.Signal> private final AtomicBooleanprivate Subscription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate final voiddone()private voidprivate voidhandleOnError(Throwable error) private final voidhandleOnNext(T element) private final voidfinal voidSuccessful terminal state.final voidFailed terminal state.final voidData notification sent by thePublisherin response to requests toSubscription.request(long).final voidInvoked after callingPublisher.subscribe(Subscriber).final voidrun()private voidsignal(AsyncSubscriber.Signal signal) private final voidprotected voidprotected voidprotected abstract boolean
-
Field Details
-
subscription
-
done
private boolean done -
executor
-
inboundSignals
-
on
-
-
Constructor Details
-
AsyncSubscriber
-
-
Method Details
-
done
private final void done() -
whenNext
-
whenComplete
protected void whenComplete() -
whenError
-
handleOnSubscribe
-
handleOnNext
-
handleOnComplete
private void handleOnComplete() -
handleOnError
-
onSubscribe
Description copied from interface:SubscriberInvoked after callingPublisher.subscribe(Subscriber).No data will start flowing until
Subscription.request(long)is invoked.It is the responsibility of this
Subscriberinstance to callSubscription.request(long)whenever more data is wanted.The
Publisherwill send notifications only in response toSubscription.request(long).- Specified by:
onSubscribein interfaceSubscriber<T>- Parameters:
s- theSubscriptionthat allows requesting data viaSubscription.request(long)
-
onNext
Description copied from interface:SubscriberData notification sent by thePublisherin response to requests toSubscription.request(long).- Specified by:
onNextin interfaceSubscriber<T>- Parameters:
element- the element signaled
-
onError
Description copied from interface:SubscriberFailed terminal state.No further events will be sent even if
Subscription.request(long)is invoked again.- Specified by:
onErrorin interfaceSubscriber<T>- Parameters:
t- the throwable signaled
-
onComplete
public final void onComplete()Description copied from interface:SubscriberSuccessful terminal state.No further events will be sent even if
Subscription.request(long)is invoked again.- Specified by:
onCompletein interfaceSubscriber<T>
-
run
-
signal
-
tryScheduleToExecute
private final void tryScheduleToExecute()
-