T - the type of items the Subscriber expects to observepublic abstract class Subscriber<T> extends java.lang.Object implements Observer<T>, Subscription
After a Subscriber calls an Observable's subscribe method, the
Observable calls the Subscriber's Observer.onNext(T) method to emit items. A well-behaved
Observable will call a Subscriber's Observer.onCompleted() method exactly once or the Subscriber's
Observer.onError(java.lang.Throwable) method exactly once.
| Modifier | Constructor and Description |
|---|---|
protected |
Subscriber() |
protected |
Subscriber(Subscriber<?> op) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Subscription s)
Adds a
Subscription to this Subscriber's list of subscriptions if this list is not marked as
unsubscribed. |
boolean |
isUnsubscribed()
Indicates whether this Subscriber has unsubscribed from its list of subscriptions.
|
void |
onStart()
This method is invoked when the Subscriber and Observable have been connected but the Observable has
not yet begun to emit items or send notifications to the Subscriber.
|
protected void |
request(long n)
Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.
|
void |
setProducer(Producer producer) |
void |
unsubscribe()
Stops the receipt of notifications on the
Subscriber that was registered when this Subscription
was received. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonCompleted, onError, onNextprotected Subscriber()
protected Subscriber(Subscriber<?> op)
public final void add(Subscription s)
Subscription to this Subscriber's list of subscriptions if this list is not marked as
unsubscribed. If the list is marked as unsubscribed, add will indicate this by
explicitly unsubscribing the new Subscription as well.s - the Subscription to addpublic final void unsubscribe()
SubscriptionSubscriber that was registered when this Subscription
was received.
This allows unregistering an Subscriber before it has finished receiving all events (i.e. before
onCompleted is called).
unsubscribe in interface Subscriptionpublic final boolean isUnsubscribed()
isUnsubscribed in interface Subscriptiontrue if this Subscriber has unsubscribed from its subscriptions, false otherwisepublic void onStart()
protected final void request(long n)
Long.MAX_VALUE to this
method.
Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then
Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at
Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example,
the code below may result in Long.MAX_VALUE requests being actioned only.
request(100); request(Long.MAX_VALUE-1);
n - the maximum number of items you want the Observable to emit to the Subscriber at this time, or
Long.MAX_VALUE if you want the Observable to emit items at its own pacejava.lang.IllegalArgumentException - if n is negativepublic void setProducer(Producer producer)
producer -