All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.reactive.RxJavaInterop Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.reactive;

import java.util.Map;

import org.infinispan.commons.util.Util;
import org.reactivestreams.Publisher;

import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;

/**
 * Static factory class that provides methods to obtain commonly used instances for interoperation between RxJava
 * and standard JRE.
 * @author wburns
 * @since 10.0
 */
public class RxJavaInterop {
   private RxJavaInterop() { }

   /**
    * Provides a {@link Function} that can be used to convert from an instance of {@link java.util.Map.Entry} to
    * the key of the entry. This is useful for the instance passed to a method like {@link Flowable#map(Function)}.
    * @param  key type
    * @param  value type
    * @return rxjava function to convert from a Map.Entry to its key.
    */
   public static  Function, K> entryToKeyFunction() {
      return (Function) entryToKeyFunction;
   }

   public static  Function> cacheExceptionWrapper() {
      return (Function) wrapThrowable;
   }

   public static  Function identityFunction() {
      return (Function) identityFunction;
   }

   public static  Consumer emptyConsumer() {
      return (Consumer) emptyConsumer;
   }

   private static final Function identityFunction = i -> i;
   private static final Consumer emptyConsumer = ignore -> {};
   private static final Function, Object> entryToKeyFunction = Map.Entry::getKey;
   private static final Function> wrapThrowable = t -> Flowable.error(Util.rewrapAsCacheException(t));
}