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 enum
private static class
private static class
private static class
private static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final Executor
private final ConcurrentLinkedQueue
<AsyncSubscriber.Signal> private final AtomicBoolean
private Subscription
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate final void
done()
private void
private void
handleOnError
(Throwable error) private final void
handleOnNext
(T element) private final void
final void
Successful terminal state.final void
Failed terminal state.final void
Data notification sent by thePublisher
in response to requests toSubscription.request(long)
.final void
Invoked after callingPublisher.subscribe(Subscriber)
.final void
run()
private void
signal
(AsyncSubscriber.Signal signal) private final void
protected void
protected void
protected 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:Subscriber
Invoked after callingPublisher.subscribe(Subscriber)
.No data will start flowing until
Subscription.request(long)
is invoked.It is the responsibility of this
Subscriber
instance to callSubscription.request(long)
whenever more data is wanted.The
Publisher
will send notifications only in response toSubscription.request(long)
.- Specified by:
onSubscribe
in interfaceSubscriber<T>
- Parameters:
s
- theSubscription
that allows requesting data viaSubscription.request(long)
-
onNext
Description copied from interface:Subscriber
Data notification sent by thePublisher
in response to requests toSubscription.request(long)
.- Specified by:
onNext
in interfaceSubscriber<T>
- Parameters:
element
- the element signaled
-
onError
Description copied from interface:Subscriber
Failed terminal state.No further events will be sent even if
Subscription.request(long)
is invoked again.- Specified by:
onError
in interfaceSubscriber<T>
- Parameters:
t
- the throwable signaled
-
onComplete
public final void onComplete()Description copied from interface:Subscriber
Successful terminal state.No further events will be sent even if
Subscription.request(long)
is invoked again.- Specified by:
onComplete
in interfaceSubscriber<T>
-
run
public final void run() -
signal
-
tryScheduleToExecute
private final void tryScheduleToExecute()
-