org.infinispan
Class AbstractDelegatingAdvancedCache<K,V>

java.lang.Object
  extended by org.infinispan.AbstractDelegatingCache<K,V>
      extended by org.infinispan.AbstractDelegatingAdvancedCache<K,V>
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>, AdvancedCache<K,V>, BasicCache<K,V>, Cache<K,V>, Lifecycle, Listenable
Direct Known Subclasses:
ClassLoaderSpecfiedCache, DecoratedCache

public abstract class AbstractDelegatingAdvancedCache<K,V>
extends AbstractDelegatingCache<K,V>
implements AdvancedCache<K,V>

Similar to AbstractDelegatingCache, but for AdvancedCache.

Author:
Mircea.Markus@jboss.com
See Also:
AbstractDelegatingCache

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  AdvancedCache<K,V> cache
           
 
Constructor Summary
AbstractDelegatingAdvancedCache(AdvancedCache<K,V> cache)
           
 
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 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
 AdvancedCache<K,V> getAdvancedCache()
           
 BatchContainer getBatchContainer()
          Returns the component in charge of batching cache operations.
 ClassLoader getClassLoader()
          Returns the cache loader associated associated with this cache.
 ComponentRegistry getComponentRegistry()
           
 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.
 LockManager getLockManager()
          Returns the component that deals with all aspects of acquiring and releasing locks for cache entries.
 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.
 TransactionManager getTransactionManager()
          Returns the transaction manager configured for this cache.
 XAResource getXAResource()
          Returns the XAResource associated with this cache which can be used to do transactional recovery.
 boolean lock(Collection<? extends K> keys)
          Locks collections of keys eagerly across cache nodes in a cluster.
 boolean lock(K... key)
          Locks a given key or keys eagerly across cache nodes in a cluster.
protected  void putForExternalRead(K key, V value, EnumSet<Flag> flags, ClassLoader classLoader)
           
 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.
 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.AbstractDelegatingCache
addListener, clear, clearAsync, compact, containsKey, containsValue, endBatch, entrySet, evict, get, getAsync, getCacheConfiguration, getCacheManager, getConfiguration, getDelegate, getListeners, getName, getStatus, getVersion, isEmpty, keySet, put, put, put, putAll, putAll, putAll, putAllAsync, putAllAsync, putAllAsync, putAsync, putAsync, putAsync, putForExternalRead, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, remove, remove, removeAsync, removeAsync, removeListener, replace, replace, replace, replace, replace, replace, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, set, size, start, startBatch, stop, toString, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.infinispan.Cache
compact, endBatch, entrySet, evict, getCacheConfiguration, getCacheManager, getConfiguration, getStatus, keySet, putForExternalRead, startBatch, values
 
Methods inherited from interface org.infinispan.api.BasicCache
clearAsync, getAsync, getName, getVersion, put, put, putAll, putAll, putAllAsync, putAllAsync, putAllAsync, putAsync, putAsync, putAsync, putIfAbsent, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, removeAsync, removeAsync, replace, replace, replace, replace, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size
 
Methods inherited from interface org.infinispan.lifecycle.Lifecycle
start, stop
 
Methods inherited from interface org.infinispan.notifications.Listenable
addListener, getListeners, removeListener
 

Field Detail

cache

protected final AdvancedCache<K,V> cache
Constructor Detail

AbstractDelegatingAdvancedCache

public AbstractDelegatingAdvancedCache(AdvancedCache<K,V> cache)
Method Detail

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

getAdvancedCache

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

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

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.

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

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

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

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.

lock

public boolean lock(K... key)
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:
key - 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

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

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.

putForExternalRead

protected final void putForExternalRead(K key,
                                        V value,
                                        EnumSet<Flag> flags,
                                        ClassLoader classLoader)

-->

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