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

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

The newest version!
package org.infinispan.hotrod;

import java.util.Set;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.api.mutiny.MutinyCache;
import org.infinispan.api.mutiny.MutinyCaches;

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

/**
 * @since 14.0
 **/
public class HotRodMutinyCaches implements MutinyCaches {
   private final HotRod hotrod;

   HotRodMutinyCaches(HotRod hotrod) {
      this.hotrod = hotrod;
   }

   @Override
   public  Uni> create(String name, CacheConfiguration cacheConfiguration) {
      return Uni.createFrom().completionStage(() -> hotrod.transport.getRemoteCache(name))
            .map(r -> new HotRodMutinyCache<>(hotrod, r));
   }

   @Override
   public  Uni> create(String name, String template) {
      return Uni.createFrom().completionStage(() -> hotrod.transport.getRemoteCache(name))
            .map(r -> new HotRodMutinyCache<>(hotrod, r));
   }

   @Override
   public  Uni> get(String name) {
      return Uni.createFrom().completionStage(() -> hotrod.transport.getRemoteCache(name))
            .map(r -> new HotRodMutinyCache<>(hotrod, r));
   }

   @Override
   public Uni remove(String name) {
      return Uni.createFrom().completionStage(() -> hotrod.transport.removeCache(name));
   }

   @Override
   public Multi names() {
      return Multi.createFrom().deferred(() -> toMulti(hotrod.transport.getCacheNames()));
   }

   @Override
   public Uni createTemplate(String name, CacheConfiguration cacheConfiguration) {
      return null;
   }

   @Override
   public Uni removeTemplate(String name) {
      return null;
   }

   @Override
   public Multi templateNames() {
      return Multi.createFrom().deferred(() -> toMulti(hotrod.transport.getTemplateNames()));
   }

   private Multi toMulti(CompletionStage> cs) {
      return Multi.createFrom().completionStage(cs).onItem().transformToIterable(Function.identity());
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy