org.infinispan
Class CacheImpl<K,V>

java.lang.Object
  extended by org.infinispan.CacheSupport<K,V>
      extended by org.infinispan.CacheImpl<K,V>
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>, AdvancedCache<K,V>, BasicCache<K,V>, Cache<K,V>, Lifecycle, Listenable

public class CacheImpl<K,V>
extends CacheSupport<K,V>
implements AdvancedCache<K,V>

Since:
4.0
Author:
Mircea.Markus@jboss.com, Galder ZamarreƱo, Sanne Grinovero, Trustin Lee

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  BatchContainer batchContainer
           
protected  CommandsFactory commandsFactory
           
protected  ComponentRegistry componentRegistry
           
protected  Configuration config
           
protected  InvocationContextContainer icc
           
protected  InterceptorChain invoker
           
protected  StreamingMarshaller marshaller
           
protected  CacheNotifier notifier
           
static String OBJECT_NAME
           
protected  RpcManager rpcManager
           
protected  TransactionManager transactionManager
           
 
Fields inherited from class org.infinispan.CacheSupport
defaultLifespan, defaultMaxIdleTime
 
Constructor Summary
CacheImpl(String name)
           
 
Method Summary
 void addInterceptor(CommandInterceptor i, int position)
          Adds a custom interceptor to the interceptor chain, at specified position, where the first interceptor in the chain is at position 0 and the last one at NUM_INTERCEPTORS - 1.
 boolean addInterceptorAfter(CommandInterceptor i, Class<? extends CommandInterceptor> afterInterceptor)
          Adds a custom interceptor to the interceptor chain, after an instance of the specified interceptor type.
 boolean addInterceptorBefore(CommandInterceptor i, Class<? extends CommandInterceptor> beforeInterceptor)
          Adds a custom interceptor to the interceptor chain, before an instance of the specified interceptor type.
 void addListener(Object listener)
          Adds a listener to the component.
 void applyDelta(K deltaAwareValueKey, Delta delta, Object... locksToAcquire)
          Applies the given Delta to the DeltaAware object stored under deltaAwareValueKey if and only if all locksToAcquire locks are successfully obtained
 void clear()
           
 NotifyingFuture<Void> clearAsync()
          Asynchronous version of Map.clear().
 void compact()
          Method that releases object references of cached objects held in the cache by serializing them to byte buffers.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 void endBatch(boolean successful)
          Completes a batch if one has been started using Cache.startBatch().
 Set<Map.Entry<K,V>> entrySet()
          Returns a set view of the mappings contained in this cache.
 void evict(K key)
          Evicts an entry from the memory of the cache.
 V get(Object key)
           
 AdvancedCache<K,V> getAdvancedCache()
           
 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.
 BatchContainer getBatchContainer()
          Returns the component in charge of batching cache operations.
 Configuration getCacheConfiguration()
           
 EmbeddedCacheManager getCacheManager()
          Retrieves the cache manager responsible for creating this cache instance.
 String getCacheName()
          Returns the cache name.
 String getCacheStatus()
          Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX tools that don't have access to infinispan classes.
 ClassLoader getClassLoader()
          Returns the cache loader associated associated with this cache.
 ComponentRegistry getComponentRegistry()
           
 Configuration getConfiguration()
          Deprecated. 
 String getConfigurationAsXmlString()
          Returns the cache configuration as XML string.
 DataContainer getDataContainer()
          Returns the container where data is stored in the cache.
 DistributionManager getDistributionManager()
          Retrieves a reference to the DistributionManager if the cache is configured to use Distribution.
 EvictionManager getEvictionManager()
           
 List<CommandInterceptor> getInterceptorChain()
          Retrieves the current Interceptor chain.
 InvocationContextContainer getInvocationContextContainer()
          Returns the component in charge of managing the interactions between the cache operations and the context information associated with them.
 Set<Object> getListeners()
           
 LockManager getLockManager()
          Returns the component that deals with all aspects of acquiring and releasing locks for cache entries.
 String getName()
          Retrieves the name of the cache
 RpcManager getRpcManager()
          Returns the component in charge of communication with other caches in the cluster.
 Stats getStats()
          Returns a Stats object that allows several statistics associated with this cache at runtime.
 ComponentStatus getStatus()
           
 TransactionManager getTransactionManager()
          Returns the transaction manager configured for this cache.
 String getVersion()
          Retrieves the version of Infinispan
 XAResource getXAResource()
          Returns the XAResource associated with this cache which can be used to do transactional recovery.
 void injectDependencies(EvictionManager evictionManager, InvocationContextContainer icc, CommandsFactory commandsFactory, InterceptorChain interceptorChain, Configuration configuration, CacheNotifier notifier, ComponentRegistry componentRegistry, TransactionManager transactionManager, BatchContainer batchContainer, RpcManager rpcManager, DataContainer dataContainer, StreamingMarshaller marshaller, ResponseGenerator responseGenerator, DistributionManager distributionManager, EmbeddedCacheManager cacheManager, StateTransferManager stateTransferManager, ExecutorService asyncExecutor, TransactionTable txTable, RecoveryManager recoveryManager, TransactionCoordinator txCoordinator, LockManager lockManager)
           
 boolean isEmpty()
           
 Set<K> keySet()
          Returns a set view of the keys contained in this cache.
 boolean lock(Collection<? extends K> keys)
          Locks collections of keys eagerly across cache nodes in a cluster.
 boolean lock(K... keys)
          Locks a given key or keys eagerly across cache nodes in a cluster.
 V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
          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 idleTimeUnit)
          An overloaded form of Map.putAll(Map), which takes in lifespan parameters.
 NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Asynchronous version of BasicCache.putAll(Map, long, TimeUnit, long, TimeUnit).
 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).
 void putForExternalRead(K key, V value)
          Under special operating behavior, associates the value with the specified key.
 V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
          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)
           
 boolean remove(Object key, Object value)
           
 NotifyingFuture<V> removeAsync(Object key)
          Asynchronous version of Map.remove(Object).
 NotifyingFuture<Boolean> removeAsync(Object key, Object value)
          Asynchronous version of ConcurrentMap.remove(Object, Object).
 void removeInterceptor(Class<? extends CommandInterceptor> interceptorType)
          Removes the interceptor of specified type.
 void removeInterceptor(int position)
          Removes the interceptor at a specified position, where the first interceptor in the chain is at position 0 and the last one at getInterceptorChain().size() - 1.
 void removeListener(Object listener)
          Removes a listener from the component.
 V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
          An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
 boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
          An overloaded form of ConcurrentMap.replace(Object, 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).
 NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
          Asynchronous version of BasicCache.replace(Object, Object, Object, long, TimeUnit, long, TimeUnit).
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()
           
 boolean startBatch()
          Starts a batch.
 void stop()
           
 String toString()
           
 Collection<V> values()
          Returns a collection view of the values contained in this cache.
 AdvancedCache<K,V> with(ClassLoader classLoader)
          Using this operation, users can call any AdvancedCache operation with a given ClassLoader.
 AdvancedCache<K,V> withFlags(Flag... flags)
          A method that adds flags to any API call.
 
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, wait, wait, wait
 
