public class CacheImpl<K,V> extends Object implements AdvancedCache<K,V>
Modifier and Type | Field and Description |
---|---|
protected BatchContainer |
batchContainer |
protected CommandsFactory |
commandsFactory |
protected ComponentRegistry |
componentRegistry |
protected Configuration |
config |
protected Metadata |
defaultMetadata |
protected InvocationContextContainer |
icc |
protected InvocationContextFactory |
invocationContextFactory |
protected InterceptorChain |
invoker |
protected StreamingMarshaller |
marshaller |
protected CacheNotifier |
notifier |
static String |
OBJECT_NAME |
protected RpcManager |
rpcManager |
protected TransactionManager |
transactionManager |
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 |
addListener(Object listener)
Adds a listener to the component.
|
<C> void |
addListener(Object listener,
CacheEventFilter<? super K,? super V> filter,
CacheEventConverter<? super K,? super V,C> converter)
Registers a listener that will be notified on events that pass the filter condition.
|
void |
addListener(Object listener,
KeyFilter<? super K> filter)
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
|
CacheSet<CacheEntry<K,V>> |
cacheEntrySet()
Identical to
Cache.entrySet() but is typed to return CacheEntries instead of Entries. |
void |
clear()
Removes all mappings from the cache.
|
NotifyingFuture<Void> |
clearAsync()
Asynchronous version of
#clear() . |
void |
clearOperation() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
void |
endBatch(boolean successful)
Completes a batch if one has been started using
BatchingCache.startBatch() . |
CacheSet<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this cache and cache loader across the entire cluster.
|
void |
evict(K key)
Evicts an entry from the memory of the cache.
|
EntryIterable<K,V> |
filterEntries(KeyValueFilter<? super K,? super V> filter)
Retrieve the entry iterable that can be used to iterate over the contents of this cache.
|
protected EntryIterable<K,V> |
filterEntries(KeyValueFilter<? super K,? super V> filter,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
V |
get(Object key) |
AdvancedCache<K,V> |
getAdvancedCache() |
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,V> |
getAll(Set<?> keys,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
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. |
Map<K,CacheEntry<K,V>> |
getAllCacheEntries(Set<?> keys,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
NotifyingFuture<V> |
getAsync(K key)
Asynchronous version of
#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. |
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.
|
String |
getCacheAvailability() |
Configuration |
getCacheConfiguration() |
CacheEntry |
getCacheEntry(Object key)
Retrieves a CacheEntry corresponding to a specific key.
|
CacheEntry |
getCacheEntry(Object key,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
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() |
Properties |
getConfigurationAsProperties() |
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() |
ExpirationManager |
getExpirationManager() |
Map<K,V> |
getGroup(String groupName)
It fetches all the keys which belong to the group.
|
protected Map<K,V> |
getGroup(String groupName,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
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()
Returns 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,
ExpirationManager expirationManager,
InvocationContextFactory invocationContextFactory,
InvocationContextContainer icc,
CommandsFactory commandsFactory,
InterceptorChain interceptorChain,
Configuration configuration,
CacheNotifier notifier,
ComponentRegistry componentRegistry,
TransactionManager transactionManager,
BatchContainer batchContainer,
RpcManager rpcManager,
DataContainer dataContainer,
StreamingMarshaller marshaller,
DistributionManager distributionManager,
EmbeddedCacheManager cacheManager,
ExecutorService asyncExecutor,
TransactionTable txTable,
RecoveryManager recoveryManager,
TransactionCoordinator txCoordinator,
LockManager lockManager,
AuthorizationManager authorizationManager,
GlobalConfiguration globalCfg,
PartitionHandlingManager partitionHandlingManager,
LocalTopologyManager localTopologyManager) |
boolean |
isEmpty() |
boolean |
isRebalancingEnabled() |
CacheSet<K> |
keySet()
Returns a set view of the keys contained in this cache and cache loader across the entire cluster.
|
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)
If the return value of this operation will be ignored by the application,
the user is strongly encouraged to use the
Flag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently
as possible (i.e. |
V |
put(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of
BasicCache.put(Object, Object) , which takes in lifespan parameters. |
V |
put(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit idleTimeUnit)
An overloaded form of
BasicCache.put(Object, Object) , which takes in lifespan parameters. |
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> m) |
void |
putAll(Map<? extends K,? extends V> map,
long lifespan,
TimeUnit unit)
An overloaded form of
Map.putAll(Map) , 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. |
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. |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data)
Asynchronous version of
#putAll(Map) . |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit unit)
Asynchronous version of
#putAll(Map, long, TimeUnit) . |
NotifyingFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#putAll(Map, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> |
putAsync(K key,
V value)
Asynchronous version of
#put(Object, Object) . |
NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#put(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
putAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#put(Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<V> |
putAsync(K key,
V value,
Metadata metadata)
Asynchronous version of
AdvancedCache.put(Object, Object, Metadata) which stores
metadata alongside the value. |
void |
putForExternalRead(K key,
V value)
Under special operating behavior, associates the value with the specified key.
|
void |
putForExternalRead(K key,
V value,
long lifespan,
TimeUnit lifespanUnit)
An overloaded form of
#putForExternalRead(K, V) , which takes in lifespan parameters. |
void |
putForExternalRead(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit idleTimeUnit)
An overloaded form of
#putForExternalRead(K, V) , which takes in lifespan parameters. |
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) |
V |
putIfAbsent(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of
ConcurrentMap.putIfAbsent(Object, Object) , which takes in lifespan parameters. |
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. |
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. |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value)
Asynchronous version of
#putIfAbsent(Object, Object) . |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#putIfAbsent(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
putIfAbsentAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit) . |
V |
remove(Object key)
If the return value of this operation will be ignored by the application,
the user is strongly encouraged to use the
Flag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently
as possible (i.e. |
boolean |
remove(Object key,
Object value) |
NotifyingFuture<V> |
removeAsync(Object key)
Asynchronous version of
#remove(Object) . |
NotifyingFuture<Boolean> |
removeAsync(Object key,
Object value)
Asynchronous version of
#remove(Object, Object) . |
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.
|
protected void |
removeGroup(String groupName,
EnumSet<Flag> explicitFlags,
ClassLoader explicitClassLoader) |
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) |
V |
replace(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of
ConcurrentMap.replace(Object, Object) , which takes in lifespan parameters. |
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. |
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) |
boolean |
replace(K key,
V oldValue,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of
ConcurrentMap.replace(Object, 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. |
boolean |
replace(K key,
V oldValue,
V value,
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. |
NotifyingFuture<V> |
replaceAsync(K key,
V value)
Asynchronous version of
#replace(Object, Object) . |
NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit unit)
Asynchronous version of
#replace(Object, Object, long, TimeUnit) . |
NotifyingFuture<V> |
replaceAsync(K key,
V value,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#replace(Object, Object, long, TimeUnit, long, TimeUnit) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue)
Asynchronous version of
#replace(Object, Object, Object) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit unit)
Asynchronous version of
#replace(Object, Object, Object, long, TimeUnit) . |
NotifyingFuture<Boolean> |
replaceAsync(K key,
V oldValue,
V newValue,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Asynchronous version of
#replace(Object, Object, Object, long, TimeUnit, long, TimeUnit) . |
void |
setAvailability(AvailabilityMode availability)
Manually change the availability of the cache.
|
void |
setCacheAvailability(String availabilityString) |
void |
setRebalancingEnabled(boolean enabled) |
int |
size()
Returns a count of all elements in this cache and cache loader across the entire cluster.
|
void |
start()
Invoked on component start
|
boolean |
startBatch()
Starts a batch.
|
void |
stop()
Invoked on component stop
|
String |
toString() |
CacheCollection<V> |
values()
Returns a collection view of the values contained in this cache across the entire cluster.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
public static final String OBJECT_NAME
protected InvocationContextContainer icc
protected InvocationContextFactory invocationContextFactory
protected CommandsFactory commandsFactory
protected InterceptorChain invoker
protected Configuration config
protected CacheNotifier notifier
protected BatchContainer batchContainer
protected ComponentRegistry componentRegistry
protected TransactionManager transactionManager
protected RpcManager rpcManager
protected StreamingMarshaller marshaller
protected Metadata defaultMetadata
public CacheImpl(String name)
public void injectDependencies(EvictionManager evictionManager, ExpirationManager expirationManager, InvocationContextFactory invocationContextFactory, InvocationContextContainer icc, CommandsFactory commandsFactory, InterceptorChain interceptorChain, Configuration configuration, CacheNotifier notifier, ComponentRegistry componentRegistry, TransactionManager transactionManager, BatchContainer batchContainer, RpcManager rpcManager, DataContainer dataContainer, StreamingMarshaller marshaller, DistributionManager distributionManager, EmbeddedCacheManager cacheManager, ExecutorService asyncExecutor, TransactionTable txTable, RecoveryManager recoveryManager, TransactionCoordinator txCoordinator, LockManager lockManager, AuthorizationManager authorizationManager, GlobalConfiguration globalCfg, PartitionHandlingManager partitionHandlingManager, LocalTopologyManager localTopologyManager)
public final V put(K key, V value)
BasicCache
Flag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently
as possible (i.e. avoiding needless remote or network calls).public final V put(K key, V value, long lifespan, TimeUnit unit)
BasicCache
BasicCache.put(Object, Object)
, which takes in lifespan parameters.put
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic final V putIfAbsent(K key, V value, long lifespan, TimeUnit unit)
BasicCache
ConcurrentMap.putIfAbsent(Object, Object)
, which takes in lifespan parameters.putIfAbsent
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic final void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit unit)
BasicCache
Map.putAll(Map)
, which takes in lifespan parameters. Note that the lifespan is applied
to all mappings in the map passed in.putAll
in interface BasicCache<K,V>
map
- map containing mappings to enterlifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic final V replace(K key, V value, long lifespan, TimeUnit unit)
BasicCache
ConcurrentMap.replace(Object, Object)
, which takes in lifespan parameters.replace
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit)
BasicCache
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.replace
in interface BasicCache<K,V>
key
- key to useoldValue
- value to replacevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespanpublic final V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
putIfAbsent
in interface Map<K,V>
public final NotifyingFuture<V> putAsync(K key, V value)
AsyncCache
#put(Object, Object)
. This method does not block on remote calls, even if your
cache mode is synchronous. Has no benefit over #put(Object, Object)
if used in LOCAL mode.
putAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storepublic final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit)
AsyncCache
#put(Object, Object, long, TimeUnit)
. This method does not block on remote
calls, even if your cache mode is synchronous. Has no benefit over #put(Object, Object, long, TimeUnit)
if used in LOCAL mode.putAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanpublic final NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
AsyncCache
#putAll(Map)
. This method does not block on remote calls, even if your cache mode
is synchronous. Has no benefit over #putAll(Map)
if used in LOCAL mode.putAllAsync
in interface AsyncCache<K,V>
data
- to storepublic final NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
AsyncCache
#putAll(Map, long, TimeUnit)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #putAll(Map, long, TimeUnit)
if used in LOCAL mode.putAllAsync
in interface AsyncCache<K,V>
data
- to storelifespan
- lifespan of entryunit
- time unit for lifespanpublic final NotifyingFuture<V> putIfAbsentAsync(K key, V value)
AsyncCache
#putIfAbsent(Object, Object)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #putIfAbsent(Object, Object)
if used in LOCAL mode.
putIfAbsentAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storepublic final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit)
AsyncCache
#putIfAbsent(Object, Object, long, TimeUnit)
. This method does not block on
remote calls, even if your cache mode is synchronous. Has no benefit over #putIfAbsent(Object, Object,
long, TimeUnit)
if used in LOCAL mode.putIfAbsentAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanpublic final NotifyingFuture<V> replaceAsync(K key, V value)
AsyncCache
#replace(Object, Object)
. This method does not block on remote calls, even if
your cache mode is synchronous. Has no benefit over #replace(Object, Object)
if used in LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removevalue
- value to storepublic final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit)
AsyncCache
#replace(Object, Object, long, TimeUnit)
. This method does not block on remote
calls, even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, long,
TimeUnit)
if used in LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removevalue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanpublic final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
AsyncCache
#replace(Object, Object, Object)
. This method does not block on remote calls,
even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, Object)
if used in
LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removeoldValue
- value to overwritenewValue
- value to storepublic final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit)
AsyncCache
#replace(Object, Object, Object, long, TimeUnit)
. This method does not block on
remote calls, even if your cache mode is synchronous. Has no benefit over #replace(Object, Object, Object,
long, TimeUnit)
if used in LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removeoldValue
- value to overwritenewValue
- value to storelifespan
- lifespan of entryunit
- time unit for lifespanpublic final int size()
Cache
Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache loader in case if this is not needed in the size calculation.
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
If this method is used in a transactional context, note this method will not bring additional values into the
transaction context and thus objects that haven't yet been read will act in a
IsolationLevel.READ_COMMITTED
behavior irrespective of the configured
isolation level. However values that have been previously modified or read that are in the context will be
adhered to. e.g. any write modification or any previous read when using
IsolationLevel.REPEATABLE_READ
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.
public final boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public final boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public final CacheEntry getCacheEntry(Object key, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public final CacheEntry getCacheEntry(Object key)
AdvancedCache
getCacheEntry
in interface AdvancedCache<K,V>
key
- the key whose associated cache entry is to be returnednull
if this map contains no mapping for the keypublic Map<K,V> getAll(Set<?> keys)
AdvancedCache
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.
getAll
in interface AdvancedCache<K,V>
keys
- The keys whose associated values are to be returned.public final Map<K,V> getAll(Set<?> keys, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public Map<K,CacheEntry<K,V>> getAllCacheEntries(Set<?> keys)
AdvancedCache
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.
getAllCacheEntries
in interface AdvancedCache<K,V>
keys
- The keys whose associated values are to be returned.public final Map<K,CacheEntry<K,V>> getAllCacheEntries(Set<?> keys, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public EntryIterable<K,V> filterEntries(KeyValueFilter<? super K,? super V> filter)
AdvancedCache
Iterable.iterator()
will cause a new request chain to retrieve all of the values in
the cache, including any configured loaders. This iterator is performed in memory sensitive way and thus works
for distributed caches unlike Cache.entrySet()
.
Whenever possible a user should provide a converter through
EntryIterable.converter(org.infinispan.filter.Converter)
to reduce value
payloads or create projection views.
This iterator does not participate in any ongoing transaction that may be present. This is because
IsolationLevel.REPEATABLE_READ
transactions have to keep track of all
the entries they have read (which in this case would include the entries that did not match the filter).
Keeping all the values on a single node would negate the benefits of using a filter and/or converter, and in many
cases it would cause OutOfMemoryErrors. If it is desired to remove entries the
BasicCache.remove(Object)
method or another similar method may be used which would
participate in the transaction
The iterable should always be closed after finished with it, using the standard try/finally or try with resource idioms to ensure that any current resources are freed if an exception prevents full iteration of iterator. Note this will prevent any ongoing iterators that were created from it from progressing further.
filterEntries
in interface AdvancedCache<K,V>
filter
- The filter to use. Note this is required and for distributed caches must be serializable. Callbacks
to the filter will never provide a key or value that will be null.protected EntryIterable<K,V> filterEntries(KeyValueFilter<? super K,? super V> filter, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public Map<K,V> getGroup(String groupName)
AdvancedCache
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 AdvancedCache.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.getGroup
in interface AdvancedCache<K,V>
groupName
- the group name.Map
with the key/value pairs.protected final Map<K,V> getGroup(String groupName, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public void removeGroup(String groupName)
AdvancedCache
removeGroup
in interface AdvancedCache<K,V>
groupName
- the group name.protected final void removeGroup(String groupName, EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader)
public final V remove(Object key)
BasicCache
Flag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently
as possible (i.e. avoiding needless remote or network calls).public void removeExpired(K key, V value, Long lifespan)
AdvancedCache
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.
removeExpired
in interface AdvancedCache<K,V>
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 valuepublic final void clearOperation()
public final void clear()
Cache
public CacheSet<K> keySet()
Cache
Set.toArray()
, Set.toArray(Object[])
,
Set.size()
, Set.retainAll(Collection)
and Set.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
CloseableIteratorSet
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.
UnsupportedOperationException
if invoked.
Set.add(Object)
Set.addAll(java.util.Collection)
public CacheCollection<V> values()
Cache
Collection.toArray()
, Collection.toArray(Object[])
,
Collection.size()
, Collection.retainAll(Collection)
and Collection.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
* Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
This class implements the CloseableIteratorCollection
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.
The iterator retrieved using CloseableIteratorCollection.iterator()
supports the remove method, however the
iterator retrieved from CacheStream.iterator()
will not support remove.
UnsupportedOperationException
if invoked.
Set.add(Object)
Set.addAll(java.util.Collection)
public CacheSet<CacheEntry<K,V>> cacheEntrySet()
AdvancedCache
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
cacheEntrySet
in interface AdvancedCache<K,V>
Cache.entrySet()
public CacheSet<Map.Entry<K,V>> entrySet()
Cache
Set.toArray()
, Set.toArray(Object[])
,
Set.size()
, Set.retainAll(Collection)
and Set.iterator()
methods as they will traverse the entire contents of the cluster including a configured
CacheLoader
and remote entries. The former 2 methods especially have a
very high likely hood of causing a OutOfMemoryError
due to storing all the keys in the entire
cluster in the array.
Use involving execution of this method on a production system is not recommended as they can be quite expensive
operations
* Flag.SKIP_CACHE_LOAD
flag should be used to
avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to
prevent OutOfMemoryError
)
Also if you want the local contents only you can use the Flag.CACHE_MODE_LOCAL
flag so
that other remote nodes are not queried for data. However the loader will still be used unless the previously
mentioned Flag.SKIP_CACHE_LOAD
is also configured.
Map.Entry#setValue(Object)
and it will update
the cache as well. Also this backing set does allow addition of a new Map.Entry(s) via the
Set.add(Object)
or Set.addAll(java.util.Collection)
methods.
CloseableIteratorSet
interface which creates a
CloseableIterator
instead of a regular one. This means this iterator must be
explicitly closed either through try with resource or calling the close method directly. Technically this iterator
will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.public final void putForExternalRead(K key, V value)
Cache
ConcurrentMap.putIfAbsent(Object, Object)
)
putForExternalRead
in interface Cache<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.public void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit)
Cache
#putForExternalRead(K, V)
, which takes in lifespan parameters.putForExternalRead
in interface Cache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- unit of measurement for the lifespanpublic void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
Cache
#putForExternalRead(K, V)
, which takes in lifespan parameters.putForExternalRead
in interface Cache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic void putForExternalRead(K key, V value, Metadata metadata)
AdvancedCache
#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.putForExternalRead
in interface AdvancedCache<K,V>
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 valuepublic final void evict(K key)
Cache
BasicCache.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.public Configuration getCacheConfiguration()
getCacheConfiguration
in interface Cache<K,V>
public void addListener(Object listener)
Listenable
Listener
and
further to that, contain methods annotated appropriately, otherwise the listener will not be registered.
See the Listener
annotation for more information.
addListener
in interface Listenable
listener
- must not be null.public void addListener(Object listener, KeyFilter<? super K> filter)
FilteringListenable
Listener
and
further to that, contain methods annotated appropriately, otherwise the listener will not be registered.
See the Listener
annotation for more information.
addListener
in interface FilteringListenable<K,V>
listener
- must not be null.public <C> void addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
FilteringListenable
Some implementations may provide optimizations when a
CacheEventFilterConverter
is provided as both arguments
to the filter and converter arguments. Note the provided object must have reference equality ie. (==)
to be recognized. This allows for the filter and conversion step to take place in the same method call reducing
possible overhead.
addListener
in interface FilteringListenable<K,V>
C
- The type of the resultant value after being convertedlistener
- The listener to callback upon event notifications. Must not be null.filter
- The filter to see if the notification should be sent to the listener. Can be null.converter
- The converter to apply to the entry before being sent to the listener. Can be null.public void removeListener(Object listener)
Listenable
removeListener
in interface Listenable
listener
- listener to remove. Must not be null.public Set<Object> getListeners()
getListeners
in interface Listenable
public boolean lock(K... keys)
AdvancedCache
Keys can be locked eagerly in the context of a transaction only.
lock
in interface AdvancedCache<K,V>
keys
- the keys to lockFlag.FAIL_SILENTLY
.public boolean lock(Collection<? extends K> keys)
AdvancedCache
Collections of keys can be locked eagerly in the context of a transaction only.
lock
in interface AdvancedCache<K,V>
keys
- collection of keys to lockFlag.FAIL_SILENTLY
.public void applyDelta(K deltaAwareValueKey, Delta delta, Object... locksToAcquire)
AdvancedCache
applyDelta
in interface AdvancedCache<K,V>
deltaAwareValueKey
- the key for DeltaAware objectdelta
- the delta to be applied to DeltaAware objectlocksToAcquire
- keys to be locked in DeltaAware scopepublic void start()
Lifecycle
public void stop()
Lifecycle
public List<CommandInterceptor> getInterceptorChain()
AdvancedCache
getInterceptorChain
in interface AdvancedCache<K,V>
List
of CommandInterceptor
s
configured for this cachepublic void addInterceptor(CommandInterceptor i, int position)
AdvancedCache
addInterceptor
in interface AdvancedCache<K,V>
i
- the interceptor to addposition
- the position to add the interceptorpublic boolean addInterceptorAfter(CommandInterceptor i, Class<? extends CommandInterceptor> afterInterceptor)
AdvancedCache
addInterceptorAfter
in interface AdvancedCache<K,V>
i
- interceptor to addafterInterceptor
- interceptor type after which to place custom interceptorpublic boolean addInterceptorBefore(CommandInterceptor i, Class<? extends CommandInterceptor> beforeInterceptor)
AdvancedCache
addInterceptorBefore
in interface AdvancedCache<K,V>
i
- interceptor to addbeforeInterceptor
- interceptor type before which to place custom interceptorpublic void removeInterceptor(int position)
AdvancedCache
removeInterceptor
in interface AdvancedCache<K,V>
position
- the position at which to remove an interceptorpublic void removeInterceptor(Class<? extends CommandInterceptor> interceptorType)
AdvancedCache
removeInterceptor
in interface AdvancedCache<K,V>
interceptorType
- type of interceptor to removepublic EvictionManager getEvictionManager()
getEvictionManager
in interface AdvancedCache<K,V>
public ExpirationManager getExpirationManager()
getExpirationManager
in interface AdvancedCache<K,V>
public ComponentRegistry getComponentRegistry()
getComponentRegistry
in interface AdvancedCache<K,V>
public DistributionManager getDistributionManager()
AdvancedCache
DistributionManager
if the cache is configured
to use Distribution. Otherwise, returns a null.getDistributionManager
in interface AdvancedCache<K,V>
public AuthorizationManager getAuthorizationManager()
AdvancedCache
AuthorizationManager
if the cache has security enabled. Otherwise returns nullgetAuthorizationManager
in interface AdvancedCache<K,V>
public ComponentStatus getStatus()
public String getCacheStatus()
public AvailabilityMode getAvailability()
AdvancedCache
AvailabilityMode.AVAILABLE
. In
clustered mode, the PartitionHandlingManager
is queried to obtain the availability mode.getAvailability
in interface AdvancedCache<K,V>
public void setAvailability(AvailabilityMode availability)
AdvancedCache
PartitionHandlingConfiguration.enabled()
.setAvailability
in interface AdvancedCache<K,V>
public String getCacheAvailability()
public void setCacheAvailability(String availabilityString) throws Exception
Exception
public boolean isRebalancingEnabled()
public void setRebalancingEnabled(boolean enabled)
public boolean startBatch()
BatchingCache
startBatch
in interface BatchingCache
public void endBatch(boolean successful)
BatchingCache
BatchingCache.startBatch()
. If no batch has been started, this is a
no-op.
endBatch
in interface BatchingCache
successful
- if true, the batch completes, otherwise the batch is aborted and changes are not committed.public String getName()
BasicCache
getName
in interface BasicCache<K,V>
public String getCacheName()
public String getVersion()
getVersion
in interface BasicCache<K,V>
public BatchContainer getBatchContainer()
AdvancedCache
getBatchContainer
in interface AdvancedCache<K,V>
public InvocationContextContainer getInvocationContextContainer()
AdvancedCache
getInvocationContextContainer
in interface AdvancedCache<K,V>
public DataContainer getDataContainer()
AdvancedCache
getDataContainer
in interface AdvancedCache<K,V>
public TransactionManager getTransactionManager()
AdvancedCache
getTransactionManager
in interface AdvancedCache<K,V>
public LockManager getLockManager()
AdvancedCache
getLockManager
in interface AdvancedCache<K,V>
public EmbeddedCacheManager getCacheManager()
Cache
getCacheManager
in interface Cache<K,V>
public Stats getStats()
AdvancedCache
Stats
object that allows several statistics associated
with this cache at runtime.getStats
in interface AdvancedCache<K,V>
Stats
objectpublic XAResource getXAResource()
AdvancedCache
XAResource
associated with this cache which can be
used to do transactional recovery.getXAResource
in interface AdvancedCache<K,V>
XAResource
public final V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
BasicCache
BasicCache.put(Object, Object)
, which takes in lifespan parameters.put
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic final V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
BasicCache
ConcurrentMap.putIfAbsent(Object, Object)
, which takes in lifespan parameters.putIfAbsent
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic final void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
BasicCache
Map.putAll(Map)
, which takes in lifespan parameters. Note that the lifespan is applied
to all mappings in the map passed in.putAll
in interface BasicCache<K,V>
map
- map containing mappings to enterlifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic final V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
BasicCache
ConcurrentMap.replace(Object, Object)
, which takes in lifespan parameters.replace
in interface BasicCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit)
BasicCache
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.replace
in interface BasicCache<K,V>
key
- key to useoldValue
- value to replacevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdleTime
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredidleTimeUnit
- time unit for max idle timepublic final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
AsyncCache
#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 #put(Object, Object, long,
TimeUnit, long, TimeUnit)
if used in LOCAL mode.putAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of entrylifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit
- time unit for max idle timepublic final NotifyingFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
AsyncCache
#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 #putAll(Map, long, TimeUnit,
long, TimeUnit)
if used in LOCAL mode.putAllAsync
in interface AsyncCache<K,V>
data
- to storelifespan
- lifespan of entrylifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit
- time unit for max idle timepublic final NotifyingFuture<Void> clearAsync()
AsyncCache
#clear()
. This method does not block on remote calls, even if your cache mode is
synchronous. Has no benefit over #clear()
if used in LOCAL mode.clearAsync
in interface AsyncCache<K,V>
public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
AsyncCache
#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 #putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.putIfAbsentAsync
in interface AsyncCache<K,V>
key
- key to usevalue
- value to storelifespan
- lifespan of entrylifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit
- time unit for max idle timepublic final NotifyingFuture<V> removeAsync(Object key)
AsyncCache
#remove(Object)
. This method does not block on remote calls, even if your cache
mode is synchronous. Has no benefit over #remove(Object)
if used in LOCAL mode.removeAsync
in interface AsyncCache<K,V>
key
- key to removepublic final NotifyingFuture<Boolean> removeAsync(Object key, Object value)
AsyncCache
#remove(Object, Object)
. This method does not block on remote calls, even if your
cache mode is synchronous. Has no benefit over #remove(Object, Object)
if used in LOCAL mode.removeAsync
in interface AsyncCache<K,V>
key
- key to removevalue
- value to match onpublic final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
AsyncCache
#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 #replace(Object,
Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removevalue
- value to storelifespan
- lifespan of entrylifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit
- time unit for max idle timepublic final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
AsyncCache
#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 #replace(Object, Object, Object, long, TimeUnit, long, TimeUnit)
if used in LOCAL mode.replaceAsync
in interface AsyncCache<K,V>
key
- key to removeoldValue
- value to overwritenewValue
- value to storelifespan
- lifespan of entrylifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as
expiredmaxIdleUnit
- time unit for max idle timepublic NotifyingFuture<V> getAsync(K key)
AsyncCache
#get(Object)
that allows user code to
retrieve the value associated with a key at a later stage, hence allowing
multiple parallel get requests to be sent. Normally, when this method
detects that the value is likely to be retrieved from from a remote
entity, it will span a different thread in order to allow the
asynchronous get call to return immediately. If the call will definitely
resolve locally, for example when the cache is configured with LOCAL mode
and no stores are configured, the get asynchronous call will act
sequentially and will have no different to #get(Object)
.getAsync
in interface AsyncCache<K,V>
key
- key to retrieve#get(Object)
public AdvancedCache<K,V> getAdvancedCache()
getAdvancedCache
in interface Cache<K,V>
public RpcManager getRpcManager()
AdvancedCache
ClusteringConfiguration.cacheMode()
is CacheMode.LOCAL
, this
method will return null.getRpcManager
in interface AdvancedCache<K,V>
public AdvancedCache<K,V> withFlags(Flag... flags)
AdvancedCache
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);
withFlags
in interface AdvancedCache<K,V>
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.public ClassLoader getClassLoader()
AdvancedCache
DecoratedCache
wrapper.getClassLoader
in interface AdvancedCache<K,V>
public AdvancedCache<K,V> with(ClassLoader classLoader)
AdvancedCache
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 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);
with
in interface AdvancedCache<K,V>
AdvancedCache
instance upon which operations can be called
with a particular ClassLoader
.public V put(K key, V value, Metadata metadata)
AdvancedCache
#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.put
in interface AdvancedCache<K,V>
key
- key to usevalue
- value to storemetadata
- information to store alongside the valuepublic void putAll(Map<? extends K,? extends V> map, Metadata metadata)
AdvancedCache
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.putAll
in interface AdvancedCache<K,V>
map
- the values to storemetadata
- information to store alongside the value(s)public V replace(K key, V value, Metadata metadata)
AdvancedCache
#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.replace
in interface AdvancedCache<K,V>
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic boolean replace(K key, V oldValue, V value, Metadata metadata)
AdvancedCache
#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.replace
in interface AdvancedCache<K,V>
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keyvalue
- value to be associated with the specified keymetadata
- information to store alongside the new valuepublic V putIfAbsent(K key, V value, Metadata metadata)
AdvancedCache
#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.putIfAbsent
in interface AdvancedCache<K,V>
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 valuepublic NotifyingFuture<V> putAsync(K key, V value, Metadata metadata)
AdvancedCache
AdvancedCache.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
AdvancedCache.put(Object, Object, Metadata)
if used in LOCAL mode.
putAsync
in interface AdvancedCache<K,V>
key
- key to usevalue
- value to storemetadata
- information to store alongside the new valuepublic Properties getConfigurationAsProperties()
Copyright © 2021 JBoss, a division of Red Hat. All rights reserved.