io.vertx.rx.java

## Class RxHelper

- java.lang.Object
- - io.vertx.rx.java.RxHelper

-     public class RxHelper
      extends Object

  A set of helpers for RxJava and Vert.x.
  Author:
    Julien Viet

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RxHelper()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static rx.Scheduler` | `blockingScheduler(Vertx vertx)` Create a scheduler for a `Vertx` object, actions can be blocking, they are not executed on Vertx event loop.
    `static rx.Scheduler` | `blockingScheduler(Vertx vertx, boolean ordered)` Create a scheduler for a `Vertx` object, actions can be blocking, they are not executed on Vertx event loop.
    `static <T> ObservableFuture<T>` | `observableFuture()` Create a new `ObservableFuture<T>` object: an `Observable` implementation implementing `Handler<AsyncResult<T>>`.
    `static <T> ObservableHandler<T>` | `observableHandler()` Create a new `ObservableHandler<T>` object: an `Observable` implementation implementing `Handler<T>`.
    `static <T> ObservableHandler<T>` | `observableHandler(boolean multi)` Create a new `ObservableHandler<T>` object: an `Observable` implementation implementing `Handler<T>`. When parameter is false and the event handler completes, the observable will produce the event and complete immediatly after, as a single event is expected.
    `static rx.Scheduler` | `scheduler(Context context)` Create a scheduler for a `Context`, actions are executed on the event loop of this context.
    `static rx.Scheduler` | `scheduler(Vertx vertx)` Create a scheduler for a `Vertx` object, actions are executed on the event loop.
    `static rx.plugins.RxJavaSchedulersHook` | `schedulerHook(Context context)` Create a scheduler hook for a `Context` object, the `RxJavaSchedulersHook.getIOScheduler()` uses a blocking scheduler.
    `static rx.plugins.RxJavaSchedulersHook` | `schedulerHook(Vertx vertx)` Create a scheduler hook for a `Vertx` object, the `RxJavaSchedulersHook.getIOScheduler()` uses a blocking scheduler.
    `static <T> Handler<AsyncResult<T>>` | `toFuture(rx.functions.Action1<T> onNext)` Adapt an item callback as a `Handler<AsyncResult<T>>`.
    `static <T> Handler<AsyncResult<T>>` | `toFuture(rx.functions.Action1<T> onNext, rx.functions.Action1<Throwable> onError)` Adapt an item callback and an error callback as a `Handler<AsyncResult<T>>`.
    `static <T> Handler<AsyncResult<T>>` | `toFuture(rx.functions.Action1<T> onNext, rx.functions.Action1<Throwable> onError, rx.functions.Action0 onComplete)` Adapt an item callback and an error callback as a `Handler<AsyncResult<T>>`.
    `static <T> Handler<AsyncResult<T>>` | `toFuture(rx.Observer<T> observer)` Adapt a `Subscriber` as a `Handler<AsyncResult<T>>;`.
    `static <T> Handler<T>` | `toHandler(rx.functions.Action1<T> onNext)` Adapt an item callback as a `Handler<T>`.
    `static <T> Handler<T>` | `toHandler(rx.Observer<T> observer)` Adapt a `Subscriber` as a `Handler<T>;`. When the event handler completes, the observer will complete immediatly after the event is received, as a single event is expected.
    `static <T> Handler<T>` | `toHandler(rx.Observer<T> observer, boolean multi)` Adapt a `Subscriber` as a `Handler<T>;`. When parameter is false and the event handler completes, the observer will complete immediatly after the event is received, as a single event is expected.
    `static <T> rx.Observable<T>` | `toObservable(ReadStream<T> stream)` Adapts a Vert.x `io.vertx.core.streams.ReadStream` to an RxJava `Observable`.
    `static <T,R> rx.Observable<R>` | `toObservable(ReadStream<T> stream, java.util.function.Function<T,R> adapter)` Like `toObservable(ReadStream)` but with a function that adapts the items.
    `static <T,R> rx.Observable<R>` | `toObservable(ReadStream<T> stream, java.util.function.Function<T,R> adapter, int maxBufferSize)` Like `toObservable(ReadStream, int)` but with a function that adapts the items.
    `static <T> rx.Observable<T>` | `toObservable(ReadStream<T> stream, int maxBufferSize)` Adapts a Vert.x `io.vertx.core.streams.ReadStream` to an RxJava `Observable`.
    `static <T> ReadStream<T>` | `toReadStream(rx.Observable<T> observable)` Adapts an RxJava `Observable` to a Vert.x `io.vertx.core.streams.ReadStream`.
    `static <T> rx.Subscriber<T>` | `toSubscriber(Handler<AsyncResult<T>> handler)` Adapts an Vert.x `Handler<AsyncResult<T>>` to an RxJava `Subscriber`.
    `static <T> rx.Observable.Operator<T,Buffer>` | `unmarshaller(Class<T> mappedType)` Returns a json unmarshaller for the specified java type as a `Observable.Operator` instance. The marshaller can be used with the `Observable.lift(rx.Observable.Operator)` method to transform a Observable<Buffer> into a Observable<T>. The unmarshaller buffers the content until onComplete is called, then unmarshalling happens. Note that the returned observable will emit at most a single object.
    `static <T> rx.Observable.Operator<T,Buffer>` | `unmarshaller(TypeReference<T> mappedTypeRef)` Returns a json unmarshaller for the specified java type as a `Observable.Operator` instance. The marshaller can be used with the `Observable.lift(rx.Observable.Operator)` method to transform a Observable<Buffer> into a Observable<T>. The unmarshaller buffers the content until onComplete is called, then unmarshalling happens. Note that the returned observable will emit at most a single object.

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

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

- - ### Constructor Detail

    - #### RxHelper

          public RxHelper()

  - ### Method Detail

    - #### toSubscriber

          public static <T> rx.Subscriber<T> toSubscriber(Handler<AsyncResult<T>> handler)

      Adapts an Vert.x `Handler<AsyncResult<T>>` to an RxJava `Subscriber`.

      The returned subscriber can be subscribed to an `Observable.subscribe(Subscriber)` or `Single.subscribe(Subscriber)`.

      Parameters:
        `handler` - the handler to adapt
      Returns:
        the subscriber

    - #### toReadStream

          public static <T> ReadStream<T> toReadStream(rx.Observable<T> observable)

      Adapts an RxJava `Observable` to a Vert.x `io.vertx.core.streams.ReadStream`. The returned readstream will be subscribed to the `Observable`.

      Parameters:
        `observable` - the observable to adapt
      Returns:
        the adapted stream

    - #### toObservable

          public static <T> rx.Observable<T> toObservable(ReadStream<T> stream)

      Adapts a Vert.x `io.vertx.core.streams.ReadStream` to an RxJava `Observable`. After the stream is adapted to an observable, the original stream handlers should not be used anymore as they will be used by the observable adapter.

      The adapter supports reactive pull back-pressure.

      When back-pressure is enabled, a buffer of `ObservableReadStream.DEFAULT_MAX_BUFFER_SIZE` items is maintained:

      - When the buffer is full, the stream is paused
      - When the buffer is half empty, the stream is resumed
      Parameters:
        `stream` - the stream to adapt
      Returns:
        the adapted observable

    - #### toObservable

          public static <T> rx.Observable<T> toObservable(ReadStream<T> stream,
                                                          int maxBufferSize)

      Adapts a Vert.x `io.vertx.core.streams.ReadStream` to an RxJava `Observable`. After the stream is adapted to an observable, the original stream handlers should not be used anymore as they will be used by the observable adapter.

      The adapter supports reactive pull back-pressure.

      When back-pressure is enabled, a buffer of `maxBufferSize` items is maintained:

      - When the buffer is full, the stream is paused
      - When the buffer is half empty, the stream is resumed
      Parameters:
        `stream` - the stream to adapt
        `maxBufferSize` - the max size of the buffer used when back-pressure is active
      Returns:
        the adapted observable

    - #### toObservable

          public static <T,R> rx.Observable<R> toObservable(ReadStream<T> stream,
                                                            java.util.function.Function<T,R> adapter)

      Like `toObservable(ReadStream)` but with a function that adapts the items.

    - #### toObservable

          public static <T,R> rx.Observable<R> toObservable(ReadStream<T> stream,
                                                            java.util.function.Function<T,R> adapter,
                                                            int maxBufferSize)

      Like `toObservable(ReadStream, int)` but with a function that adapts the items.

    - #### observableFuture

          public static <T> ObservableFuture<T> observableFuture()

      Create a new `ObservableFuture<T>` object: an `Observable` implementation implementing `Handler<AsyncResult<T>>`. When the async result handler completes, the observable will produce the result and complete immediatly after, when it fails it will signal the error.
      Returns:
        the observable future.

    - #### observableHandler

          public static <T> ObservableHandler<T> observableHandler()

      Create a new `ObservableHandler<T>` object: an `Observable` implementation implementing `Handler<T>`. When the event handler completes, the observable will produce the event and complete immediatly after.
      Returns:
        the observable future.

    - #### observableHandler

          public static <T> ObservableHandler<T> observableHandler(boolean multi)

      Create a new `ObservableHandler<T>` object: an `Observable` implementation implementing `Handler<T>`.

      When parameter is false and the event handler completes, the observable will produce the event and complete immediatly after, as a single event is expected.
      Parameters:
        `multi` - true if the handler can emit multiple events
      Returns:
        the observable future.

    - #### toFuture

          public static <T> Handler<AsyncResult<T>> toFuture(rx.Observer<T> observer)

      Adapt a `Subscriber` as a `Handler<AsyncResult<T>>;`.
      Parameters:
        `observer` - the subscriber to adapt
      Returns:
        a `Handler<AsyncResult<T>>`

    - #### toHandler

          public static <T> Handler<T> toHandler(rx.Observer<T> observer)

      Adapt a `Subscriber` as a `Handler<T>;`.

      When the event handler completes, the observer will complete immediatly after the event is received, as a single event is expected.
      Parameters:
        `observer` - the subscriber to adapt
      Returns:
        a `Handler<T>`

    - #### toHandler

          public static <T> Handler<T> toHandler(rx.Observer<T> observer,
                                                 boolean multi)

      Adapt a `Subscriber` as a `Handler<T>;`.

      When parameter is false and the event handler completes, the observer will complete immediatly after the event is received, as a single event is expected.
      Parameters:
        `observer` - the subscriber to adapt
        `multi` - true if the handler can emit multiple events
      Returns:
        a `Handler<T>`

    - #### toFuture

          public static <T> Handler<AsyncResult<T>> toFuture(rx.functions.Action1<T> onNext)

      Adapt an item callback as a `Handler<AsyncResult<T>>`.
      Parameters:
        `onNext` - the `Action1<T>` you have designed to accept the resolution from the `Handler<AsyncResult<T>>`
      Returns:
        a `Handler<AsyncResult<T>>`

    - #### toHandler

          public static <T> Handler<T> toHandler(rx.functions.Action1<T> onNext)

      Adapt an item callback as a `Handler<T>`.
      Parameters:
        `onNext` - the `Action1<T>` you have designed to accept the resolution from the `Handler<T>`
      Returns:
        a `Handler<T>`

    - #### toFuture

          public static <T> Handler<AsyncResult<T>> toFuture(rx.functions.Action1<T> onNext,
                                                             rx.functions.Action1<Throwable> onError)

      Adapt an item callback and an error callback as a `Handler<AsyncResult<T>>`.
      Parameters:
        `onNext` - the `Action1<T>` you have designed to accept the resolution from the `Handler<AsyncResult<T>>`
        `onError` - the `Action1<Throwable>` you have designed to accept the eventual failure from the `Handler<AsyncResult<T>>`
      Returns:
        a `Handler<AsyncResult<T>>`

    - #### toFuture

          public static <T> Handler<AsyncResult<T>> toFuture(rx.functions.Action1<T> onNext,
                                                             rx.functions.Action1<Throwable> onError,
                                                             rx.functions.Action0 onComplete)

      Adapt an item callback and an error callback as a `Handler<AsyncResult<T>>`.
      Parameters:
        `onNext` - the `Action1<T>` you have designed to accept the resolution from the `Handler<AsyncResult<T>>`
        `onError` - the `Action1<Throwable>` you have designed to accept the eventual failure from the `Handler<AsyncResult<T>>`
        `onComplete` - the `Action0` you have designed to accept a completion notification from the `Handler<AsyncResult<T>>`
      Returns:
        a `Handler<AsyncResult<T>>`

    - #### scheduler

          public static rx.Scheduler scheduler(Vertx vertx)

      Create a scheduler for a `Vertx` object, actions are executed on the event loop.
      Parameters:
        `vertx` - the vertx object
      Returns:
        the scheduler

    - #### scheduler

          public static rx.Scheduler scheduler(Context context)

      Create a scheduler for a `Context`, actions are executed on the event loop of this context.
      Parameters:
        `context` - the context object
      Returns:
        the scheduler

    - #### blockingScheduler

          public static rx.Scheduler blockingScheduler(Vertx vertx)

      Create a scheduler for a `Vertx` object, actions can be blocking, they are not executed on Vertx event loop.
      Parameters:
        `vertx` - the vertx object
      Returns:
        the scheduler

    - #### blockingScheduler

          public static rx.Scheduler blockingScheduler(Vertx vertx,
                                                       boolean ordered)

      Create a scheduler for a `Vertx` object, actions can be blocking, they are not executed on Vertx event loop.
      Parameters:
        `vertx` - the vertx object
        `ordered` - if true then if when tasks are scheduled several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees
      Returns:
        the scheduler

    - #### schedulerHook

          public static rx.plugins.RxJavaSchedulersHook schedulerHook(Context context)

      Create a scheduler hook for a `Context` object, the `RxJavaSchedulersHook.getIOScheduler()` uses a blocking scheduler.
      Parameters:
        `context` - the context object
      Returns:
        the scheduler hook

    - #### schedulerHook

          public static rx.plugins.RxJavaSchedulersHook schedulerHook(Vertx vertx)

      Create a scheduler hook for a `Vertx` object, the `RxJavaSchedulersHook.getIOScheduler()` uses a blocking scheduler.
      Parameters:
        `vertx` - the vertx object
      Returns:
        the scheduler hook

    - #### unmarshaller

          public static <T> rx.Observable.Operator<T,Buffer> unmarshaller(Class<T> mappedType)

      Returns a json unmarshaller for the specified java type as a `Observable.Operator` instance.

      The marshaller can be used with the `Observable.lift(rx.Observable.Operator)` method to transform a Observable<Buffer> into a Observable<T>.

      The unmarshaller buffers the content until onComplete is called, then unmarshalling happens.

      Note that the returned observable will emit at most a single object.
      Parameters:
        `mappedType` - the type to unmarshall
      Returns:
        the unmarshaller operator

    - #### unmarshaller

          public static <T> rx.Observable.Operator<T,Buffer> unmarshaller(TypeReference<T> mappedTypeRef)

      Returns a json unmarshaller for the specified java type as a `Observable.Operator` instance.

      The marshaller can be used with the `Observable.lift(rx.Observable.Operator)` method to transform a Observable<Buffer> into a Observable<T>.

      The unmarshaller buffers the content until onComplete is called, then unmarshalling happens.

      Note that the returned observable will emit at most a single object.
      Parameters:
        `mappedTypeRef` - the type reference to unmarshall
      Returns:
        the unmarshaller operator

Copyright © 2017. All rights reserved.