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

org.infinispan.client.hotrod.impl.DelegatingRemoteCache Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.client.hotrod.impl;

import java.net.SocketAddress;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Function;

import javax.management.ObjectName;

import org.infinispan.client.hotrod.CacheTopologyInfo;
import org.infinispan.client.hotrod.DataFormat;
import org.infinispan.client.hotrod.Flag;
import org.infinispan.client.hotrod.MetadataValue;
import org.infinispan.client.hotrod.RemoteCacheContainer;
import org.infinispan.client.hotrod.ServerStatistics;
import org.infinispan.client.hotrod.StreamingRemoteCache;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.impl.operations.OperationsFactory;
import org.infinispan.client.hotrod.impl.operations.PingResponse;
import org.infinispan.client.hotrod.impl.operations.RetryAwareCompletionStage;
import org.infinispan.commons.util.CloseableIterator;
import org.infinispan.commons.util.CloseableIteratorCollection;
import org.infinispan.commons.util.CloseableIteratorSet;
import org.infinispan.commons.util.IntSet;
import org.infinispan.query.dsl.Query;
import org.reactivestreams.Publisher;

/**
 * Delegates all invocations to the provided underlying {@link InternalRemoteCache} but provides extensibility to intercept
 * when a method is invoked. Currently all methods are supported except for iterators produced from the
 * {@link #keyIterator(IntSet)} and {@link #entryIterator(IntSet)} which are known to invoke back into the delegate cache.
 * @param  key type
 * @param  value type
 */
public abstract class DelegatingRemoteCache extends RemoteCacheSupport implements InternalRemoteCache {
   protected final InternalRemoteCache delegate;

   protected DelegatingRemoteCache(InternalRemoteCache delegate) {
      this.delegate = delegate;
   }

   abstract  InternalRemoteCache newDelegatingCache(InternalRemoteCache innerCache);

