Class RemoteCacheImpl<K,​V>

  • All Implemented Interfaces:
    ConcurrentMap<K,​V>, Map<K,​V>, RemoteCache<K,​V>, org.infinispan.commons.api.AsyncCache<K,​V>, org.infinispan.commons.api.BasicCache<K,​V>, org.infinispan.commons.api.Lifecycle, org.infinispan.commons.api.TransactionalCache
    Direct Known Subclasses:
    InvalidatedNearRemoteCache

    public class RemoteCacheImpl<K,​V>
    extends RemoteCacheSupport<K,​V>
    Since:
    4.1
    Author:
    Mircea.Markus@jboss.com
    • Field Detail

      • operationsFactory

        protected org.infinispan.client.hotrod.impl.operations.OperationsFactory operationsFactory
    • Method Detail

      • init

        public void init​(org.infinispan.commons.marshall.Marshaller marshaller,
                         org.infinispan.client.hotrod.impl.operations.OperationsFactory operationsFactory,
                         int estimateKeySize,
                         int estimateValueSize,
                         int batchSize,
                         ObjectName jmxParent)
      • getOperationsFactory

        public org.infinispan.client.hotrod.impl.operations.OperationsFactory getOperationsFactory()
      • removeWithVersion

        public boolean removeWithVersion​(K key,
                                         long version)
        Description copied from interface: RemoteCache
        Removes the given entry only if its version matches the supplied version. A typical use case looks like this:
         VersionedEntry ve = remoteCache.getVersioned(key);
         //some processing
         remoteCache.removeWithVersion(key, ve.getVersion();
         
        Lat call (removeWithVersion) will make sure that the entry will only be removed if it hasn't been changed in between.
        Returns:
        true if the entry has been removed
        See Also:
        VersionedValue, RemoteCache.getVersioned(Object)
      • replaceWithVersion

        public boolean replaceWithVersion​(K key,
                                          V newValue,
                                          long version,
                                          int lifespanSeconds,
                                          int maxIdleTimeSeconds)
        Description copied from interface: RemoteCache
        A overloaded form of RemoteCache.replaceWithVersion(Object, Object, long) which takes in lifespan and maximum idle time parameters.
        Parameters:
        key - key to use
        newValue - new value to be associated with the key
        version - numeric version that should match the one in the server for the operation to succeed
        lifespanSeconds - lifespan of the entry
        maxIdleTimeSeconds - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        Returns:
        true if the value was replaced
      • replaceWithVersion

        public boolean replaceWithVersion​(K key,
                                          V newValue,
                                          long version,
                                          long lifespan,
                                          TimeUnit lifespanTimeUnit,
                                          long maxIdle,
                                          TimeUnit maxIdleTimeUnit)
        Description copied from interface: RemoteCache
        A overloaded form of RemoteCache.replaceWithVersion(Object, Object, long) which takes in lifespan and maximum idle time parameters.
        Parameters:
        key - key to use
        newValue - new value to be associated with the key
        version - numeric version that should match the one in the server for the operation to succeed
        lifespan - lifespan of the entry
        lifespanTimeUnit - TimeUnit for lifespan
        maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - TimeUnit for maxIdle
        Returns:
        true if the value was replaced
      • replaceWithVersionAsync

        public CompletableFuture<Boolean> replaceWithVersionAsync​(K key,
                                                                  V newValue,
                                                                  long version,
                                                                  long lifespan,
                                                                  TimeUnit lifespanTimeUnit,
                                                                  long maxIdle,
                                                                  TimeUnit maxIdleTimeUnit)
      • retrieveEntries

        public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,​Object>> retrieveEntries​(String filterConverterFactory,
                                                                                                             Object[] filterConverterParams,
                                                                                                             Set<Integer> segments,
                                                                                                             int batchSize)
        Description copied from interface: RemoteCache
        Retrieve entries from the server
        Parameters:
        filterConverterFactory - Factory name for the KeyValueFilterConverter or null for no filtering.
        filterConverterParams - Parameters to the KeyValueFilterConverter
        segments - The segments to iterate. If null all segments will be iterated. An empty set will filter out all entries.
        batchSize - The number of entries transferred from the server at a time.
        Returns:
        Iterator for the entries
      • retrieveEntriesByQuery

        public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,​Object>> retrieveEntriesByQuery​(Query filterQuery,
                                                                                                                    Set<Integer> segments,
                                                                                                                    int batchSize)
        Description copied from interface: RemoteCache
        Retrieve entries from the server matching a query.
        Parameters:
        filterQuery - Query
        segments - The segments to iterate. If null all segments will be iterated. An empty set will filter out all entries.
        batchSize - The number of entries transferred from the server at a time.
        Returns:
        CloseableIterator
      • retrieveEntriesWithMetadata

        public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,​MetadataValue<Object>>> retrieveEntriesWithMetadata​(Set<Integer> segments,
                                                                                                                                        int batchSize)
        Description copied from interface: RemoteCache
        Retrieve entries with metadata information
      • getVersioned

        public VersionedValue<V> getVersioned​(K key)
        Description copied from interface: RemoteCache
        Returns the VersionedValue associated to the supplied key param, or null if it doesn't exist.
      • getWithMetadata

        public MetadataValue<V> getWithMetadata​(K key)
        Description copied from interface: RemoteCache
        Returns the MetadataValue associated to the supplied key param, or null if it doesn't exist.
      • putAll

        public void putAll​(Map<? extends K,​? extends V> map,
                           long lifespan,
                           TimeUnit lifespanUnit,
                           long maxIdleTime,
                           TimeUnit maxIdleTimeUnit)
        Description copied from interface: RemoteCache
        Synthetic operation.
        Parameters:
        map - map containing mappings to enter
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        See Also:
        RemoteCache.putAll(java.util.Map, long, java.util.concurrent.TimeUnit)
      • putAllAsync

        public CompletableFuture<Void> putAllAsync​(Map<? extends K,​? extends V> map,
                                                   long lifespan,
                                                   TimeUnit lifespanUnit,
                                                   long maxIdleTime,
                                                   TimeUnit maxIdleTimeUnit)
        Description copied from interface: RemoteCache
        Synthetic operation.
        Parameters:
        map - to store
        lifespan - lifespan of entry
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        a future containing a void return type
        See Also:
        RemoteCache.putAll(java.util.Map, long, java.util.concurrent.TimeUnit)
      • size

        public int size()
      • isEmpty

        public boolean isEmpty()
      • serverStatistics

        public ServerStatistics serverStatistics()
        Description copied from interface: RemoteCache
        Returns server-side statistics for this cache.
      • put

        public V put​(K key,
                     V value,
                     long lifespan,
                     TimeUnit lifespanUnit,
                     long maxIdleTime,
                     TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.BasicCache
        An overloaded form of BasicCache.put(Object, Object), which takes in lifespan parameters.
        Specified by:
        put in interface org.infinispan.commons.api.BasicCache<K,​V>
        Overrides:
        put in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value,
                             long lifespan,
                             TimeUnit lifespanUnit,
                             long maxIdleTime,
                             TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.BasicCache
        An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
        Specified by:
        putIfAbsent in interface org.infinispan.commons.api.BasicCache<K,​V>
        Overrides:
        putIfAbsent in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • replace

        public V replace​(K key,
                         V value,
                         long lifespan,
                         TimeUnit lifespanUnit,
                         long maxIdleTime,
                         TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.BasicCache
        An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
        Specified by:
        replace in interface org.infinispan.commons.api.BasicCache<K,​V>
        Overrides:
        replace in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V value,
                               long lifespan,
                               TimeUnit lifespanUnit,
                               long maxIdleTime,
                               TimeUnit maxIdleTimeUnit)
        Description copied from interface: RemoteCache
        An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.

        This method requires 2 round trips to the server. The first to retrieve the value and version and a second to replace the key with the version if the value matches. If possible user should use RemoteCache.getWithMetadata(Object) and RemoteCache.replaceWithVersion(Object, Object, long, long, TimeUnit, long, TimeUnit) if possible.

        Specified by:
        replace in interface org.infinispan.commons.api.BasicCache<K,​V>
        Specified by:
        replace in interface RemoteCache<K,​V>
        Overrides:
        replace in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        oldValue - value to replace
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        true if the value was replaced, false otherwise
      • putAsync

        public CompletableFuture<V> putAsync​(K key,
                                             V value,
                                             long lifespan,
                                             TimeUnit lifespanUnit,
                                             long maxIdleTime,
                                             TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of BasicCache.put(Object, Object, long, TimeUnit, long, TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of entry
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        a future containing the old value replaced
      • clearAsync

        public CompletableFuture<Void> clearAsync()
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of Map.clear(). This method does not block on remote calls, even if your cache mode is synchronous.
        Returns:
        a future containing a void return type
      • compute

        public V compute​(K key,
                         BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                         long lifespan,
                         TimeUnit lifespanUnit,
                         long maxIdleTime,
                         TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.BasicCache
        An overloaded form of ConcurrentMap.compute(Object, BiFunction) which takes in lifespan and maxIdleTime parameters.
        Specified by:
        compute in interface org.infinispan.commons.api.BasicCache<K,​V>
        Overrides:
        compute in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        remappingFunction - function to use to compute and store the value under key
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the computed value that was stored under key
      • computeAsync

        public CompletableFuture<V> computeAsync​(K key,
                                                 BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                                                 long lifespan,
                                                 TimeUnit lifespanUnit,
                                                 long maxIdle,
                                                 TimeUnit maxIdleUnit)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of BasicCache.compute(Object, BiFunction, long, TimeUnit, long, TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous.
        Specified by:
        computeAsync in interface org.infinispan.commons.api.AsyncCache<K,​V>
        Overrides:
        computeAsync in class RemoteCacheSupport<K,​V>
      • putIfAbsentAsync

        public CompletableFuture<V> putIfAbsentAsync​(K key,
                                                     V value,
                                                     long lifespan,
                                                     TimeUnit lifespanUnit,
                                                     long maxIdleTime,
                                                     TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of BasicCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous.
        Specified by:
        putIfAbsentAsync in interface org.infinispan.commons.api.AsyncCache<K,​V>
        Overrides:
        putIfAbsentAsync in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of entry
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        a future containing the old value replaced
      • removeAsync

        public CompletableFuture<V> removeAsync​(Object key)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of BasicCache.remove(Object). This method does not block on remote calls, even if your cache mode is synchronous.
        Parameters:
        key - key to remove
        Returns:
        a future containing the value removed
      • replaceAsync

        public CompletableFuture<V> replaceAsync​(K key,
                                                 V value,
                                                 long lifespan,
                                                 TimeUnit lifespanUnit,
                                                 long maxIdleTime,
                                                 TimeUnit maxIdleTimeUnit)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of BasicCache.replace(Object, Object, long, TimeUnit, long, TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous.
        Specified by:
        replaceAsync in interface org.infinispan.commons.api.AsyncCache<K,​V>
        Overrides:
        replaceAsync in class RemoteCacheSupport<K,​V>
        Parameters:
        key - key to remove
        value - value to store
        lifespan - lifespan of entry
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        a future containing the previous value overwritten
      • containsKey

        public boolean containsKey​(Object key)
      • containsValue

        public boolean containsValue​(Object value)
      • get

        public V get​(Object key)
      • getAll

        public Map<K,​V> getAll​(Set<? extends K> keys)
        Description copied from interface: RemoteCache
        Retrieves all of the entries for the provided keys. A key will not be present in the resulting map if the entry was not found in the cache.
        Parameters:
        keys - The keys to find values for
        Returns:
        The entries that were present for the given keys
      • getBulk

        public Map<K,​V> getBulk()
        Description copied from interface: RemoteCache
        Bulk get operations, returns all the entries within the remote cache.
        Returns:
        the returned values depend on the configuration of the back-end infinispan servers. Read this for more details. The returned Map is unmodifiable.
      • getBulk

        public Map<K,​V> getBulk​(int size)
        Description copied from interface: RemoteCache
        Same as RemoteCache.getBulk(), but limits the returned set of values to the specified size. No ordering is guaranteed, and there is no guarantee that "size" elements are returned( e.g. if the number of elements in the back-end server is smaller that "size")
      • remove

        public V remove​(Object key)
        Description copied from interface: RemoteCache
        If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.IGNORE_RETURN_VALUES flag when invoking this method in order to make it behave as efficiently as possible (i.e. avoiding needless remote or network calls).

        The returned value is only sent back if Flag.FORCE_RETURN_VALUE is enabled.

      • clear

        public void clear()
      • start

        public void start()
        Description copied from interface: org.infinispan.commons.api.Lifecycle
        Invoked on component start
      • stop

        public void stop()
        Description copied from interface: org.infinispan.commons.api.Lifecycle
        Invoked on component stop
      • getName

        public String getName()
        Description copied from interface: org.infinispan.commons.api.BasicCache
        Retrieves the name of the cache
        Returns:
        the name of the cache
      • getVersion

        public String getVersion()
        Description copied from interface: org.infinispan.commons.api.BasicCache
        Retrieves the version of Infinispan
        Returns:
        a version string
      • getProtocolVersion

        public String getProtocolVersion()
        Description copied from interface: RemoteCache
        Returns the HotRod protocol version supported by this RemoteCache implementation
      • addClientListener

        public void addClientListener​(Object listener)
        Description copied from interface: RemoteCache
        Add a client listener to receive events that happen in the remote cache. The listener object must be annotated with @ClientListener annotation.
      • addClientListener

        public void addClientListener​(Object listener,
                                      Object[] filterFactoryParams,
                                      Object[] converterFactoryParams)
        Description copied from interface: RemoteCache
        Add a client listener to receive events that happen in the remote cache. The listener object must be annotated with @ClientListener annotation.
      • removeClientListener

        public void removeClientListener​(Object listener)
        Description copied from interface: RemoteCache
        Remove a previously added client listener. If the listener was not added before, this operation is a no-op.
      • getListeners

        public Set<Object> getListeners()
        Description copied from interface: RemoteCache
        Returns a set with all the listeners registered by this client for the given cache.
      • withFlags

        public RemoteCache<K,​V> withFlags​(Flag... flags)
        Description copied from interface: RemoteCache
        Applies one or more Flags to the scope of a single invocation. See the Flag enumeration to for information on available flags.

        Sample usage:

            remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("hello", "world");
         
        Returns:
        the current RemoteCache instance to continue running operations on.
      • getAsync

        public CompletableFuture<V> getAsync​(Object key)
        Description copied from interface: org.infinispan.commons.api.AsyncCache
        Asynchronous version of Map.get(Object) that allows user code to retrieve the value associated with a key at a later stage, hence allowing multiple parallel get requests to be sent. Normally, when this method detects that the value is likely to be retrieved from from a remote entity, it will span a different thread in order to allow the asynchronous get call to return immediately. If the call will definitely resolve locally, for example when the cache is configured with LOCAL mode and no stores are configured, the get asynchronous call will act sequentially and will have no different to Map.get(Object).
        Parameters:
        key - key to retrieve
        Returns:
        a future that can be used to retrieve value associated with the key when this is available. The actual value returned by the future follows the same rules as Map.get(Object)
      • ping

        public org.infinispan.client.hotrod.impl.operations.PingOperation.PingResponse ping()
      • keyToBytes

        protected byte[] keyToBytes​(Object o)
      • valueToBytes

        protected byte[] valueToBytes​(Object o)
      • assertRemoteCacheManagerIsStarted

        protected void assertRemoteCacheManagerIsStarted()
      • set

        protected void set​(K key,
                           V value)
        Description copied from class: RemoteCacheSupport
        This is intentionally a non-public method meant as an integration point for bytecode manipulation. Don't remove or alter the signature even if it might look like unreachable code. Implementors should perform a put operation but optimizing it as return values are not required.
        Specified by:
        set in class RemoteCacheSupport<K,​V>
      • keySet

        public org.infinispan.commons.util.CloseableIteratorSet<K> keySet()
      • keySet

        public org.infinispan.commons.util.CloseableIteratorSet<K> keySet​(org.infinispan.commons.util.IntSet segments)
        Description copied from interface: RemoteCache
        This method is identical to RemoteCache.keySet() except that it will only return keys that map to the given segments. Note that these segments will be determined by the remote server. Thus you should be aware of how many segments it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same this method may return unexpected keys.
        Parameters:
        segments - the segments of keys to return - null means all available
        Returns:
        set containing keys that map to the given segments
        See Also:
        RemoteCache.keySet()
      • entrySet

        public org.infinispan.commons.util.CloseableIteratorSet<Map.Entry<K,​V>> entrySet()
      • entrySet

        public org.infinispan.commons.util.CloseableIteratorSet<Map.Entry<K,​V>> entrySet​(org.infinispan.commons.util.IntSet segments)
        Description copied from interface: RemoteCache
        This method is identical to RemoteCache.entrySet() except that it will only return entries that map to the given segments. Note that these segments will be determined by the remote server. Thus you should be aware of how many segments it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same this method may return unexpected entries.
        Parameters:
        segments - the segments of entries to return - null means all available
        Returns:
        set containing entries that map to the given segments
        See Also:
        RemoteCache.entrySet()
      • values

        public org.infinispan.commons.util.CloseableIteratorCollection<V> values()
      • values

        public org.infinispan.commons.util.CloseableIteratorCollection<V> values​(org.infinispan.commons.util.IntSet segments)
        Description copied from interface: RemoteCache
        This method is identical to RemoteCache.values() except that it will only return values that map to the given segments. Note that these segments will be determined by the remote server. Thus you should be aware of how many segments it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same this method may return unexpected values.
        Parameters:
        segments - the segments of values to return - null means all available
        Returns:
        collection containing values that map to the given segments
        See Also:
        RemoteCache.values()
      • execute

        public <T> T execute​(String taskName,
                             Map<String,​?> params)
        Description copied from interface: RemoteCache
        Executes a remote script passing a set of named parameters
      • execute

        public <T> T execute​(String taskName,
                             Map<String,​?> params,
                             Object key)
        Description copied from interface: RemoteCache
        Executes a remote script passing a set of named parameters, hinting that the script should be executed on the server that is expected to store given key. The key itself is not transferred to the server.
      • resolveStorage

        public org.infinispan.client.hotrod.impl.operations.PingOperation.PingResponse resolveStorage()
      • isObjectStorage

        public boolean isObjectStorage()