public class RxHelper extends Object
Constructor and Description |
---|
RxHelper() |
Modifier and Type | Method and Description |
---|---|
static Scheduler |
blockingScheduler(Vertx vertx)
Create a scheduler for a
Vertx object, actions can be blocking, they are not executed
on Vertx event loop. |
static 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()
|
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 Scheduler |
scheduler(Context context)
Create a scheduler for a
Context , actions are executed on the event loop of this context. |
static Scheduler |
scheduler(Vertx vertx)
Create a scheduler for a
Vertx object, actions are executed on the event loop. |
static RxJavaSchedulersHook |
schedulerHook(Context context)
Create a scheduler hook for a
Context object, the RxJavaSchedulersHook.getIOScheduler()
uses a blocking scheduler. |
static 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(Action1<T> onNext)
Adapt an item callback as a
Handler<AsyncResult<T>> . |
static <T> Handler<AsyncResult<T>> |
toFuture(Action1<T> onNext,
Action1<Throwable> onError)
Adapt an item callback and an error callback as a
Handler<AsyncResult<T>> . |
static <T> Handler<AsyncResult<T>> |
toFuture(Action1<T> onNext,
Action1<Throwable> onError,
Action0 onComplete)
Adapt an item callback and an error callback as a
Handler<AsyncResult<T>> . |
static <T> Handler<AsyncResult<T>> |
toFuture(Observer<T> observer)
Adapt a
Subscriber as a Handler<AsyncResult<T>>; . |
static <T> Handler<T> |
toHandler(Action1<T> onNext)
Adapt an item callback as a
Handler<T> . |
static <T> Handler<T> |
toHandler(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(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> Observable<T> |
toObservable(ReadStream<T> stream)
Adapts a Vert.x
io.vertx.core.streams.ReadStream to an RxJava Observable . |
static <T,R> 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> 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> 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(Observable<T> observable)
Adapts an RxJava
Observable to a Vert.x io.vertx.core.streams.ReadStream . |
static <T> Subscriber<T> |
toSubscriber(Handler<AsyncResult<T>> handler)
Adapts a Vert.x
Handler<AsyncResult<T>> to an RxJava Subscriber . |
static <T> WriteStreamSubscriber<T> |
toSubscriber(WriteStream<T> stream)
Adapts a Vert.x
WriteStream to an RxJava Subscriber . |
static <R,T> WriteStreamSubscriber<R> |
toSubscriber(WriteStream<T> stream,
java.util.function.Function<R,T> mapping)
Like
toSubscriber(WriteStream) , except the provided mapping function is applied to each Observable item. |
static <T> 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> Observable.Operator<T,Buffer> |
unmarshaller(Class<T> mappedType,
ObjectCodec mapper)
Returns a unmarshaller for the specified java type as a
Observable.Operator instance given the
the provided ObjectMapper
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> 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. |
static <T> Observable.Operator<T,Buffer> |
unmarshaller(TypeReference<T> mappedTypeRef,
ObjectCodec mapper)
Returns a unmarshaller for the specified java type as a
Observable.Operator instance given the
the provided ObjectMapper
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. |
public static <T> Subscriber<T> toSubscriber(Handler<AsyncResult<T>> handler)
Handler<AsyncResult<T>>
to an RxJava Subscriber
.
The returned subscriber can be subscribed to an Observable.subscribe(Subscriber)
or
Single.subscribe(Subscriber)
.
handler
- the handler to adaptpublic static <T> ReadStream<T> toReadStream(Observable<T> observable)
Observable
to a Vert.x io.vertx.core.streams.ReadStream
. The returned
readstream will be subscribed to the Observable
.observable
- the observable to adaptpublic static <T> Observable<T> toObservable(ReadStream<T> stream)
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:
stream
- the stream to adaptpublic static <T> Observable<T> toObservable(ReadStream<T> stream, int maxBufferSize)
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:
stream
- the stream to adaptmaxBufferSize
- the max size of the buffer used when back-pressure is activepublic static <T,R> Observable<R> toObservable(ReadStream<T> stream, java.util.function.Function<T,R> adapter)
toObservable(ReadStream)
but with a function that adapts the items.public static <T,R> Observable<R> toObservable(ReadStream<T> stream, java.util.function.Function<T,R> adapter, int maxBufferSize)
toObservable(ReadStream, int)
but with a function that adapts the items.public static <T> ObservableFuture<T> observableFuture()
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.public static <T> ObservableHandler<T> observableHandler()
ObservableHandler<T>
object: an Observable
implementation
implementing Handler<T>
. When the event handler completes, the observable
will produce the event and complete immediatly after.public static <T> ObservableHandler<T> observableHandler(boolean multi)
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.multi
- true if the handler can emit multiple eventspublic static <T> Handler<AsyncResult<T>> toFuture(Observer<T> observer)
Subscriber
as a Handler<AsyncResult<T>>;
.observer
- the subscriber to adaptHandler<AsyncResult<T>>
public static <T> Handler<T> toHandler(Observer<T> observer)
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.observer
- the subscriber to adaptHandler<T>
public static <T> Handler<T> toHandler(Observer<T> observer, boolean multi)
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.observer
- the subscriber to adaptmulti
- true if the handler can emit multiple eventsHandler<T>
public static <T> Handler<AsyncResult<T>> toFuture(Action1<T> onNext)
Handler<AsyncResult<T>>
.onNext
- the Action1<T>
you have designed to accept the resolution from the Handler<AsyncResult<T>>
Handler<AsyncResult<T>>
public static <T> Handler<T> toHandler(Action1<T> onNext)
Handler<T>
.onNext
- the Action1<T>
you have designed to accept the resolution from the Handler<T>
Handler<T>
public static <T> Handler<AsyncResult<T>> toFuture(Action1<T> onNext, Action1<Throwable> onError)
Handler<AsyncResult<T>>
.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>>
Handler<AsyncResult<T>>
public static <T> Handler<AsyncResult<T>> toFuture(Action1<T> onNext, Action1<Throwable> onError, Action0 onComplete)
Handler<AsyncResult<T>>
.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>>
Handler<AsyncResult<T>>
public static Scheduler scheduler(Vertx vertx)
Vertx
object, actions are executed on the event loop.vertx
- the vertx objectpublic static Scheduler scheduler(Context context)
Context
, actions are executed on the event loop of this context.context
- the context objectpublic static Scheduler blockingScheduler(Vertx vertx)
Vertx
object, actions can be blocking, they are not executed
on Vertx event loop.vertx
- the vertx objectpublic static Scheduler blockingScheduler(Vertx vertx, boolean ordered)
Vertx
object, actions can be blocking, they are not executed
on Vertx event loop.vertx
- the vertx objectordered
- 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
guaranteespublic static RxJavaSchedulersHook schedulerHook(Context context)
Context
object, the RxJavaSchedulersHook.getIOScheduler()
uses a blocking scheduler.context
- the context objectpublic static RxJavaSchedulersHook schedulerHook(Vertx vertx)
Vertx
object, the RxJavaSchedulersHook.getIOScheduler()
uses a blocking scheduler.vertx
- the vertx objectpublic static <T> Observable.Operator<T,Buffer> unmarshaller(Class<T> mappedType, ObjectCodec mapper)
Observable.Operator
instance given the
the provided ObjectMapper
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.mappedType
- the type to unmarshallmapper
- the mapper to use to unmarshellpublic static <T> Observable.Operator<T,Buffer> unmarshaller(Class<T> mappedType)
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.mappedType
- the type to unmarshallpublic static <T> Observable.Operator<T,Buffer> unmarshaller(TypeReference<T> mappedTypeRef)
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.mappedTypeRef
- the type reference to unmarshallpublic static <T> Observable.Operator<T,Buffer> unmarshaller(TypeReference<T> mappedTypeRef, ObjectCodec mapper)
Observable.Operator
instance given the
the provided ObjectMapper
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.mappedTypeRef
- the type reference to unmarshallpublic static <T> WriteStreamSubscriber<T> toSubscriber(WriteStream<T> stream)
WriteStream
to an RxJava Subscriber
.
After subscription, the original WriteStream
handlers should not be used anymore as they will be used by the adapter.
stream
- the stream to adaptSubscriber
public static <R,T> WriteStreamSubscriber<R> toSubscriber(WriteStream<T> stream, java.util.function.Function<R,T> mapping)
toSubscriber(WriteStream)
, except the provided mapping
function is applied to each Observable
item.Copyright © 2024 Eclipse. All rights reserved.