Class RemoteCacheImpl<K,V>
- java.lang.Object
-
- org.infinispan.client.hotrod.impl.RemoteCacheSupport<K,V>
-
- org.infinispan.client.hotrod.impl.RemoteCacheImpl<K,V>
-
- All Implemented Interfaces:
ConcurrentMap<K,V>
,Map<K,V>
,RemoteCache<K,V>
,org.infinispan.commons.api.AsyncCache<K,V>
,org.infinispan.commons.api.BasicCache<K,V>
,org.infinispan.commons.api.Lifecycle
,org.infinispan.commons.api.TransactionalCache
- Direct Known Subclasses:
InvalidatedNearRemoteCache
,TransactionalRemoteCacheImpl
public class RemoteCacheImpl<K,V> extends RemoteCacheSupport<K,V>
- Since:
- 4.1
- Author:
- Mircea.Markus@jboss.com
-
-
Field Summary
Fields Modifier and Type Field Description protected OperationsFactory
operationsFactory
-
Fields inherited from class org.infinispan.client.hotrod.impl.RemoteCacheSupport
defaultLifespan, defaultMaxIdleTime
-
-
Constructor Summary
Constructors Constructor Description RemoteCacheImpl(RemoteCacheManager rcm, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.protected void
assertRemoteCacheManagerIsStarted()
void
clear()
CompletableFuture<Void>
clearAsync()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
org.infinispan.commons.util.CloseableIteratorSet<Map.Entry<K,V>>
entrySet()
<T> T
execute(String taskName, Map<String,?> params)
Executes a remote script passing a set of named parameters<T> T
execute(String taskName, Map<String,?> params, Object key)
Executes a remote script passing a set of named parameters, hinting that the script should be executed on the server that is expected to store given key.V
get(Object key)
Map<K,V>
getAll(Set<? extends K> keys)
Retrieves all of the entries for the provided keys.CompletableFuture<V>
getAsync(Object key)
Map<K,V>
getBulk()
Bulk get operations, returns all the entries within the remote cache.Map<K,V>
getBulk(int size)
Same asRemoteCache.getBulk()
, but limits the returned set of values to the specified size.CacheTopologyInfo
getCacheTopologyInfo()
ReturnsCacheTopologyInfo
for this cache.DataFormat
getDataFormat()
Return the currentlyDataFormat
being used.Set<Object>
getListeners()
Returns a set with all the listeners registered by this client for the given cache.String
getName()
OperationsFactory
getOperationsFactory()
String
getProtocolVersion()
Returns the HotRod protocol version supported by this RemoteCache implementationRemoteCacheManager
getRemoteCacheManager()
Returns theRemoteCacheManager
that created this cache.String
getVersion()
VersionedValue<V>
getVersioned(K key)
Returns theVersionedValue
associated to the supplied key param, or null if it doesn't exist.MetadataValue<V>
getWithMetadata(K key)
Returns theMetadataValue
associated to the supplied key param, or null if it doesn't exist.boolean
hasCompatibility()
void
init(org.infinispan.commons.marshall.Marshaller marshaller, OperationsFactory operationsFactory, int estimateKeySize, int estimateValueSize, int batchSize)
boolean
isEmpty()
org.infinispan.commons.util.CloseableIteratorSet<K>
keySet()
protected byte[]
keyToBytes(Object o)
PingOperation.PingResult
ping()
V
put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
void
putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Synthetic operation.CompletableFuture<Void>
putAllAsync(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Synthetic operation.CompletableFuture<V>
putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
V
putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
V
remove(Object key)
boolean
remove(Object key, Object value)
CompletableFuture<V>
removeAsync(Object key)
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)
V
replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
boolean
replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
boolean
replaceWithVersion(K key, V newValue, long version, int lifespanSeconds, int maxIdleTimeSeconds)
A overloaded form ofRemoteCache.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 ofRemoteCache.replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters.CompletableFuture<Boolean>
replaceWithVersionAsync(K key, V newValue, long version, int lifespanSeconds, int maxIdleSeconds)
CompletableFuture<Boolean>
replaceWithVersionAsync(K key, V newValue, long version, long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit)
PingOperation.PingResult
resolveCompatibility()
org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>>
retrieveEntries(String filterConverterFactory, int batchSize)
org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>>
retrieveEntries(String filterConverterFactory, Object[] filterConverterParams, Set<Integer> segments, int batchSize)
Retrieve entries from the serverorg.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>>
retrieveEntries(String filterConverterFactory, Set<Integer> segments, int batchSize)
org.infinispan.commons.util.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.org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,MetadataValue<Object>>>
retrieveEntriesWithMetadata(Set<Integer> segments, int batchSize)
Retrieve entries with metadata informationprotected void
set(K key, V value)
This is intentionally a non-public method meant as an integration point for bytecode manipulation.int
size()
void
start()
ServerStatistics
stats()
void
stop()
StreamingRemoteCache<K>
streaming()
Returns a cache where values are manipulated usingInputStream
andOutputStream
org.infinispan.commons.util.CloseableIteratorCollection<V>
values()
protected byte[]
valueToBytes(Object o)
<T,U>
RemoteCache<T,U>withDataFormat(DataFormat newDataFormat)
Return a new instance ofRemoteCache
using the suppliedDataFormat
.RemoteCache<K,V>
withFlags(Flag... flags)
Applies one or moreFlag
s to the scope of a single invocation.-
Methods inherited from class org.infinispan.client.hotrod.impl.RemoteCacheSupport
merge, merge, merge, put, put, putAll, putAll, putAllAsync, putAllAsync, putAsync, putAsync, putIfAbsent, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, removeAsync, replace, replace, replace, replace, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceWithVersion, replaceWithVersion, replaceWithVersionAsync, replaceWithVersionAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.commons.api.AsyncCache
containsKeyAsync, getAllAsync
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, replaceAll
-
-
-
-
Field Detail
-
operationsFactory
protected OperationsFactory operationsFactory
-
-
Constructor Detail
-
RemoteCacheImpl
public RemoteCacheImpl(RemoteCacheManager rcm, String name)
-
-
Method Detail
-
init
public void init(org.infinispan.commons.marshall.Marshaller marshaller, OperationsFactory operationsFactory, int estimateKeySize, int estimateValueSize, int batchSize)
-
getOperationsFactory
public OperationsFactory getOperationsFactory()
-
getRemoteCacheManager
public RemoteCacheManager getRemoteCacheManager()
Description copied from interface:RemoteCache
Returns theRemoteCacheManager
that created this cache.
-
removeWithVersion
public boolean removeWithVersion(K key, long version)
Description copied from interface:RemoteCache
Removes the given entry only if its version matches the supplied version. A typical use case looks like this: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.- Returns:
- true if the entry has been removed
- See Also:
VersionedValue
,RemoteCache.getVersioned(Object)
-
removeWithVersionAsync
public CompletableFuture<Boolean> removeWithVersionAsync(K key, long version)
- See Also:
RemoteCache.remove(Object, Object)
-
replaceWithVersion
public boolean replaceWithVersion(K key, V newValue, long version, int lifespanSeconds, int maxIdleTimeSeconds)
Description copied from interface:RemoteCache
A overloaded form ofRemoteCache.replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters.- 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 expired- Returns:
- true if the value was replaced
-
replaceWithVersion
public boolean replaceWithVersion(K key, V newValue, long version, long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit)
Description copied from interface:RemoteCache
A overloaded form ofRemoteCache.replaceWithVersion(Object, Object, long)
which takes in lifespan and maximum idle time parameters.- 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 maxIdle- Returns:
- true if the value was replaced
-
replaceWithVersionAsync
public CompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, int lifespanSeconds, int maxIdleSeconds)
-
replaceWithVersionAsync
public CompletableFuture<Boolean> replaceWithVersionAsync(K key, V newValue, long version, long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit)
-
retrieveEntries
public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, Object[] filterConverterParams, Set<Integer> segments, int batchSize)
Description copied from interface:RemoteCache
Retrieve entries from the server- Parameters:
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.- Returns:
- Iterator for the entries
-
retrieveEntries
public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, Set<Integer> segments, int batchSize)
-
retrieveEntries
public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>> retrieveEntries(String filterConverterFactory, int batchSize)
-
retrieveEntriesByQuery
public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,Object>> retrieveEntriesByQuery(org.infinispan.query.dsl.Query filterQuery, Set<Integer> segments, int batchSize)
Description copied from interface:RemoteCache
Retrieve entries from the server matching a query.- Parameters:
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.- Returns:
CloseableIterator
-
retrieveEntriesWithMetadata
public org.infinispan.commons.util.CloseableIterator<Map.Entry<Object,MetadataValue<Object>>> retrieveEntriesWithMetadata(Set<Integer> segments, int batchSize)
Description copied from interface:RemoteCache
Retrieve entries with metadata information
-
getVersioned
public VersionedValue<V> getVersioned(K key)
Description copied from interface:RemoteCache
Returns theVersionedValue
associated to the supplied key param, or null if it doesn't exist.
-
getWithMetadata
public MetadataValue<V> getWithMetadata(K key)
Description copied from interface:RemoteCache
Returns theMetadataValue
associated to the supplied key param, or null if it doesn't exist.
-
putAll
public void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Description copied from interface:RemoteCache
Synthetic operation.
-
putAllAsync
public CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Description copied from interface:RemoteCache
Synthetic operation.
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
stats
public ServerStatistics stats()
-
put
public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
putIfAbsent
public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
replace
public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
replace
public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
Description copied from interface:RemoteCache
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
RemoteCache.getWithMetadata(Object)
andRemoteCache.replaceWithVersion(Object, Object, long, long, TimeUnit, long, TimeUnit)
if possible.
-
putAsync
public CompletableFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
clearAsync
public CompletableFuture<Void> clearAsync()
-
putIfAbsentAsync
public CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
removeAsync
public CompletableFuture<V> removeAsync(Object key)
-
replaceAsync
public CompletableFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
containsKey
public boolean containsKey(Object key)
-
containsValue
public boolean containsValue(Object value)
-
getAll
public Map<K,V> getAll(Set<? extends K> keys)
Description copied from interface:RemoteCache
Retrieves all of the entries for the provided keys. A key will not be present in the resulting map if the entry was not found in the cache.- Parameters:
keys
- The keys to find values for- Returns:
- The entries that were present for the given keys
-
getBulk
public Map<K,V> getBulk()
Description copied from interface:RemoteCache
Bulk get operations, returns all the entries within the remote cache.- Returns:
- the returned values depend on the configuration of the back-end infinispan servers. Read this for more details. The returned Map is unmodifiable.
-
getBulk
public Map<K,V> getBulk(int size)
Description copied from interface:RemoteCache
Same asRemoteCache.getBulk()
, but limits the returned set of values to the specified size. No ordering is guaranteed, and there is no guarantee that "size" elements are returned( e.g. if the number of elements in the back-end server is smaller that "size")
-
remove
public V remove(Object key)
Description copied from interface:RemoteCache
The returned value is only sent back if
Flag.FORCE_RETURN_VALUE
is enabled.
-
remove
public boolean remove(Object key, Object value)
Description copied from interface:RemoteCache
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
RemoteCache.getWithMetadata(Object)
andRemoteCache.removeWithVersion(Object, long)
.
-
clear
public void clear()
-
start
public void start()
-
stop
public void stop()
-
getName
public String getName()
-
getVersion
public String getVersion()
-
getProtocolVersion
public String getProtocolVersion()
Description copied from interface:RemoteCache
Returns the HotRod protocol version supported by this RemoteCache implementation
-
addClientListener
public void addClientListener(Object listener)
Description copied from interface:RemoteCache
Add a client listener to receive events that happen in the remote cache. The listener object must be annotated with @ClientListener
annotation.
-
addClientListener
public void addClientListener(Object listener, Object[] filterFactoryParams, Object[] converterFactoryParams)
Description copied from interface:RemoteCache
Add a client listener to receive events that happen in the remote cache. The listener object must be annotated with @ClientListener annotation.
-
removeClientListener
public void removeClientListener(Object listener)
Description copied from interface:RemoteCache
Remove a previously added client listener. If the listener was not added before, this operation is a no-op.
-
getListeners
public Set<Object> getListeners()
Description copied from interface:RemoteCache
Returns a set with all the listeners registered by this client for the given cache.
-
withFlags
public RemoteCache<K,V> withFlags(Flag... flags)
Description copied from interface:RemoteCache
Applies one or moreFlag
s to the scope of a single invocation. See theFlag
enumeration to for information on available flags. Sample usage:remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("hello", "world");
- Returns:
- the current RemoteCache instance to continue running operations on.
-
getAsync
public CompletableFuture<V> getAsync(Object key)
-
ping
public PingOperation.PingResult ping()
-
keyToBytes
protected byte[] keyToBytes(Object o)
-
valueToBytes
protected byte[] valueToBytes(Object o)
-
assertRemoteCacheManagerIsStarted
protected void assertRemoteCacheManagerIsStarted()
-
set
protected void set(K key, V value)
Description copied from class:RemoteCacheSupport
This is intentionally a non-public method meant as an integration point for bytecode manipulation. Don't remove or alter the signature even if it might look like unreachable code. Implementors should perform a put operation but optimizing it as return values are not required.- Specified by:
set
in classRemoteCacheSupport<K,V>
-
keySet
public org.infinispan.commons.util.CloseableIteratorSet<K> keySet()
-
values
public org.infinispan.commons.util.CloseableIteratorCollection<V> values()
-
execute
public <T> T execute(String taskName, Map<String,?> params)
Description copied from interface:RemoteCache
Executes a remote script passing a set of named parameters
-
execute
public <T> T execute(String taskName, Map<String,?> params, Object key)
Description copied from interface:RemoteCache
Executes a remote script passing a set of named parameters, hinting that the script should be executed on the server that is expected to store given key. The key itself is not transferred to the server.
-
getCacheTopologyInfo
public CacheTopologyInfo getCacheTopologyInfo()
Description copied from interface:RemoteCache
ReturnsCacheTopologyInfo
for this cache.
-
streaming
public StreamingRemoteCache<K> streaming()
Description copied from interface:RemoteCache
Returns a cache where values are manipulated usingInputStream
andOutputStream
-
withDataFormat
public <T,U> RemoteCache<T,U> withDataFormat(DataFormat newDataFormat)
Description copied from interface:RemoteCache
Return a new instance ofRemoteCache
using the suppliedDataFormat
.
-
resolveCompatibility
public PingOperation.PingResult resolveCompatibility()
-
getDataFormat
public DataFormat getDataFormat()
Description copied from interface:RemoteCache
Return the currentlyDataFormat
being used.
-
hasCompatibility
public boolean hasCompatibility()
-
-