Interface DistributedMapCacheClient
- All Superinterfaces:
org.apache.nifi.components.ConfigurableComponent
,org.apache.nifi.controller.ControllerService
- All Known Subinterfaces:
AtomicDistributedMapCacheClient<R>
@Tags({"distributed","client","cluster","map","cache"})
@CapabilityDescription("Provides the ability to communicate with a DistributedMapCacheServer. This allows multiple nodes to coordinate state with a single remote entity.")
public interface DistributedMapCacheClient
extends org.apache.nifi.controller.ControllerService
This interface defines an API that can be used for interacting with a
Distributed Cache that functions similarly to a
Map
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Attempts to notify the server that we are finished communicating with it and cleans up resources<K> boolean
containsKey
(K key, Serializer<K> keySerializer) Determines if the given value is present in the cache and if so returnstrue
, else returnsfalse
<K,
V> V get
(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) Returns the value in the cache for the given key, if one exists; otherwise returnsnull
<K,
V> V getAndPutIfAbsent
(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer, Deserializer<V> valueDeserializer) Adds the specified key and value to the cache, if they are not already present, serializing the key and value with the givenSerializer
s.default <K> Set
<K> keySet
(Deserializer<K> keyDeserializer) Returns a set of all keys currently in the cache<K,
V> void put
(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) Adds the specified key and value to the cache, overwriting any value that is currently set.default <K,
V> void putAll
(Map<K, V> keysAndValues, Serializer<K> keySerializer, Serializer<V> valueSerializer) Performs a bulk put operation.<K,
V> boolean putIfAbsent
(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) Adds the specified key and value to the cache, if they are not already present, serializing the key and value with the givenSerializer
s.<K> boolean
remove
(K key, Serializer<K> serializer) Removes the entry with the given key from the cache, if it is present.default <K,
V> V removeAndGet
(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) Removes the entry with the given key from the cache, if it is present, and returns the value that was removed from the map.default <K,
V> Map <K, V> subMap
(Set<K> keys, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) Returns the values in the cache for the given keys, if they exist; otherwise returnsnull
Methods inherited from interface org.apache.nifi.components.ConfigurableComponent
getIdentifier, getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validate
Methods inherited from interface org.apache.nifi.controller.ControllerService
initialize, isStateful, migrateProperties
-
Method Details
-
putIfAbsent
<K,V> boolean putIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOException Adds the specified key and value to the cache, if they are not already present, serializing the key and value with the givenSerializer
s.- Type Parameters:
K
- type of keyV
- type of value- Parameters:
key
- the key for into the mapvalue
- the value to add to the map if and only if the key is absentkeySerializer
- key serializervalueSerializer
- value serializer- Returns:
- true if the value was added to the cache, false if the value already existed in the cache
- Throws:
IOException
- if unable to communicate with the remote instance
-
getAndPutIfAbsent
<K,V> V getAndPutIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer, Deserializer<V> valueDeserializer) throws IOException Adds the specified key and value to the cache, if they are not already present, serializing the key and value with the givenSerializer
s. If a value already exists in the cache for the given key, the value associated with the key is returned, after being deserialized with the given valueDeserializer.- Type Parameters:
K
- type of keyV
- type of value- Parameters:
key
- keyvalue
- valuekeySerializer
- key serializervalueSerializer
- key serializervalueDeserializer
- value deserializer- Returns:
- If a value already exists in the cache for the given
key, the value associated with the key is returned, after being
deserialized with the given
valueDeserializer
. If the key does not exist, the key and its value will be added to the cache. - Throws:
IOException
- ex
-
containsKey
Determines if the given value is present in the cache and if so returnstrue
, else returnsfalse
- Type Parameters:
K
- type of key- Parameters:
key
- keykeySerializer
- key serializer- Returns:
- Determines if the given value is present in the cache and if so returns
true
, else returnsfalse
- Throws:
IOException
- if unable to communicate with the remote instance
-
put
<K,V> void put(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOException Adds the specified key and value to the cache, overwriting any value that is currently set.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- The key to setvalue
- The value to associate with the given KeykeySerializer
- the Serializer that will be used to serialize the key into bytesvalueSerializer
- the Serializer that will be used to serialize the value into bytes- Throws:
IOException
- if unable to communicate with the remote instanceNullPointerException
- if the key or either serializer is null
-
putAll
default <K,V> void putAll(Map<K, V> keysAndValues, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOExceptionPerforms a bulk put operation. This should be used when needed to send a large batch of updates to a cache in a single update operation.- Type Parameters:
K
- The key typeV
- The value type- Parameters:
keysAndValues
- A java.util.Map that contains an association between keys and values to be bulk inserted into the cache.keySerializer
- The Serializer that will be used to serialize the key into bytesvalueSerializer
- The Serializer that will be used to serialize the value into bytes- Throws:
IOException
- if unable to communicate with the remote instance
-
get
<K,V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException Returns the value in the cache for the given key, if one exists; otherwise returnsnull
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- the key to lookup in the mapkeySerializer
- key serializervalueDeserializer
- value serializer- Returns:
- the value in the cache for the given key, if one exists;
otherwise returns
null
- Throws:
IOException
- ex
-
subMap
default <K,V> Map<K,V> subMap(Set<K> keys, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException Returns the values in the cache for the given keys, if they exist; otherwise returnsnull
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
keys
- a set of keys whose values to lookup in the mapkeySerializer
- key serializervalueDeserializer
- value serializer- Returns:
- the value in the cache for the given key, if one exists;
otherwise returns
null
- Throws:
IOException
- ex
-
close
Attempts to notify the server that we are finished communicating with it and cleans up resources- Throws:
IOException
- ex
-
remove
Removes the entry with the given key from the cache, if it is present.- Type Parameters:
K
- type of key- Parameters:
key
- keyserializer
- serializer- Returns:
true
if the entry is removed,false
if the key did not exist in the cache- Throws:
IOException
- ex
-
removeAndGet
default <K,V> V removeAndGet(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException Removes the entry with the given key from the cache, if it is present, and returns the value that was removed from the map.- Type Parameters:
K
- type of keyV
- type of value- Parameters:
key
- keykeySerializer
- key serializervalueDeserializer
- value deserializer- Returns:
- the value previously associated with the key, or null if there was no mapping null can also indicate that the map previously associated null with the key
- Throws:
IOException
- ex
-
keySet
Returns a set of all keys currently in the cache- Type Parameters:
K
- type of key- Parameters:
keyDeserializer
- key deserializer- Returns:
- a Set of all keys currently in the cache
- Throws:
IOException
- ex
-