org.infinispan.client.hotrod.impl
Class RemoteCacheImpl<K,V>

java.lang.Object
  extended by org.infinispan.CacheSupport<K,V>
      extended by org.infinispan.client.hotrod.impl.RemoteCacheSupport<K,V>
          extended by org.infinispan.client.hotrod.impl.RemoteCacheImpl<K,V>
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>, BasicCache<K,V>, RemoteCache<K,V>, Lifecycle

public class RemoteCacheImpl<K,V>
extends RemoteCacheSupport<K,V>

Since:
4.1
Author:
Mircea.Markus@jboss.com

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.infinispan.CacheSupport
defaultLifespan, defaultMaxIdleTime
 
Constructor Summary
RemoteCacheImpl(RemoteCacheManager rcm, String name)
           
 
Method Summary
 void clear()
           
 NotifyingFuture<Void> clearAsync()
          Asynchronous version of Map.clear().
 boolean containsKey(Object key)
           
 V get(Object key)
           
 NotifyingFuture<V> getAsync(K key)
          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.
 Map<K,V> getBulk()
          Bulk get operations, returns all the entries within the remote cache.
 Map<K,V> getBulk(int size)
          Same as RemoteCache.getBulk(), but limits the returned set of values to the specified size.
 String getName()
          Retrieves the name of the cache
 RemoteCacheManager getRemoteCacheManager()
          Returns the RemoteCacheManager that created this cache.
 String getVersion()
          Retrieves the version of Infinispan
 VersionedValue<V> getVersioned(K key)
          Returns the VersionedValue associated to the supplied key param, or null if it doesn't exist.
 void init(Marshaller marshaller, ExecutorService executorService, OperationsFactory operationsFactory, int estimateKeySize, int estimateValueSize)
           
 boolean isEmpty()
           
 PingOperation.PingResult ping()
           
 V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.
 void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          Synthetic operation.
 NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Synthetic operation.
 NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Asynchronous version of BasicCache.put(Object, Object, long, TimeUnit, long, TimeUnit).
 V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
 NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Asynchronous version of BasicCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit).
 V remove(Object key)
           
 NotifyingFuture<V> removeAsync(Object key)
          Asynchronous version of Map.remove(Object).
 boolean removeWithVersion(K key, long version)
          Removes the given entry only if its version matches the supplied version.
 NotifyingFuture<Boolean> removeWithVersionAsync(K key, long version)
           
 V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
          An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
 NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Asynchronous version of BasicCache.replace(Object, Object, long, TimeUnit, long, TimeUnit).
 boolean replaceWithVersion(K key, V newValue, long version, int lifespanSeconds, int maxIdleTimeSeconds)
          A overloaded form of RemoteCache.replaceWithVersion(Object, Object, long) which takes in lifespan and maximum idle time parameters.
 NotifyingFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, int lifespanSeconds, int maxIdleSeconds)
           
protected  void set(K key, V value)
          This is intentionally a non-public method meant as an integration point for bytecode manipulation.
 int size()
           
 void start()
           
 ServerStatistics stats()
           
 void stop()
           
 RemoteCache<K,V> withFlags(Flag... flags)
          Applies one or more Flags to the scope of a single invocation.
 
Methods inherited from class org.infinispan.client.hotrod.impl.RemoteCacheSupport
containsValue, entrySet, keySet, remove, removeAsync, replace, replaceAsync, replaceWithVersion, replaceWithVersion, replaceWithVersionAsync, replaceWithVersionAsync, values
 
Methods inherited from class org.infinispan.CacheSupport
put, put, putAll, putAll, putAllAsync, putAllAsync, putAsync, putAsync, putIfAbsent, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, replace, replace, replace, replace, replaceAsync, replaceAsync, replaceAsync, replaceAsync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.infinispan.client.hotrod.RemoteCache
putAll, putAll, putAllAsync, putAllAsync, replace, replace, replaceAsync, replaceAsync
 
Methods inherited from interface org.infinispan.api.BasicCache
put, putAsync, putAsync, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, replace, replaceAsync, replaceAsync
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, replace
 
Methods inherited from interface java.util.Map
equals, hashCode, put
 

Constructor Detail

RemoteCacheImpl

