Package org.aksw.commons.rx.util
Class RxUtils
java.lang.Object
org.aksw.commons.rx.util.RxUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconsume(io.reactivex.rxjava3.core.Flowable<?> flowable) Consume a flow by mapping it to empty maybes as long as there is no error.static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,T> static <I,O> io.reactivex.rxjava3.core.FlowableTransformer<I, O> createTransformer(Function<? super io.reactivex.rxjava3.core.FlowableEmitter<O>, ? extends io.reactivex.rxjava3.core.FlowableSubscriber<I>> fsSupp) Utils method to create a transformer from a function that takes a FlowableEmitter and yields a FlowableSubscriber from it.static <I,O> io.reactivex.rxjava3.core.FlowableTransformer<I, O> createTransformer(Function<? super io.reactivex.rxjava3.core.FlowableEmitter<O>, ? extends io.reactivex.rxjava3.core.FlowableSubscriber<I>> fsSupp, io.reactivex.rxjava3.core.BackpressureStrategy backpressureStrategy) static <T> io.reactivex.rxjava3.core.Flowable<T>fromBlockingQueue(BlockingQueue<T> queue, Predicate<? super T> isPoison) static <T> Tpoison()static <T> voidput(io.reactivex.rxjava3.operators.SimpleQueue<T> queue, T item) static <T> io.reactivex.rxjava3.core.FlowableTransformer<BlockingQueue<T>,T> Take items from the blocking queue and pass them on to the subscriberstatic <T> io.reactivex.rxjava3.core.FlowableTransformer<T,T> queuedObserveOn(io.reactivex.rxjava3.core.Scheduler scheduler, int capacity) static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,BlockingQueue<T>> queueProducer(int capacity) Map each item to the same blocking queue instance thereby appending that item to the queue.static <T> io.reactivex.rxjava3.core.Maybe<T>If something goes wrong when running the wrapped action then log an error return an empty maybestatic <T> Stream<T>stream(io.reactivex.rxjava3.core.Flowable<T> flowable) Create a stream that must eventually be closed from a Flowable.static <T> Ttake(io.reactivex.rxjava3.operators.SimpleQueue<T> queue)
-
Field Details
-
POISON
A 'poison' is an object that serves as an end marker on blocking queues -
nameMap
-
-
Constructor Details
-
RxUtils
public RxUtils()
-
-
Method Details
-
stream
Create a stream that must eventually be closed from a Flowable. If closing cannot be ensured then it is most likely preferrable to useflowable.toList().blockingGet().stream(). Example Usage:try (Stream
stream : RxUtils.stream(flowable)) { ... } -
safeMaybe
If something goes wrong when running the wrapped action then log an error return an empty maybe- Parameters:
action- A callable encapsulating some action- Returns:
- A maybe with the action's return value or empty
-
poison
public static <T> T poison() -
counter
public static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,T> counter(String name, long interval) -
put
public static <T> void put(io.reactivex.rxjava3.operators.SimpleQueue<T> queue, T item) throws InterruptedException - Throws:
InterruptedException
-
take
- Throws:
Throwable
-
queuedObserveOn
public static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,T> queuedObserveOn(io.reactivex.rxjava3.core.Scheduler scheduler, int capacity) -
queueProducer
public static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,BlockingQueue<T>> queueProducer(int capacity) Map each item to the same blocking queue instance thereby appending that item to the queue.- Type Parameters:
T-- Parameters:
capacity-- Returns:
-
fromBlockingQueue
public static <T> io.reactivex.rxjava3.core.Flowable<T> fromBlockingQueue(BlockingQueue<T> queue, Predicate<? super T> isPoison) -
queueConsumer
Take items from the blocking queue and pass them on to the subscriber- Type Parameters:
T-- Returns:
-
createTransformer
public static <I,O> io.reactivex.rxjava3.core.FlowableTransformer<I,O> createTransformer(Function<? super io.reactivex.rxjava3.core.FlowableEmitter<O>, ? extends io.reactivex.rxjava3.core.FlowableSubscriber<I>> fsSupp) Utils method to create a transformer from a function that takes a FlowableEmitter and yields a FlowableSubscriber from it. Used to slightly reduce boilerplate.- Type Parameters:
I-O-- Parameters:
fsSupp-- Returns:
-
createTransformer
public static <I,O> io.reactivex.rxjava3.core.FlowableTransformer<I,O> createTransformer(Function<? super io.reactivex.rxjava3.core.FlowableEmitter<O>, ? extends io.reactivex.rxjava3.core.FlowableSubscriber<I>> fsSupp, io.reactivex.rxjava3.core.BackpressureStrategy backpressureStrategy) -
consume
public static void consume(io.reactivex.rxjava3.core.Flowable<?> flowable) Consume a flow by mapping it to empty maybes as long as there is no error. On error emit a maybe that holds the occurred exception. This method underneath uses blockingGet on the single result.- Parameters:
flowable-
-