Methods inherited from interface org.infinispan.api.BasicCache
put, putAll, putAllAsync, putAllAsync, putAsync, putAsync, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, replace, replace, replaceAsync, replaceAsync, replaceAsync, replaceAsync
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, replace, replace
 
Methods inherited from interface java.util.Map
equals, hashCode, put, putAll
 

Field Detail

OBJECT_NAME

public static final String OBJECT_NAME
See Also:
Constant Field Values

icc

protected InvocationContextContainer icc

commandsFactory

protected CommandsFactory commandsFactory

invoker

protected InterceptorChain invoker

config

protected Configuration config

notifier

protected CacheNotifier notifier

batchContainer

protected BatchContainer batchContainer

componentRegistry

protected ComponentRegistry componentRegistry

transactionManager

protected TransactionManager transactionManager

rpcManager

protected RpcManager rpcManager

marshaller

protected StreamingMarshaller marshaller
Constructor Detail

CacheImpl

public CacheImpl(String name)
Method Detail

injectDependencies

public void injectDependencies(EvictionManager evictionManager,
                               InvocationContextContainer icc,
                               CommandsFactory commandsFactory,
                               InterceptorChain interceptorChain,
                               Configuration configuration,
                               CacheNotifier notifier,
                               ComponentRegistry componentRegistry,
                               TransactionManager transactionManager,
                               BatchContainer batchContainer,
                               RpcManager rpcManager,
                               DataContainer dataContainer,
                               StreamingMarshaller marshaller,
                               ResponseGenerator responseGenerator,
                               DistributionManager distributionManager,
                               EmbeddedCacheManager cacheManager,
                               StateTransferManager stateTransferManager,
                               ExecutorService asyncExecutor,
                               TransactionTable txTable,
                               RecoveryManager recoveryManager,
                               TransactionCoordinator txCoordinator,
                               LockManager lockManager)

remove

public final boolean remove(Object key,
                            Object value)
Specified by:
remove in interface ConcurrentMap<K,V>

size

public final int size()
Specified by:
size in interface Map<K,V>

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

containsKey

public final boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public final boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

get

public final V get(Object key)
Specified by:
get in interface Map<K,V>

remove

public final V remove(Object key)
Specified by:
remove in interface Map<K,V>

clear

public final void clear()
Specified by:
clear in interface Map<K,V>

keySet

public Set<K> keySet()
Description copied from interface: Cache
Returns a set view of the keys contained in this cache. This set is immutable, so it cannot be modified and changes to the cache won't be reflected in the set. When this method is called on a cache configured with distribution mode, the set returned only contains the keys locally available in the cache instance. To avoid memory issues, there will be not attempt to bring keys from other nodes.

This method should only be used for debugging purposes such as to verify that the cache contains all the keys entered. Any other use involving execution of this method on a production system is not recommended.

Specified by:
keySet in interface Map<K,V>
Specified by:
keySet in interface Cache<K,V>
Returns:
a set view of the keys contained in this cache.

values

public Collection<V> values()
Description copied from interface: Cache
Returns a collection view of the values contained in this cache. This collection is immutable, so it cannot be modified and changes to the cache won't be reflected in the set. When this method is called on a cache configured with distribution mode, the collection returned only contains the values locally available in the cache instance. To avoid memory issues, there is not attempt to bring values from other nodes.

This method should only be used for testing or debugging purposes such as to verify that the cache contains all the values entered. Any other use involving execution of this method on a production system is not recommended.

Specified by:
values in interface Map<K,V>
Specified by:
values in interface Cache<K,V>
Returns:
a collection view of the values contained in this map.

entrySet

public Set<Map.Entry<K,V>> entrySet()
Description copied from interface: Cache
Returns a set view of the mappings contained in this cache. This set is immutable, so it cannot be modified and changes to the cache won't be reflected in the set. Besides, each element in the returned set is an immutable Map.Entry. When this method is called on a cache configured with distribution mode, the set returned only contains the mappings locally available in the cache instance. To avoid memory issues, there will be not attempt to bring mappings from other nodes.

This method should only be used for debugging purposes such as to verify that the cache contains all the mappings entered. Any other use involving execution of this method on a production system is not recommended.

Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in interface Cache<K,V>
Returns:
a set view of the mappings contained in this cache.

putForExternalRead

public final void putForExternalRead(K key,
                                     V value)
Description copied from interface: Cache
Under special operating behavior, associates the value with the specified key. This method is for caching data that has an external representation in storage, where, concurrent modification and transactions are not a consideration, and failure to put the data in the cache should be treated as a 'suboptimal outcome' rather than a 'failing outcome'.

An example of when this method is useful is when data is read from, for example, a legacy datastore, and is cached before returning the data to the caller. Subsequent calls would prefer to get the data from the cache and if the data doesn't exist in the cache, fetch again from the legacy datastore.

See JBCACHE-848 for details around this feature.

Specified by:
putForExternalRead in interface Cache<K,V>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.

evict

public final void evict(K key)
Description copied from interface: Cache
Evicts an entry from the memory of the cache. Note that the entry is not removed from any configured cache stores or any other caches in the cluster (if used in a clustered mode). Use Map.remove(Object) to remove an entry from the entire cache system.

This method is designed to evict an entry from memory to free up memory used by the application. This method uses a 0 lock acquisition timeout so it does not block in attempting to acquire locks. It behaves as a no-op if the lock on the entry cannot be acquired immediately.

Important: this method should not be called from within a transaction scope.

Specified by:
evict in interface Cache<K,V>
Parameters:
key - key to evict

getConfiguration

@Deprecated
public Configuration getConfiguration()
Deprecated. 

Specified by:
getConfiguration in interface Cache<K,V>

getCacheConfiguration

public Configuration getCacheConfiguration()
Specified by:
getCacheConfiguration in interface Cache<K,V>

addListener

public void addListener(Object listener)
Description copied from interface: Listenable
Adds a listener to the component. Typically, listeners would need to be annotated with Listener and further to that, contain methods annotated appropriately, otherwise the listener will not be registered.

See the Listener annotation for more information.

Specified by:
addListener in interface Listenable
Parameters:
listener - must not be null.

removeListener

public void removeListener(Object listener)
Description copied from interface: Listenable
Removes a listener from the component.

Specified by:
removeListener in interface Listenable
Parameters:
listener - listener to remove. Must not be null.

getListeners

public Set<Object> getListeners()
Specified by:
getListeners in interface Listenable
Returns:
a set of all listeners registered on this component.

lock

public boolean lock(K... keys)
Description copied from interface: AdvancedCache
Locks a given key or keys eagerly across cache nodes in a cluster.

Keys can be locked eagerly in the context of a transaction only.

Specified by:
lock in interface AdvancedCache<K,V>
Parameters:
keys - the keys to lock
Returns:
true if the lock acquisition attempt was successful for all keys; false will only be returned if the lock acquisition timed out and the operation has been called with Flag.FAIL_SILENTLY.

lock

public boolean lock(Collection<? extends K> keys)
Description copied from interface: AdvancedCache
Locks collections of keys eagerly across cache nodes in a cluster.

Collections of keys can be locked eagerly in the context of a transaction only.

Specified by:
lock in interface AdvancedCache<K,V>
Parameters:
keys - collection of keys to lock
Returns:
true if the lock acquisition attempt was successful for all keys; false will only be returned if the lock acquisition timed out and the operation has been called with Flag.FAIL_SILENTLY.

applyDelta

public void applyDelta(K deltaAwareValueKey,
                       Delta delta,
                       Object... locksToAcquire)
Description copied from interface: AdvancedCache
Applies the given Delta to the DeltaAware object stored under deltaAwareValueKey if and only if all locksToAcquire locks are successfully obtained

Specified by:
applyDelta in interface AdvancedCache<K,V>
Parameters:
deltaAwareValueKey - the key for DeltaAware object
delta - the delta to be applied to DeltaAware object
locksToAcquire - keys to be locked in DeltaAware scope

start

public void start()
Specified by:
start in interface Lifecycle

stop

public void stop()
Specified by:
stop in interface Lifecycle

getInterceptorChain

public List<CommandInterceptor> getInterceptorChain()
Description copied from interface: AdvancedCache
Retrieves the current Interceptor chain.

Specified by:
getInterceptorChain in interface AdvancedCache<K,V>
Returns:
an immutable List of CommandInterceptors configured for this cache

addInterceptor

public void addInterceptor(CommandInterceptor i,
                           int position)
Description copied from interface: AdvancedCache
Adds a custom interceptor to the interceptor chain, at specified position, where the first interceptor in the chain is at position 0 and the last one at NUM_INTERCEPTORS - 1.

Specified by:
addInterceptor in interface AdvancedCache<K,V>
Parameters:
i - the interceptor to add
position - the position to add the interceptor

addInterceptorAfter

public boolean addInterceptorAfter(CommandInterceptor i,
                                   Class<? extends CommandInterceptor> afterInterceptor)
Description copied from interface: AdvancedCache
Adds a custom interceptor to the interceptor chain, after an instance of the specified interceptor type. Throws a cache exception if it cannot find an interceptor of the specified type.

Specified by:
addInterceptorAfter in interface AdvancedCache<K,V>
Parameters:
i - interceptor to add
afterInterceptor - interceptor type after which to place custom interceptor
Returns:
true if successful, false otherwise.

addInterceptorBefore

public boolean addInterceptorBefore(CommandInterceptor i,
                                    Class<? extends CommandInterceptor> beforeInterceptor)
Description copied from interface: AdvancedCache
Adds a custom interceptor to the interceptor chain, before an instance of the specified interceptor type. Throws a cache exception if it cannot find an interceptor of the specified type.

Specified by:
addInterceptorBefore in interface AdvancedCache<K,V>
Parameters:
i - interceptor to add
beforeInterceptor - interceptor type before which to place custom interceptor
Returns:
true if successful, false otherwise.

removeInterceptor

public void removeInterceptor(int position)
Description copied from interface: AdvancedCache
Removes the interceptor at a specified position, where the first interceptor in the chain is at position 0 and the last one at getInterceptorChain().size() - 1.

Specified by:
removeInterceptor in interface AdvancedCache<K,V>
Parameters:
position - the position at which to remove an interceptor

removeInterceptor

public void removeInterceptor(Class<? extends CommandInterceptor> interceptorType)
Description copied from interface: AdvancedCache
Removes the interceptor of specified type.

Specified by:
removeInterceptor in interface AdvancedCache<K,V>
Parameters:
interceptorType - type of interceptor to remove

getEvictionManager

public EvictionManager getEvictionManager()
Specified by:
getEvictionManager in interface AdvancedCache<K,V>
Returns:
the eviction manager - if one is configured - for this cache instance

getComponentRegistry

public ComponentRegistry getComponentRegistry()
Specified by:
getComponentRegistry in interface AdvancedCache<K,V>
Returns:
the component registry for this cache instance

getDistributionManager

public DistributionManager getDistributionManager()
Description copied from interface: AdvancedCache
Retrieves a reference to the DistributionManager if the cache is configured to use Distribution. Otherwise, returns a null.

Specified by:
getDistributionManager in interface AdvancedCache<K,V>
Returns:
a DistributionManager, or null.

getStatus

public ComponentStatus getStatus()
Specified by:
getStatus in interface Cache<K,V>

getCacheStatus

public String getCacheStatus()
Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX tools that don't have access to infinispan classes.


startBatch

public boolean startBatch()
Description copied from interface: Cache
Starts a batch. All operations on the current client thread are performed as a part of this batch, with locks held for the duration of the batch and any remote calls delayed till the end of the batch.

Specified by:
startBatch in interface Cache<K,V>
Returns:
true if a batch was successfully started; false if one was available and already running.

endBatch

public void endBatch(boolean successful)
Description copied from interface: Cache
Completes a batch if one has been started using Cache.startBatch(). If no batch has been started, this is a no-op.

Specified by:
endBatch in interface Cache<K,V>
Parameters:
successful - if true, the batch completes, otherwise the batch is aborted and changes are not committed.

getName

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

Specified by:
getName in interface BasicCache<K,V>
Returns:
the name of the cache

getCacheName

public String getCacheName()
Returns the cache name. If this is the default cache, it returns a more friendly name.


getConfigurationAsXmlString

public String getConfigurationAsXmlString()
Returns the cache configuration as XML string.


getVersion

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

Specified by:
getVersion in interface BasicCache<K,V>
Returns:
a version string

toString

public String toString()
Overrides:
toString in class Object

getBatchContainer

public BatchContainer getBatchContainer()
Description copied from interface: AdvancedCache
Returns the component in charge of batching cache operations.

Specified by:
getBatchContainer in interface AdvancedCache<K,V>
Returns:
the batching component associated with this cache instance

getInvocationContextContainer

public InvocationContextContainer getInvocationContextContainer()
Description copied from interface: AdvancedCache
Returns the component in charge of managing the interactions between the cache operations and the context information associated with them.

Specified by:
getInvocationContextContainer in interface AdvancedCache<K,V>
Returns:
the invocation context container component

getDataContainer

public DataContainer getDataContainer()
Description copied from interface: AdvancedCache
Returns the container where data is stored in the cache. Users should interact with this component with care because direct calls on it bypass the internal interceptors and other infrastructure in place to guarantee the consistency of data.

Specified by:
getDataContainer in interface AdvancedCache<K,V>
Returns:
the data container associated with this cache instance

getTransactionManager

public TransactionManager getTransactionManager()
Description copied from interface: AdvancedCache
Returns the transaction manager configured for this cache. If no transaction manager was configured, this method returns null.

Specified by:
getTransactionManager in interface AdvancedCache<K,V>
Returns:
the transaction manager associated with this cache instance or null

getLockManager

public LockManager getLockManager()
Description copied from interface: AdvancedCache
Returns the component that deals with all aspects of acquiring and releasing locks for cache entries.

Specified by:
getLockManager in interface AdvancedCache<K,V>
Returns:
retrieves the lock manager associated with this cache instance

getCacheManager

public EmbeddedCacheManager getCacheManager()
Description copied from interface: Cache
Retrieves the cache manager responsible for creating this cache instance.

Specified by:
getCacheManager in interface Cache<K,V>
Returns:
a cache manager

getStats

public Stats getStats()
Description copied from interface: AdvancedCache
Returns a Stats object that allows several statistics associated with this cache at runtime.

Specified by:
getStats in interface AdvancedCache<K,V>
Returns:
this cache's Stats object

getXAResource

public XAResource getXAResource()
Description copied from interface: AdvancedCache
Returns the XAResource associated with this cache which can be used to do transactional recovery.

Specified by:
getXAResource in interface AdvancedCache<K,V>
Returns:
an instance of XAResource

put

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

Specified by:
put in interface BasicCache<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
idleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

putIfAbsent

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

Specified by:
putIfAbsent in interface BasicCache<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
idleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

putAll

public final void putAll(Map<? extends K,? extends V> map,
                         long lifespan,
                         TimeUnit lifespanUnit,
                         long maxIdleTime,
                         TimeUnit idleTimeUnit)
Description copied from interface: BasicCache
An overloaded form of Map.putAll(Map), which takes in lifespan parameters. Note that the lifespan is applied to all mappings in the map passed in.

Specified by:
putAll in interface BasicCache<K,V>
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
idleTimeUnit - time unit for max idle time

replace

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

Specified by:
replace in interface BasicCache<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
idleTimeUnit - time unit for max idle time
Returns:
the value being replaced, or null if nothing is being replaced.

replace

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

Specified by:
replace in interface BasicCache<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
idleTimeUnit - time unit for max idle time
Returns:
true if the value was replaced, false otherwise

putAsync

public final 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.

Specified by:
putAsync in interface BasicCache<K,V>
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

putAllAsync

public final NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data,
                                               long lifespan,
                                               TimeUnit lifespanUnit,
                                               long maxIdle,
                                               TimeUnit maxIdleUnit)
Description copied from interface: BasicCache
Asynchronous version of BasicCache.putAll(Map, long, TimeUnit, long, TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over BasicCache.putAll(Map, long, TimeUnit, long, TimeUnit) if used in LOCAL mode.

Specified by:
putAllAsync in interface BasicCache<K,V>
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

clearAsync

public final 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.

Specified by:
clearAsync in interface BasicCache<K,V>
Returns:
a future containing a void return type

putIfAbsentAsync

public final 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.

Specified by:
putIfAbsentAsync in interface BasicCache<K,V>
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 final 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.

Specified by:
removeAsync in interface BasicCache<K,V>
Parameters:
key - key to remove
Returns:
a future containing the value removed

removeAsync

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

Specified by:
removeAsync in interface BasicCache<K,V>
Parameters:
key - key to remove
value - value to match on
Returns:
a future containing a boolean, indicating whether the entry was removed or not

replaceAsync

public final 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.

Specified by:
replaceAsync in interface BasicCache<K,V>
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

replaceAsync

public final NotifyingFuture<Boolean> replaceAsync(K key,
                                                   V oldValue,
                                                   V newValue,
                                                   long lifespan,
                                                   TimeUnit lifespanUnit,
                                                   long maxIdle,
                                                   TimeUnit maxIdleUnit)
Description copied from interface: BasicCache
Asynchronous version of BasicCache.replace(Object, 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, Object, long, TimeUnit, long, TimeUnit) if used in LOCAL mode.

Specified by:
replaceAsync in interface BasicCache<K,V>
Parameters:
key - key to remove
oldValue - value to overwrite
newValue - 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 a boolean, indicating whether the entry was replaced or not

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).