   @Override
   public CompletableFuture putAllAsync(Map data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.putAllAsync(data, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture clearAsync() {
      return delegate.clearAsync();
   }

   @Override
   public ClientStatistics clientStatistics() {
      return delegate.clientStatistics();
   }

   @Override
   public ServerStatistics serverStatistics() {
      return delegate.serverStatistics();
   }

    @Override
    public CompletionStage serverStatisticsAsync() {
        return delegate.serverStatisticsAsync();
    }

    @Override
   public InternalRemoteCache withFlags(Flag... flags) {
      InternalRemoteCache newCache = delegate.withFlags(flags);
      if (newCache != delegate) {
         return newDelegatingCache(newCache);
      }
      return this;
   }

   @Override
   public RemoteCacheContainer getRemoteCacheContainer() {
      return delegate.getRemoteCacheContainer();
   }

   @Override
   public CompletableFuture> getAllAsync(Set keys) {
      return delegate.getAllAsync(keys);
   }

   @Override
   public String getProtocolVersion() {
      return delegate.getProtocolVersion();
   }

   @Override
   public void addClientListener(Object listener) {
      delegate.addClientListener(listener);
   }

   @Override
   public void addClientListener(Object listener, Object[] filterFactoryParams, Object[] converterFactoryParams) {
      delegate.addClientListener(listener, filterFactoryParams, converterFactoryParams);
   }

   @Override
   public void removeClientListener(Object listener) {
      delegate.removeClientListener(listener);
   }

   @Override
   public SocketAddress addNearCacheListener(Object listener, int bloomBits) {
      return delegate.addNearCacheListener(listener, bloomBits);
   }

   @Override
   public Set getListeners() {
      return delegate.getListeners();
   }

   @Override
   public  T execute(String taskName, Map params) {
      return delegate.execute(taskName, params);
   }

   @Override
   public CacheTopologyInfo getCacheTopologyInfo() {
      return delegate.getCacheTopologyInfo();
   }

   @Override
   public StreamingRemoteCache streaming() {
      return delegate.streaming();
   }

   @Override
   public  InternalRemoteCache withDataFormat(DataFormat dataFormat) {
      InternalRemoteCache newCache = delegate.withDataFormat(dataFormat);
      if (newCache != delegate) {
         return newDelegatingCache(newCache);
      }
      //noinspection unchecked
      return (InternalRemoteCache) this;
   }

   @Override
   public DataFormat getDataFormat() {
      return delegate.getDataFormat();
   }

   @Override
   public boolean isTransactional() {
      return delegate.isTransactional();
   }

   @Override
   public CompletableFuture putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.replaceAsync(key, oldValue, newValue, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture getAsync(K key) {
      return delegate.getAsync(key);
   }

   @Override
   public CompletableFuture> getWithMetadataAsync(K key) {
      return delegate.getWithMetadataAsync(key);
   }

   @Override
   public RetryAwareCompletionStage> getWithMetadataAsync(K key, SocketAddress preferredAddres) {
      return delegate.getWithMetadataAsync(key, preferredAddres);
   }

   @Override
   public boolean isEmpty() {
      return delegate.isEmpty();
   }

   @Override
   public boolean containsValue(Object value) {
      return delegate.containsValue(value);
   }

   @Override
   public CloseableIteratorSet keySet(IntSet segments) {
      return new RemoteCacheKeySet<>(this, segments);
   }

   @Override
   public CloseableIteratorCollection values(IntSet segments) {
      return new RemoteCacheValuesCollection<>(this, segments);
   }

   @Override
   public CloseableIteratorSet> entrySet(IntSet segments) {
      return new RemoteCacheEntrySet<>(this, segments);
   }

   @Override
   public CompletableFuture containsKeyAsync(K key) {
      return delegate.containsKeyAsync(key);
   }

   @Override
   public CompletableFuture putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.putAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture replaceWithVersionAsync(K key, V newValue, long version, long lifespanSeconds, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit) {
      return delegate.replaceWithVersionAsync(key, newValue, version, lifespanSeconds, lifespanTimeUnit, maxIdle, maxIdleTimeUnit);
   }

   @Override
   public CloseableIterator> retrieveEntries(String filterConverterFactory, Object[] filterConverterParams, Set segments, int batchSize) {
      return delegate.retrieveEntries(filterConverterFactory, filterConverterParams, segments, batchSize);
   }

   @Override
   public  Publisher> publishEntries(String filterConverterFactory, Object[] filterConverterParams, Set segments, int batchSize) {
      return delegate.publishEntries(filterConverterFactory, filterConverterParams, segments, batchSize);
   }

   @Override
   public CloseableIterator> retrieveEntriesByQuery(Query filterQuery, Set segments, int batchSize) {
      return delegate.retrieveEntriesByQuery(filterQuery, segments, batchSize);
   }

   @Override
   public  Publisher> publishEntriesByQuery(Query filterQuery, Set segments, int batchSize) {
      return delegate.publishEntriesByQuery(filterQuery, segments, batchSize);
   }

   @Override
   public CloseableIterator>> retrieveEntriesWithMetadata(Set segments, int batchSize) {
      return delegate.retrieveEntriesWithMetadata(segments, batchSize);
   }

   @Override
   public Publisher>> publishEntriesWithMetadata(Set segments, int batchSize) {
      return delegate.publishEntriesWithMetadata(segments, batchSize);
   }

   @Override
   public CompletableFuture removeAsync(Object key) {
      return delegate.removeAsync(key);
   }

   @Override
   public CompletableFuture removeAsync(Object key, Object value) {
      return delegate.removeAsync(key, value);
   }

   @Override
   public CompletableFuture removeWithVersionAsync(K key, long version) {
      return delegate.removeWithVersionAsync(key, version);
   }

   @Override
   public CompletableFuture mergeAsync(K key, V value, BiFunction remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
      return delegate.mergeAsync(key, value, remappingFunction, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
   }

   @Override
   public CompletableFuture computeAsync(K key, BiFunction remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.computeAsync(key, remappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture computeIfAbsentAsync(K key, Function mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.computeIfAbsentAsync(key, mappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public CompletableFuture computeIfPresentAsync(K key, BiFunction remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
      return delegate.computeIfPresentAsync(key, remappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
   }

   @Override
   public void replaceAll(BiFunction function) {
      delegate.replaceAll(function);
   }

   @Override
   public CompletableFuture sizeAsync() {
      return delegate.sizeAsync();
   }

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

   @Override
   public String getVersion() {
      return delegate.getVersion();
   }

   @Override
   public void start() {
      delegate.start();
   }

   @Override
   public void stop() {
      delegate.stop();
   }

   @Override
   public CloseableIterator keyIterator(IntSet segments) {
      return delegate.keyIterator(segments);
   }

   @Override
   public CloseableIterator> entryIterator(IntSet segments) {
      return delegate.entryIterator(segments);
   }

   @Override
   public boolean hasForceReturnFlag() {
      return delegate.hasForceReturnFlag();
   }

   @Override
   public void resolveStorage(boolean objectStorage) {
      delegate.resolveStorage(objectStorage);
   }

   @Override
   public byte[] keyToBytes(Object o) {
      return delegate.keyToBytes(o);
   }

   @Override
   public void init(OperationsFactory operationsFactory, Configuration configuration, ObjectName jmxParent) {
      delegate.init(operationsFactory, configuration, jmxParent);
   }

   @Override
   public void init(OperationsFactory operationsFactory, Configuration configuration) {
      delegate.init(operationsFactory, configuration);
   }

   @Override
   public OperationsFactory getOperationsFactory() {
      return delegate.getOperationsFactory();
   }

   @Override
   public boolean isObjectStorage() {
      return delegate.isObjectStorage();
   }

   @Override
   public CompletionStage ping() {
      return delegate.ping();
   }

   @Override
   public CompletionStage updateBloomFilter() {
      return delegate.updateBloomFilter();
   }
}