Class RxUtils

java.lang.Object
org.aksw.commons.rx.util.RxUtils

public class RxUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    static final Object
    A 'poison' is an object that serves as an end marker on blocking queues
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static <T> io.reactivex.rxjava3.core.FlowableTransformer<T,T>
    counter(String name, long interval)
     
    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> T
     
    static <T> void
    put(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 subscriber
    static <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>
    safeMaybe(Callable<T> action)
    If something goes wrong when running the wrapped action then log an error return an empty maybe
    static <T> Stream<T>
    stream(io.reactivex.rxjava3.core.Flowable<T> flowable)
    Create a stream that must eventually be closed from a Flowable.
    static <T> T
    take(io.reactivex.rxjava3.operators.SimpleQueue<T> queue)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POISON

      public static final Object POISON
      A 'poison' is an object that serves as an end marker on blocking queues
    • nameMap

      public static Map<String,AtomicInteger> nameMap
  • Constructor Details

    • RxUtils

      public RxUtils()
  • Method Details

    • stream

      public static <T> Stream<T> stream(io.reactivex.rxjava3.core.Flowable<T> flowable)
      Create a stream that must eventually be closed from a Flowable. If closing cannot be ensured then it is most likely preferrable to use flowable.toList().blockingGet().stream(). Example Usage:
       try (Stream stream : RxUtils.stream(flowable)) {
          ...
       }
       
    • safeMaybe

      public static <T> io.reactivex.rxjava3.core.Maybe<T> safeMaybe(Callable<T> action)
      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

      public static <T> T take(io.reactivex.rxjava3.operators.SimpleQueue<T> queue) throws Throwable
      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

      public static <T> io.reactivex.rxjava3.core.FlowableTransformer<BlockingQueue<T>,T> 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 -