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

org.infinispan.hotrod.HotRodMutinyCache Maven / Gradle / Ivy

package org.infinispan.hotrod;

import java.util.Map;
import java.util.Set;

import org.infinispan.api.common.CacheEntry;
import org.infinispan.api.common.CacheEntryVersion;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
import org.infinispan.api.common.events.cache.CacheEntryEventType;
import org.infinispan.api.common.events.cache.CacheListenerOptions;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.api.mutiny.MutinyCache;
import org.infinispan.api.mutiny.MutinyCacheEntryProcessor;
import org.infinispan.api.mutiny.MutinyQuery;
import org.infinispan.api.mutiny.MutinyStreamingCache;
import org.infinispan.hotrod.impl.cache.RemoteCache;
import org.reactivestreams.FlowAdapters;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

/**
 * @since 14.0
 **/
public class HotRodMutinyCache implements MutinyCache {
   private final HotRod hotrod;
   private final RemoteCache remoteCache;

   HotRodMutinyCache(HotRod hotrod, RemoteCache remoteCache) {
      this.hotrod = hotrod;
      this.remoteCache = remoteCache;
   }

   @Override
   public String name() {
      return remoteCache.getName();
   }

   @Override
   public Uni configuration() {
      return Uni.createFrom().completionStage(remoteCache.configuration());
   }

   @Override
   public HotRodMutinyContainer container() {
      return hotrod.mutiny();
   }

   @Override
   public Uni get(K key, CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.get(key, options));
   }

   @Override
   public Uni> getEntry(K key, CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.getEntry(key, options));
   }

   @Override
   public Uni> putIfAbsent(K key, V value, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.putIfAbsent(key, value, options));
   }

   @Override
   public Uni setIfAbsent(K key, V value, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.setIfAbsent(key, value, options));
   }

   @Override
   public Uni> put(K key, V value, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.put(key, value, options));
   }

   @Override
   public Uni set(K key, V value, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.set(key, value, options));
   }

   @Override
   public Uni remove(K key, CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.remove(key, options));
   }

   @Override
   public Uni> getAndRemove(K key, CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.getAndRemove(key, options));
   }

   @Override
   public Multi keys(CacheOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.keys(options)));
   }

   @Override
   public Multi> entries(CacheOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.entries(options)));
   }

   @Override
   public Multi> getAll(Set keys, CacheOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.getAll(keys, options)));
   }

   @Override
   public Multi> getAll(CacheOptions options, K... keys) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.getAll(options, keys)));
   }

   @Override
   public Uni putAll(Multi> entries, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.putAll(FlowAdapters.toFlowPublisher(entries.convert().toPublisher()), options));
   }

   @Override
   public Uni putAll(Map map, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.putAll(map, options));
   }

   @Override
   public Uni replace(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.replace(key, value, version, options));
   }

   @Override
   public Uni> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.getOrReplaceEntry(key, value, version, options));
   }

   @Override
   public Multi removeAll(Set keys, CacheWriteOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.removeAll(keys, options)));
   }

   @Override
   public Multi removeAll(Multi keys, CacheWriteOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.removeAll(
            FlowAdapters.toFlowPublisher(keys.convert().toPublisher()), options)));
   }

   @Override
   public Multi> getAndRemoveAll(Multi keys, CacheWriteOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.getAndRemoveAll(
            FlowAdapters.toFlowPublisher(keys.convert().toPublisher()), options)));
   }

   @Override
   public Uni estimateSize(CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.estimateSize(options));
   }

   @Override
   public Uni clear(CacheOptions options) {
      return Uni.createFrom().completionStage(() -> remoteCache.clear(options));
   }

   @Override
   public  MutinyQuery query(String query, CacheOptions options) {
      return new HotRodMutinyQuery(query, options);
   }

   @Override
   public Multi> listen(CacheListenerOptions options, CacheEntryEventType... types) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(remoteCache.listen(options, types)));
   }

   @Override
   public  Multi> process(Set keys, MutinyCacheEntryProcessor processor, CacheOptions options) {
      return Multi.createFrom().publisher(FlowAdapters.toPublisher(
            remoteCache.process(keys, new MutinyToAsyncCacheEntryProcessor<>(processor), options)));
   }

   @Override
   public MutinyStreamingCache streaming() {
      return new HotRodMutinyStreamingCache(hotrod, remoteCache);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy