|
| 1 | +package org.reactivestreams.spi; |
| 2 | + |
| 3 | +/** |
| 4 | + * A Subscriber receives elements from a {@link org.reactivestreams.spi.Publisher Publisher} based on the {@link org.reactivestreams.spi.Subscription Subscription} it has. |
| 5 | + * The Publisher may supply elements as they become available, the Subscriber signals demand via |
| 6 | + * {@link org.reactivestreams.spi.Subscription#requestMore(int) requestMore} and elements from when supply and demand are both present. |
| 7 | + */ |
| 8 | +public interface Subscriber<T> { |
| 9 | + |
| 10 | + /** |
| 11 | + * The {@link org.reactivestreams.spi.Publisher Publisher} generates a {@link org.reactivestreams.spi.Subscription Subscription} upon {@link org.reactivestreams.spi.Publisher#subscribe(org.reactivestreams.spi.Subscriber) subscribe} and passes |
| 12 | + * it on to the Subscriber named there using this method. The Publisher may choose to reject |
| 13 | + * the subscription request by calling {@link #onError onError} instead. |
| 14 | + * @param subscription The subscription which connects this subscriber to its publisher. |
| 15 | + */ |
| 16 | + public void onSubscribe(Subscription subscription); |
| 17 | + |
| 18 | + /** |
| 19 | + * The {@link org.reactivestreams.spi.Publisher Publisher} calls this method to pass one element to this Subscriber. The element |
| 20 | + * must not be <code>null</code>. The Publisher must not call this method more often than |
| 21 | + * the Subscriber has signaled demand for via the corresponding {@link org.reactivestreams.spi.Subscription Subscription}. |
| 22 | + * @param element The element that is passed from publisher to subscriber. |
| 23 | + */ |
| 24 | + public void onNext(T element); |
| 25 | + |
| 26 | + /** |
| 27 | + * The {@link org.reactivestreams.spi.Publisher Publisher} calls this method in order to signal that it terminated normally. |
| 28 | + * No more elements will be forthcoming and none of the Subscriber’s methods will be called hereafter. |
| 29 | + */ |
| 30 | + public void onComplete(); |
| 31 | + |
| 32 | + /** |
| 33 | + * The {@link org.reactivestreams.spi.Publisher Publisher} calls this method to signal that the stream of elements has failed |
| 34 | + * and is being aborted. The Subscriber should abort its processing as soon as possible. |
| 35 | + * No more elements will be forthcoming and none of the Subscriber’s methods will be called hereafter. |
| 36 | + * <p> |
| 37 | + * This method is not intended to pass validation errors or similar from Publisher to Subscriber |
| 38 | + * in order to initiate an orderly shutdown of the exchange; it is intended only for fatal |
| 39 | + * failure conditions which make it impossible to continue processing further elements. |
| 40 | + * @param cause An exception which describes the reason for tearing down this stream. |
| 41 | + */ |
| 42 | + public void onError(Throwable cause); |
| 43 | +} |
0 commit comments