public class ReadStreamSubscriber<R,J> extends Subscriber<R> implements ReadStream<J>
Subscriber that turns an Observable into a ReadStream.
The stream implements the pause() and resume() operation by maintaining
a buffer of BUFFER_SIZE elements between the Observable and the ReadStream.
When the subscriber is created it requests 0 elements to activate the subscriber's back-pressure.
Setting the handler initially on the ReadStream triggers a request of BUFFER_SIZE elements.
When the item buffer is half empty, new elements are requested to fill the buffer back to BUFFER_SIZE
elements.
The #endHandler(Handler is called when the Observable is completed or has failed and
no pending elements, emitted before the completion or failure, are still in the buffer, i.e the handler
is not called when the stream is paused.
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE |
| Constructor and Description |
|---|
ReadStreamSubscriber(java.util.function.Function<R,J> adapter) |
| Modifier and Type | Method and Description |
|---|---|
static <R,J> ReadStream<J> |
asReadStream(Observable<R> observable,
java.util.function.Function<R,J> adapter) |
ReadStream<J> |
endHandler(Handler<Void> handler)
Set an end handler.
|
ReadStream<J> |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
ReadStream<J> |
handler(Handler<J> handler)
Set a data handler.
|
void |
onCompleted() |
void |
onError(Throwable e) |
void |
onNext(R item) |
ReadStream<J> |
pause()
Pause the
ReadSupport. |
ReadStream<J> |
resume()
Resume reading.
|
add, isUnsubscribed, onStart, request, setProducer, unsubscribepublic static final int BUFFER_SIZE
public ReadStreamSubscriber(java.util.function.Function<R,J> adapter)
public static <R,J> ReadStream<J> asReadStream(Observable<R> observable, java.util.function.Function<R,J> adapter)
public ReadStream<J> handler(Handler<J> handler)
ReadStreamhandler in interface ReadStream<J>public ReadStream<J> pause()
ReadStreamReadSupport. While it's paused, no data will be sent to the dataHandlerpause in interface ReadStream<J>public ReadStream<J> resume()
ReadStreamReadSupport has been paused, reading will recommence on it.resume in interface ReadStream<J>public ReadStream<J> endHandler(Handler<Void> handler)
ReadStreamendHandler in interface ReadStream<J>public ReadStream<J> exceptionHandler(Handler<Throwable> handler)
ReadStreamexceptionHandler in interface ReadStream<J>exceptionHandler in interface StreamBasehandler - the exception handlerpublic void onCompleted()
onCompleted in interface Observer<R>Copyright © 2018 Eclipse. All rights reserved.