public interface RemoteCache<K,V> extends BasicCache<K,V>, TransactionalCache
Cache
, but given its
nature (remote) some operations are not supported. All these unsupported operations are being overridden within this
interface and documented as such.
New operations: besides the operations inherited from Cache
, RemoteCache also adds new
operations to optimize/reduce network traffic: e.g. versioned put operation.
Concurrency: implementors of this interface will support multi-threaded access, similar to the way Cache
supports it.
Return values: previously existing values for certain Map
operations are not returned, null
is returned instead. E.g. Map.put(Object, Object)
returns the previous value associated to the
supplied key. In case of RemoteCache, this returns null.
Changing default behavior through Flag
s: it is possible to change the
default cache behaviour by using flags on an per invocation basis. E.g.
RemoteCache cache = getRemoteCache(); Object oldValue = cache.withFlags(Flag.FORCE_RETURN_VALUE).put(aKey, aValue);In the previous example, using
Flag.FORCE_RETURN_VALUE
will make the client to
also return previously existing value associated with aKey. If this flag would not be present, Infinispan
would return (by default) null. This is in order to avoid fetching a possibly large object from the remote
server, which might not be needed. The flags as set by the withFlags(Flag...)
operation only apply for the very next operation executed by the same thread on the RemoteCache.
Note on default expiration values: Due to limitations on the first
version of the protocol, it's not possible for clients to rely on default
lifespan and maxIdle values set on the server. This is because the protocol
does not support a way to tell the server that no expiration lifespan and/or
maxIdle were provided and that default values should be used. This will be
resolved in a future revision of the protocol. In the mean time, the
workaround is to explicitly provide the desired expiry lifespan/maxIdle
values in each remote cache operation.Modifier and Type | Method and Description |
---|---|
void |
addClientListener(Object listener)
Add a client listener to receive events that happen in the remote cache.
|
void |
addClientListener(Object listener,
Object[] filterFactoryParams,
Object[] converterFactoryParams)
Add a client listener to receive events that happen in the remote cache.
|
RemoteCacheClientStatisticsMXBean |
clientStatistics()
Returns client-side statistics for this cache.
|
default CloseableIteratorSet<Map.Entry<K,V>> |
entrySet() |
CloseableIteratorSet<Map.Entry<K,V>> |
entrySet(IntSet segments)
This method is identical to
entrySet() except that it will only return entries that map to the given segments. |
<T> T |
execute(String taskName,
Map<String,?> params)
Executes a remote task passing a set of named parameters
|
default <T> T |
execute(String taskName,
Map<String,?> params,
Object key)
Executes a remote task passing a set of named parameters, hinting that the task should be executed
on the server that is expected to store given key.
|
Map<K,V> |
getAll(Set<? extends K> keys)
Retrieves all of the entries for the provided keys.
|
CacheTopologyInfo |
getCacheTopologyInfo()
Returns
CacheTopologyInfo for this cache. |
DataFormat |
getDataFormat()
Return the currently
DataFormat being used. |
Set<Object> |
getListeners()
Deprecated.
Since 10.0, with no replacement
|
String |
getProtocolVersion()
Returns the HotRod protocol version supported by this RemoteCache implementation
|
RemoteCacheManager |
getRemoteCacheManager()
Returns the
RemoteCacheManager that created this cache. |
MetadataValue<V> |
getWithMetadata(K key)
Returns the
MetadataValue associated to the supplied key param, or null if it doesn't exist. |
CompletableFuture<MetadataValue<V>> |
getWithMetadataAsync(K key)
Asynchronously returns the
MetadataValue associated to the supplied key param, or null if it doesn't exist. |
boolean |
isTransactional() |
default CloseableIteratorSet<K> |
keySet() |
CloseableIteratorSet<K> |
keySet(IntSet segments)
This method is identical to
keySet() except that it will only return keys that map to the given segments. |
<E> org.reactivestreams.Publisher<Map.Entry<K,E>> |
publishEntries(String filterConverterFactory,
Object[] filterConverterParams,
Set<Integer> segments,
int batchSize)
Publishes the entries from the server in a non blocking fashion.
|
<E> org.reactivestreams.Publisher<Map.Entry<K,E>> |
publishEntriesByQuery(org.infinispan.query.dsl.Query<?> filterQuery,
Set<Integer> segments,
int batchSize)
Publish entries from the server matching a query.
|
org.reactivestreams.Publisher<Map.Entry<K,MetadataValue<V>>> |
publishEntriesWithMetadata(Set<Integer> segments,
int batchSize)
Publish entries with metadata information
|
void |
putAll(Map<? extends K,? extends V> m)
Adds or overrides each specified entry in the remote cache.
|
void |
putAll(Map<? extends K,? extends V> map,
long lifespan,
TimeUnit unit)
Adds or overrides each specified entry in the remote cache.
|
void |
putAll(Map<? extends K,? extends V> map,
long lifespan,
TimeUnit lifespanUnit,
long maxIdleTime,
TimeUnit maxIdleTimeUnit)
Adds or overrides each specified entry in the remote cache.
|
CompletableFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data)
Adds or overrides each specified entry in the remote cache.
|
CompletableFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit unit)
Adds or overrides each specified entry in the remote cache.
|
CompletableFuture<Void> |
putAllAsync(Map<? extends K,? extends V> data,
long lifespan,
TimeUnit lifespanUnit,
long maxIdle,
TimeUnit maxIdleUnit)
Adds or overrides each specified entry in the remote cache.
|
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) |
void |
removeClientListener(Object listener)
Remove a previously added client listener.
|
boolean |
removeWithVersion(K key,
long version)
Removes the given entry only if its version matches the supplied version.
|
CompletableFuture<Boolean> |
removeWithVersionAsync(K key,
long version) |
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 maxIdleTimeUnit)
An overloaded form of
ConcurrentMap.replace(Object, Object, Object) , which takes in lifespan parameters. |
boolean |
replaceWithVersion(K key,
V newValue,
long version)
Replaces the given value only if its version matches the supplied version.
|
boolean |
replaceWithVersion(K key,
V newValue,
long version,
int lifespanSeconds)
A overloaded form of
replaceWithVersion(Object, Object, long)
which takes in lifespan parameters. |
boolean |
replaceWithVersion(K key,
V newValue,
long version,
int lifespanSeconds,
int maxIdleTimeSeconds)
A overloaded form of
replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters. |
boolean |
replaceWithVersion(K key,
V newValue,
long version,
long lifespan,
TimeUnit lifespanTimeUnit,
long maxIdle,
TimeUnit maxIdleTimeUnit)
A overloaded form of
replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters. |
CompletableFuture<Boolean> |
replaceWithVersionAsync(K key,
V newValue,
long version) |
CompletableFuture<Boolean> |
replaceWithVersionAsync(K key,
V newValue,
long version,
int lifespanSeconds) |
CompletableFuture<Boolean> |
replaceWithVersionAsync(K key,
V newValue,
long version,
int lifespanSeconds,
int maxIdleSeconds) |
CompletableFuture<Boolean> |
replaceWithVersionAsync(K key,
V newValue,
long version,
long lifespanSeconds,
TimeUnit lifespanTimeUnit,
long maxIdle,
TimeUnit maxIdleTimeUnit) |
default CloseableIterator<Map.Entry<Object,Object>> |
retrieveEntries(String filterConverterFactory,
int batchSize) |
CloseableIterator<Map.Entry<Object,Object>> |
retrieveEntries(String filterConverterFactory,
Object[] filterConverterParams,
Set<Integer> segments,
int batchSize)
Retrieve entries from the server.
|
default CloseableIterator<Map.Entry<Object,Object>> |
retrieveEntries(String filterConverterFactory,
Set<Integer> segments,
int batchSize) |
CloseableIterator<Map.Entry<Object,Object>> |
retrieveEntriesByQuery(org.infinispan.query.dsl.Query<?> filterQuery,
Set<Integer> segments,
int batchSize)
Retrieve entries from the server matching a query.
|
CloseableIterator<Map.Entry<Object,MetadataValue<Object>>> |
retrieveEntriesWithMetadata(Set<Integer> segments,
int batchSize)
Retrieve entries with metadata information
|
ServerStatistics |
serverStatistics()
Returns server-side statistics for this cache.
|
default ServerStatistics |
stats()
Deprecated.
use
serverStatistics() instead |
StreamingRemoteCache<K> |
streaming()
Returns a cache where values are manipulated using
InputStream and OutputStream |
default CloseableIteratorCollection<V> |
values() |
CloseableIteratorCollection<V> |
values(IntSet segments)
This method is identical to
values() except that it will only return values that map to the given segments. |
<T,U> RemoteCache<T,U> |
withDataFormat(DataFormat dataFormat)
Return a new instance of
RemoteCache using the supplied DataFormat . |
RemoteCache<K,V> |
withFlags(Flag... flags)
Applies one or more
Flag s to the scope of a single invocation. |
compute, compute, computeIfAbsent, computeIfAbsent, computeIfPresent, computeIfPresent, getName, getVersion, merge, merge, put, put, put, putIfAbsent, putIfAbsent, replace, replace
clearAsync, computeAsync, computeAsync, computeAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfPresentAsync, computeIfPresentAsync, computeIfPresentAsync, containsKeyAsync, getAllAsync, getAsync, mergeAsync, mergeAsync, mergeAsync, putAsync, putAsync, putAsync, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, removeAsync, removeAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, sizeAsync
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, replace, replaceAll
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, size
getTransactionManager
boolean removeWithVersion(K key, long version)
VersionedEntry ve = remoteCache.getVersioned(key); //some processing remoteCache.removeWithVersion(key, ve.getVersion();Lat call (removeWithVersion) will make sure that the entry will only be removed if it hasn't been changed in between.
VersionedValue
,
getWithMetadata(Object)
V remove(Object key)
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).
The returned value is only sent back if Flag.FORCE_RETURN_VALUE
is enabled.
boolean remove(Object key, Object value)
This method requires 2 round trips to the server. The first to retrieve the value and version and a second to
remove the key with the version if the value matches. If possible user should use
getWithMetadata(Object)
and removeWithVersion(Object, long)
.
boolean replace(K key, V oldValue, V newValue)
This method requires 2 round trips to the server. The first to retrieve the value and version and a second to
replace the key with the version if the value matches. If possible user should use
getWithMetadata(Object)
and
replaceWithVersion(Object, Object, long)
.
boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit)
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.
This method requires 2 round trips to the server. The first to retrieve the value and version and a second to
replace the key with the version if the value matches. If possible user should use
getWithMetadata(Object)
and
replaceWithVersion(Object, Object, long, long, TimeUnit, long, TimeUnit)
.
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 lifespanboolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
ConcurrentMap.replace(Object, Object, Object)
, which takes in lifespan parameters.
This method requires 2 round trips to the server. The first to retrieve the value and version and a second to
replace the key with the version if the value matches. If possible user should use
getWithMetadata(Object)
and
replaceWithVersion(Object, Object, long, long, TimeUnit, long, TimeUnit)
if possible.
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
expiredmaxIdleTimeUnit
- time unit for max idle timeCompletableFuture<Boolean> removeWithVersionAsync(K key, long version)
remove(Object, Object)
boolean replaceWithVersion(K key, V newValue, long version)
removeWithVersion(Object, long)
for a sample usage of the
version-based methods.version
- numeric version that should match the one in the server
for the operation to succeedgetWithMetadata(Object)
,
VersionedValue
boolean replaceWithVersion(K key, V newValue, long version, int lifespanSeconds)
replaceWithVersion(Object, Object, long)
which takes in lifespan parameters.key
- key to usenewValue
- new value to be associated with the keyversion
- numeric version that should match the one in the server
for the operation to succeedlifespanSeconds
- lifespan of the entryboolean replaceWithVersion(K key, V newValue, long version, int lifespanSeconds, int maxIdleTimeSeconds)
replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters.key
- key to usenewValue
- new value to be associated with the keyversion
- numeric version that should match the one in the server
for the operation to succeedlifespanSeconds
- lifespan of the entrymaxIdleTimeSeconds
- the maximum amount of time this key is allowed
to be idle for before it is considered as expiredboolean replaceWithVersion(K key, V newValue, long version, long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit)
replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters.key
- key to usenewValue
- new value to be associated with the keyversion
- numeric version that should match the one in the server
for the operation to succeedlifespan
- lifespan of the entrylifespanTimeUnit
- TimeUnit
for lifespanmaxIdle
- the maximum amount of time this key is allowed
to be idle for before it is considered as expiredmaxIdleTimeUnit
- TimeUnit
for maxIdleCompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version)
replaceWithVersion(Object, Object, long)
CompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, int lifespanSeconds)
replaceWithVersion(Object, Object, long)
CompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, int lifespanSeconds, int maxIdleSeconds)
replaceWithVersion(Object, Object, long)
CompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, long lifespanSeconds, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit)
replaceWithVersion(Object, Object, long)
default CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, Set<Integer> segments, int batchSize)
CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, Object[] filterConverterParams, Set<Integer> segments, int batchSize)
filterConverterFactory
- Factory name for the KeyValueFilterConverter or null for no filtering.filterConverterParams
- Parameters to the KeyValueFilterConvertersegments
- The segments to iterate. If null all segments will be iterated. An empty set will filter out all entries.batchSize
- The number of entries transferred from the server at a time.<E> org.reactivestreams.Publisher<Map.Entry<K,E>> publishEntries(String filterConverterFactory, Object[] filterConverterParams, Set<Integer> segments, int batchSize)
Any subscriber that subscribes to the returned Publisher must not block. It is therefore recommended to offload any blocking or long running operations to a different thread and not use the invoking one. Failure to do so may cause concurrent operations to stall.
filterConverterFactory
- Factory name for the KeyValueFilterConverter or null for no filtering.filterConverterParams
- Parameters to the KeyValueFilterConvertersegments
- The segments to utilize. If null all segments will be utilized. An empty set will filter out all entries.batchSize
- The number of entries transferred from the server at a time.default CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, int batchSize)
CloseableIterator<Map.Entry<Object,Object>> retrieveEntriesByQuery(org.infinispan.query.dsl.Query<?> filterQuery, Set<Integer> segments, int batchSize)
filterQuery
- Query
segments
- The segments to iterate. If null all segments will be iterated. An empty set will filter out all entries.batchSize
- The number of entries transferred from the server at a time.CloseableIterator
<E> org.reactivestreams.Publisher<Map.Entry<K,E>> publishEntriesByQuery(org.infinispan.query.dsl.Query<?> filterQuery, Set<Integer> segments, int batchSize)
Any subscriber that subscribes to the returned Publisher must not block. It is therefore recommended to offload any blocking or long running operations to a different thread and not use the invoking one. Failure to do so may cause concurrent operations to stall.
filterQuery
- Query
segments
- The segments to utilize. If null all segments will be utilized. An empty set will filter out all entries.batchSize
- The number of entries transferred from the server at a time.CloseableIterator<Map.Entry<Object,MetadataValue<Object>>> retrieveEntriesWithMetadata(Set<Integer> segments, int batchSize)
org.reactivestreams.Publisher<Map.Entry<K,MetadataValue<V>>> publishEntriesWithMetadata(Set<Integer> segments, int batchSize)
Any subscriber that subscribes to the returned Publisher must not block. It is therefore recommended to offload any blocking or long running operations to a different thread and not use the invoking one. Failure to do so may cause concurrent operations to stall.
segments
- The segments to utilize. If null all segments will be utilized. An empty set will filter out all entries.batchSize
- The number of entries transferred from the server at a time.MetadataValue<V> getWithMetadata(K key)
MetadataValue
associated to the supplied key param, or null if it doesn't exist.CompletableFuture<MetadataValue<V>> getWithMetadataAsync(K key)
MetadataValue
associated to the supplied key param, or null if it doesn't exist.CloseableIteratorSet<K> keySet(IntSet segments)
keySet()
except that it will only return keys that map to the given segments.
Note that these segments will be determined by the remote server. Thus you should be aware of how many segments
it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same
this method may return unexpected keys.segments
- the segments of keys to return - null means all availablekeySet()
CloseableIteratorCollection<V> values(IntSet segments)
values()
except that it will only return values that map to the given segments.
Note that these segments will be determined by the remote server. Thus you should be aware of how many segments
it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same
this method may return unexpected values.segments
- the segments of values to return - null means all availablevalues()
default CloseableIteratorSet<Map.Entry<K,V>> entrySet()
CloseableIteratorSet<Map.Entry<K,V>> entrySet(IntSet segments)
entrySet()
except that it will only return entries that map to the given segments.
Note that these segments will be determined by the remote server. Thus you should be aware of how many segments
it has configured and hashing algorithm it is using. If the segments and hashing algorithm are not the same
this method may return unexpected entries.segments
- the segments of entries to return - null means all availableentrySet()
void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit unit)
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 lifespanvoid putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
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
expiredmaxIdleTimeUnit
- time unit for max idle timeputAll(java.util.Map, long, java.util.concurrent.TimeUnit)
CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
putAllAsync
in interface AsyncCache<K,V>
data
- to storeputAll(java.util.Map, long, java.util.concurrent.TimeUnit)
CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
putAllAsync
in interface AsyncCache<K,V>
data
- to storelifespan
- lifespan of entryunit
- time unit for lifespanputAll(java.util.Map, long, java.util.concurrent.TimeUnit)
CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
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 timeputAll(java.util.Map, long, java.util.concurrent.TimeUnit)
void putAll(Map<? extends K,? extends V> m)
putAll
in interface Map<K,V>
putAll(java.util.Map, long, java.util.concurrent.TimeUnit)
@Deprecated default ServerStatistics stats()
serverStatistics()
insteadRemoteCacheClientStatisticsMXBean clientStatistics()
ServerStatistics serverStatistics()
RemoteCache<K,V> withFlags(Flag... flags)
Flag
s to the scope of a single invocation. See the Flag
enumeration to for
information on available flags.
Sample usage:
remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("hello", "world");
flags
- RemoteCacheManager getRemoteCacheManager()
RemoteCacheManager
that created this cache.Map<K,V> getAll(Set<? extends K> keys)
keys
- The keys to find values forString getProtocolVersion()
void addClientListener(Object listener)
ClientListener
annotation.void addClientListener(Object listener, Object[] filterFactoryParams, Object[] converterFactoryParams)
void removeClientListener(Object listener)
@Deprecated Set<Object> getListeners()
<T> T execute(String taskName, Map<String,?> params)
default <T> T execute(String taskName, Map<String,?> params, Object key)
CacheTopologyInfo getCacheTopologyInfo()
CacheTopologyInfo
for this cache.StreamingRemoteCache<K> streaming()
InputStream
and OutputStream
<T,U> RemoteCache<T,U> withDataFormat(DataFormat dataFormat)
RemoteCache
using the supplied DataFormat
.DataFormat getDataFormat()
DataFormat
being used.boolean isTransactional()
true
if the cache can participate in a transaction, false
otherwise.Copyright © 2021 JBoss by Red Hat. All rights reserved.