public RemoteCacheImpl(RemoteCacheManager rcm,
                       String name)
Method Detail

init

public void init(Marshaller marshaller,
                 ExecutorService executorService,
                 OperationsFactory operationsFactory,
                 int estimateKeySize,
                 int estimateValueSize)

getRemoteCacheManager

public RemoteCacheManager getRemoteCacheManager()
Description copied from interface: RemoteCache
Returns the RemoteCacheManager that created this cache.


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)

removeWithVersionAsync

public NotifyingFuture<Boolean> removeWithVersionAsync(K key,
                                                       long version)
See Also:
RemoteCache.remove(Object, 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

replaceWithVersionAsync

public NotifyingFuture<Boolean> replaceWithVersionAsync(K key,
                                                        V newValue,
                                                        long version,
                                                        int lifespanSeconds,
                                                        int maxIdleSeconds)
See Also:
RemoteCache.replaceWithVersion(Object, Object, long)

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.


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 NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data,
                                         long lifespan,
                                         TimeUnit lifespanUnit,
                                         long maxIdle,
                                         TimeUnit maxIdleUnit)
Description copied from interface: RemoteCache
Synthetic operation.

Parameters:
data - to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - 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()

stats

public ServerStatistics stats()

put

public V put(K key,
             V value,
             long lifespan,
             TimeUnit lifespanUnit,
             long maxIdleTime,
             TimeUnit maxIdleTimeUnit)
Description copied from interface: BasicCache
An overloaded form of Map.put(Object, Object), which takes in lifespan parameters.

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: BasicCache
An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.

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: BasicCache
An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.

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.

putAsync

public NotifyingFuture<V> putAsync(K key,
                                   V value,
                                   long lifespan,
                                   TimeUnit lifespanUnit,
                                   long maxIdle,
                                   TimeUnit maxIdleUnit)
Description copied from interface: BasicCache
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. Has no benefit over BasicCache.put(Object, Object, long, TimeUnit, long, TimeUnit) if used in LOCAL mode.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the old value replaced

clearAsync

public NotifyingFuture<Void> clearAsync()
Description copied from interface: BasicCache
Asynchronous version of Map.clear(). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.clear() if used in LOCAL mode.

Returns:
a future containing a void return type

putIfAbsentAsync

public NotifyingFuture<V> putIfAbsentAsync(K key,
                                           V value,
                                           long lifespan,
                                           TimeUnit lifespanUnit,
                                           long maxIdle,
                                           TimeUnit maxIdleUnit)
Description copied from interface: BasicCache
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. Has no benefit over BasicCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit) if used in LOCAL mode.

Parameters:
key - key to use
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the old value replaced

removeAsync

public NotifyingFuture<V> removeAsync(Object key)
Description copied from interface: BasicCache
Asynchronous version of Map.remove(Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over Map.remove(Object) if used in LOCAL mode.

Parameters:
key - key to remove
Returns:
a future containing the value removed

replaceAsync

public NotifyingFuture<V> replaceAsync(K key,
                                       V value,
                                       long lifespan,
                                       TimeUnit lifespanUnit,
                                       long maxIdle,
                                       TimeUnit maxIdleUnit)
Description copied from interface: BasicCache
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. Has no benefit over BasicCache.replace(Object, Object, long, TimeUnit, long, TimeUnit) if used in LOCAL mode.

Parameters:
key - key to remove
value - value to store
lifespan - lifespan of entry
lifespanUnit - time unit for lifespan
maxIdle - the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit - time unit for max idle time
Returns:
a future containing the previous value overwritten

containsKey

public boolean containsKey(Object key)

get

public V get(Object key)

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)

clear

public void clear()

start

public void start()

stop

public void stop()

getName

public String getName()
Description copied from interface: BasicCache
Retrieves the name of the cache

Returns:
the name of the cache

getVersion

public String getVersion()
Description copied from interface: BasicCache
Retrieves the version of Infinispan

Returns:
a version string

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 NotifyingFuture<V> getAsync(K key)
Description copied from interface: BasicCache
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 cache loaders 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 PingOperation.PingResult ping()

set

protected void set(K key,
                   V value)
Description copied from class: CacheSupport
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 CacheSupport<K,V>

-->

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.