io.vertx.rx.java

## Class ReadStreamSubscriber<R,J>

- java.lang.Object
- - rx.Subscriber<R>
  - - io.vertx.rx.java.ReadStreamSubscriber<R,J>

- All Implemented Interfaces:
    ReadStream<J>, StreamBase, rx.Observer<R>, rx.Subscription

      public class ReadStreamSubscriber<R,J>
      extends rx.Subscriber<R>
      implements ReadStream<J>

  An RxJava `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.

  Author:
    Julien Viet

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BUFFER_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReadStreamSubscriber(java.util.function.Function<R,J> adapter)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <R,J> ReadStream<J>` | `asReadStream(rx.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.

    - ### Methods inherited from class rx.Subscriber

      `add, isUnsubscribed, onStart, request, setProducer, unsubscribe`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BUFFER_SIZE

          public static final int BUFFER_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ReadStreamSubscriber

          public ReadStreamSubscriber(java.util.function.Function<R,J> adapter)

  - ### Method Detail

    - #### asReadStream

          public static <R,J> ReadStream<J> asReadStream(rx.Observable<R> observable,
                                                         java.util.function.Function<R,J> adapter)

    - #### handler

          public ReadStream<J> handler(Handler<J> handler)

      Description copied from interface: `ReadStream`
      Set a data handler. As data is read, the handler will be called with the data.
      Specified by:
        `handler` in interface `ReadStream<J>`
      Returns:
        a reference to this, so the API can be used fluently

    - #### pause

          public ReadStream<J> pause()

      Description copied from interface: `ReadStream`
      Pause the `ReadSupport`. While it's paused, no data will be sent to the `dataHandler`
      Specified by:
        `pause` in interface `ReadStream<J>`
      Returns:
        a reference to this, so the API can be used fluently

    - #### resume

          public ReadStream<J> resume()

      Description copied from interface: `ReadStream`
      Resume reading. If the `ReadSupport` has been paused, reading will recommence on it.
      Specified by:
        `resume` in interface `ReadStream<J>`
      Returns:
        a reference to this, so the API can be used fluently

    - #### endHandler

          public ReadStream<J> endHandler(Handler<Void> handler)

      Description copied from interface: `ReadStream`
      Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.
      Specified by:
        `endHandler` in interface `ReadStream<J>`
      Returns:
        a reference to this, so the API can be used fluently

    - #### exceptionHandler

          public ReadStream<J> exceptionHandler(Handler<Throwable> handler)

      Description copied from interface: `ReadStream`
      Set an exception handler on the read stream.
      Specified by:
        `exceptionHandler` in interface `ReadStream<J>`
      Specified by:
        `exceptionHandler` in interface `StreamBase`
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### onCompleted

          public void onCompleted()

      Specified by:
        `onCompleted` in interface `rx.Observer<R>`

    - #### onError

          public void onError(Throwable e)

      Specified by:
        `onError` in interface `rx.Observer<R>`

    - #### onNext

          public void onNext(R item)

      Specified by:
        `onNext` in interface `rx.Observer<R>`

Copyright © 2017. All rights reserved.