Class SyncSubscriber<T>
- java.lang.Object
-
- org.reactivestreams.example.unicast.SyncSubscriber<T>
-
- All Implemented Interfaces:
Subscriber<T>
public abstract class SyncSubscriber<T> extends java.lang.Object implements Subscriber<T>
SyncSubscriber is an implementation of Reactive Streams `Subscriber`, it runs synchronously (on the Publisher's thread) and 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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
done
private Subscription
subscription
-
Constructor Summary
Constructors Constructor Description SyncSubscriber()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
done()
void
onComplete()
Successful terminal state.void
onError(java.lang.Throwable t)
Failed terminal state.void
onNext(T element)
Data notification sent by thePublisher
in response to requests toSubscription.request(long)
.void
onSubscribe(Subscription s)
Invoked after callingPublisher.subscribe(Subscriber)
.protected abstract boolean
whenNext(T element)
-
-
-
Field Detail
-
subscription
private Subscription subscription
-
done
private boolean done
-
-
Method Detail
-
onSubscribe
public void onSubscribe(Subscription s)
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
public void onNext(T element)
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
-
done
private void done()
-
whenNext
protected abstract boolean whenNext(T element)
-
onError
public void onError(java.lang.Throwable t)
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 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>
-
-