public interface AdvancedCache<K,V> extends Cache<K,V>
Cache
.Modifier and Type | Method and Description |
---|---|
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
|
CacheSet<CacheEntry<K,V>> |
cacheEntrySet()
Identical to
Cache.entrySet() but is typed to return CacheEntries instead of Entries. |
Map<K,V> |
getAll(Set<?> keys)
Gets a collection of entries, returning them as
Map of the values
associated with the set of keys requested. |
Map<K,CacheEntry<K,V>> |
getAllCacheEntries(Set<?> keys)
Gets a collection of entries from the
AdvancedCache , returning them as
Map of the cache entries associated with the set of keys requested. |
AuthorizationManager |
getAuthorizationManager()
Retrieves the
AuthorizationManager if the cache has security enabled. |
AvailabilityMode |
getAvailability()
Returns the cache's availability.
|
BatchContainer |
getBatchContainer()
Returns the component in charge of batching cache operations.
|
CacheEntry<K,V> |
getCacheEntry(Object key)
Retrieves a CacheEntry corresponding to a specific key.
|
ClassLoader |
getClassLoader()
Returns the cache loader associated associated with this cache.
|
ComponentRegistry |
getComponentRegistry() |
DataContainer<K,V> |
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() |
ExpirationManager<K,V> |
getExpirationManager() |
Map<K,V> |
getGroup(String groupName)
It fetches all the keys which belong to the group.
|
List<CommandInterceptor> |
getInterceptorChain()
Retrieves the current Interceptor chain.
|
InvocationContextContainer |
getInvocationContextContainer()
Deprecated.
This method may be removed in a future version of Infinispan.
|
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... keys)
Locks a given key or keys eagerly across cache nodes in a cluster.
|
V |
put(K key,
V value,
Metadata metadata)
An overloaded form of
#put(K, V) , which takes in an instance of
Metadata which can be used to provide metadata information for
the entry being stored, such as lifespan, version of value...etc. |
void |
putAll(Map<? extends K,? extends V> map,
Metadata metadata)
An overloaded form of
Map.putAll(Map) , which takes in an instance of
Metadata which can be used to provide metadata information for
the entries being stored, such as lifespan, version of value...etc. |
CompletableFuture<V> |
putAsync(K key,
V value,
Metadata metadata)
Asynchronous version of
put(Object, Object, Metadata) which stores
metadata alongside the value. |
void |
putForExternalRead(K key,
V value,
Metadata metadata)
An overloaded form of
#putForExternalRead(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
V |
putIfAbsent(K key,
V value,
Metadata metadata)
An overloaded form of
#putIfAbsent(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
void |
removeExpired(K key,
V value,
Long lifespan)
Attempts to remove the entry if it is expired.
|
void |
removeGroup(String groupName)
It removes all the key which belongs to a group.
|
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.
|
V |
replace(K key,
V value,
Metadata metadata)
An overloaded form of
#replace(K, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
boolean |
replace(K key,
V oldValue,
V newValue,
Metadata metadata)
An overloaded form of
#replace(K, V, V) , which takes in an
instance of Metadata which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. |
void |
setAvailability(AvailabilityMode availabilityMode)
Manually change the availability of the 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.
|
clear, entrySet, evict, getAdvancedCache, getCacheConfiguration, getCacheManager, getStatus, keySet, putForExternalRead, putForExternalRead, putForExternalRead, shutdown, size, stop, values
getName, getVersion, put, put, put, putAll, putAll, putIfAbsent, putIfAbsent, remove, replace, replace, replace, replace
clearAsync, getAsync, putAllAsync, putAllAsync, putAllAsync, putAsync, putAsync, putAsync, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, removeAsync, removeAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
containsKey, containsValue, equals, get, hashCode, isEmpty, putAll
endBatch, startBatch
addListener, addListener
addListener, getListeners, removeListener
AdvancedCache<K,V> withFlags(Flag... flags)
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);
flags
- a set of flags to apply. See the Flag
documentation.AdvancedCache
instance on which a real operation is to be invoked, if the flags are
to be applied.void addInterceptor(CommandInterceptor i, int position)
i
- the interceptor to addposition
- the position to add the interceptorboolean addInterceptorAfter(CommandInterceptor i, Class<? extends CommandInterceptor> afterInterceptor)
i
- interceptor to addafterInterceptor
- interceptor type after which to place custom interceptorboolean addInterceptorBefore(CommandInterceptor i, Class<? extends CommandInterceptor> beforeInterceptor)
i
- interceptor to addbeforeInterceptor
- interceptor type before which to place custom interceptorvoid removeInterceptor(int position)
position
- the position at which to remove an interceptorvoid removeInterceptor(Class<? extends CommandInterceptor> interceptorType)
interceptorType
- type of interceptor to removeList<CommandInterceptor> getInterceptorChain()
List
of CommandInterceptor
s
configured for this cacheEvictionManager getEvictionManager()
ExpirationManager<K,V> getExpirationManager()
ComponentRegistry getComponentRegistry()
DistributionManager getDistributionManager()
DistributionManager
if the cache is configured
to use Distribution. Otherwise, returns a null.AuthorizationManager getAuthorizationManager()
AuthorizationManager
if the cache has security enabled. Otherwise returns nullboolean lock(K... keys)
Keys can be locked eagerly in the context of a transaction only.
keys
- the keys to lockFlag.FAIL_SILENTLY
.TimeoutException
- if the lock
cannot be acquired within the configured lock acquisition time.boolean lock(Collection<? extends K> keys)
Collections of keys can be locked eagerly in the context of a transaction only.
keys
- collection of keys to lockFlag.FAIL_SILENTLY
.TimeoutException
- if the lock
cannot be acquired within the configured lock acquisition time.void applyDelta(K deltaAwareValueKey, Delta delta, Object... locksToAcquire)
deltaAwareValueKey
- the key for DeltaAware objectdelta
- the delta to be applied to DeltaAware objectlocksToAcquire
- keys to be locked in DeltaAware scopeRpcManager getRpcManager()
ClusteringConfiguration.cacheMode()
is CacheMode.LOCAL
, this
method will return null.BatchContainer getBatchContainer()
@Deprecated InvocationContextContainer getInvocationContextContainer()
DataContainer<K,V> getDataContainer()
TransactionManager getTransactionManager()
LockManager getLockManager()
Stats getStats()
Stats
object that allows several statistics associated
with this cache at runtime.Stats
objectXAResource getXAResource()
XAResource
associated with this cache which can be
used to do transactional recovery.XAResource
ClassLoader getClassLoader()
DecoratedCache
wrapper.AdvancedCache<K,V> with(ClassLoader classLoader)
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 StoreAsBinaryConfiguration
,
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 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);
AdvancedCache
instance upon which operations can be called
with a particular ClassLoader
.V put(K key, V value, Metadata metadata)
#put(K, V)
, which takes in an instance of
Metadata
which can be used to provide metadata information for
the entry being stored, such as lifespan, version of value...etc.key
- key to usevalue
- value to storemetadata
- information to store alongside the valuevoid putAll(Map<? extends K,? extends V> map, Metadata metadata)
Map.putAll(Map)
, which takes in an instance of
Metadata
which can be used to provide metadata information for
the entries being stored, such as lifespan, version of value...etc.map
- the values to storemetadata
- information to store alongside the value(s)V replace(K key, V value, Metadata metadata)
#replace(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.key
- key with which the specified value is associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valueboolean replace(K key, V oldValue, V newValue, Metadata metadata)
#replace(K, V, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keymetadata
- information to store alongside the new valueV putIfAbsent(K key, V value, Metadata metadata)
#putIfAbsent(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuevoid putForExternalRead(K key, V value, Metadata metadata)
#putForExternalRead(K, V)
, which takes in an
instance of Metadata
which can be used to provide metadata
information for the entry being stored, such as lifespan, version
of value...etc. The Metadata
is only stored if the call is
successful.key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valueCompletableFuture<V> putAsync(K key, V value, Metadata metadata)
put(Object, Object, Metadata)
which stores
metadata alongside the value. This method does not block on remote calls,
even if your cache mode is synchronous. Has no benefit over
put(Object, Object, Metadata)
if used in LOCAL mode.
key
- key to usevalue
- value to storemetadata
- information to store alongside the new valueMap<K,V> getAll(Set<?> keys)
Map
of the values
associated with the set of keys requested.
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an
entry cannot be loaded for a given key, the returned Map will contain null for
value of the key.
Unlike other bulk methods if this invoked in an existing transaction all entries will be stored in the current transactional context
The returned Map
will be a copy and updates to the map will not be reflected
in the Cache and vice versa. The keys and values themselves however may not be
copies depending on if storeAsBinary is enabled and the value was retrieved from
the local node.
keys
- The keys whose associated values are to be returned.NullPointerException
- if keys is null or if keys contains a nullCacheEntry<K,V> getCacheEntry(Object key)
key
- the key whose associated cache entry is to be returnednull
if this map contains no mapping for the keyMap<K,CacheEntry<K,V>> getAllCacheEntries(Set<?> keys)
AdvancedCache
, returning them as
Map
of the cache entries associated with the set of keys requested.
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an
entry cannot be loaded for a given key, the returned Map will contain null for
value of the key.
Unlike other bulk methods if this invoked in an existing transaction all entries will be stored in the current transactional context
The returned Map
will be a copy and updates to the map will not be reflected
in the Cache and vice versa. The keys and values themselves however may not be
copies depending on if storeAsBinary is enabled and the value was retrieved from
the local node.
keys
- The keys whose associated values are to be returned.NullPointerException
- if keys is null or if keys contains a nullMap<K,V> getGroup(String groupName)
map
returned is immutable and represents the group at the time of the invocation. If you want to add
or remove keys from a group use BasicCache.put(Object, Object)
and BasicCache.remove(Object)
. To remove all the keys
in the group use removeGroup(String)
.
To improve performance you may use the flag
Flag.SKIP_CACHE_LOAD
to avoid
fetching the key/value from persistence. However, you will get an inconsistent snapshot of the group.groupName
- the group name.Map
with the key/value pairs.void removeGroup(String groupName)
groupName
- the group name.AvailabilityMode getAvailability()
AvailabilityMode.AVAILABLE
. In
clustered mode, the PartitionHandlingManager
is queried to obtain the availability mode.void setAvailability(AvailabilityMode availabilityMode)
PartitionHandlingConfiguration.enabled()
.CacheSet<CacheEntry<K,V>> cacheEntrySet()
Cache.entrySet()
but is typed to return CacheEntries instead of Entries. Please see
the other method for a description of its behaviors.
This method is needed since nested generics do not support covariance
Cache.entrySet()
void removeExpired(K key, V value, Long lifespan)
ExpirationManager
.
This command will only remove the value if the value and lifespan also match if provided.
NOTE: This method may be removed at any point including in a minor release and is not supported for external usage.
key
- the key that is expiringvalue
- the value that mapped to the given. Null means it will match any valuelifespan
- the lifespan that should match. If null is provided it will match any lifespan valueCopyright © 2016 JBoss, a division of Red Hat. All rights reserved.