Specified by:
getAsync in interface BasicCache<K,V>
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)

getAdvancedCache

public AdvancedCache<K,V> getAdvancedCache()
Specified by:
getAdvancedCache in interface Cache<K,V>

compact

public void compact()
Description copied from interface: Cache
Method that releases object references of cached objects held in the cache by serializing them to byte buffers. Cached objects are lazily de-serialized when accessed again, based on the calling thread's context class loader.

This can be expensive, based on the effort required to serialize cached objects.

Specified by:
compact in interface Cache<K,V>

getRpcManager

public RpcManager getRpcManager()
Description copied from interface: AdvancedCache
Returns the component in charge of communication with other caches in the cluster. If the cache's Configuration.CacheMode is Configuration.CacheMode.LOCAL, this method will return null.

Specified by:
getRpcManager in interface AdvancedCache<K,V>
Returns:
the RPC manager component associated with this cache instance or null

withFlags

public AdvancedCache<K,V> withFlags(Flag... flags)
Description copied from interface: AdvancedCache
A method that adds flags to any API call. For example, consider the following code snippet:
   cache.withFlags(Flag.FORCE_WRITE_LOCK).get(key);
 
will invoke a cache.get() with a write lock forced.

Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method.

As an alternative to setting this on every invocation, users could also consider using the DecoratedCache wrapper, as this allows for more readable code. E.g.:

    Cache forceWriteLockCache = new DecoratedCache(cache, Flag.FORCE_WRITE_LOCK);
    forceWriteLockCache.get(key1);
    forceWriteLockCache.get(key2);
    forceWriteLockCache.get(key3);
 

Specified by:
withFlags in interface AdvancedCache<K,V>
Parameters:
flags - a set of flags to apply. See the Flag documentation.
Returns:
an AdvancedCache instance on which a real operation is to be invoked, if the flags are to be applied.

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: AdvancedCache
Returns the cache loader associated associated with this cache. As an alternative to setting this on every invocation, users could also consider using the DecoratedCache wrapper.

Specified by:
getClassLoader in interface AdvancedCache<K,V>
Returns:
this cache's cache loader

with

public AdvancedCache<K,V> with(ClassLoader classLoader)
Description copied from interface: AdvancedCache
Using this operation, users can call any AdvancedCache operation with a given ClassLoader. This means that any ClassLoader happening as a result of the cache operation will be done using the ClassLoader given. For example:

When users store POJO instances in caches configured with Configuration.storeAsBinary, these instances are transformed into byte arrays. When these entries are read from the cache, a lazy unmarshalling process happens where these byte arrays are transformed back into POJO instances. Using AdvancedCache.with(ClassLoader) when reading that enables users to provide the class loader that should be used when trying to locate the classes that are constructed as a result of the unmarshalling process.

    cache.with(classLoader).get(key);
 
Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method.

As an alternative to setting this on every invocation, users could also consider using the DecoratedCache wrapper, as this allows for more readable code. E.g.:

    Cache classLoaderSpecificCache = new DecoratedCache(cache, classLoader);
    classLoaderSpecificCache.get(key1);
    classLoaderSpecificCache.get(key2);
    classLoaderSpecificCache.get(key3);
 

Specified by:
with in interface AdvancedCache<K,V>
Returns:
an AdvancedCache instance upon which operations can be called with a particular ClassLoader.

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.