public class ReadStreamSubscriber<R,J> extends rx.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(Function<R,J> adapter) |
Modifier and Type | Method and Description |
---|---|
static <R,J> ReadStream<J> |
asReadStream(rx.Observable<R> observable,
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.
|
public static final int BUFFER_SIZE
public static <R,J> ReadStream<J> asReadStream(rx.Observable<R> observable, Function<R,J> adapter)
public ReadStream<J> handler(Handler<J> handler)
ReadStream
handler
in interface ReadStream<J>
public ReadStream<J> pause()
ReadStream
ReadSupport
. While it's paused, no data will be sent to the dataHandler
pause
in interface ReadStream<J>
public ReadStream<J> resume()
ReadStream
ReadSupport
has been paused, reading will recommence on it.resume
in interface ReadStream<J>
public ReadStream<J> endHandler(Handler<Void> handler)
ReadStream
endHandler
in interface ReadStream<J>
public ReadStream<J> exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<J>
exceptionHandler
in interface StreamBase
handler
- the exception handlerpublic void onCompleted()
onCompleted
in interface rx.Observer<R>
Copyright © 2018. All rights reserved.