@Tags(value={"distributed","cache","state","map","cluster"}) @SeeAlso(classNames={"org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer","org.apache.nifi.ssl.StandardSSLContextService"}) @CapabilityDescription(value="Provides the ability to communicate with a DistributedMapCacheServer. This can be used in order to share a Map between nodes in a NiFi cluster") public class DistributedMapCacheClientService extends AbstractControllerService implements AtomicDistributedMapCacheClient<java.lang.Long>
Modifier and Type | Field and Description |
---|---|
static PropertyDescriptor |
COMMUNICATIONS_TIMEOUT |
static PropertyDescriptor |
HOSTNAME |
static PropertyDescriptor |
PORT |
static PropertyDescriptor |
SSL_CONTEXT_SERVICE |
Constructor and Description |
---|
DistributedMapCacheClientService() |
Modifier and Type | Method and Description |
---|---|
void |
cacheConfig(ConfigurationContext context) |
void |
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 returns
true , else returns false |
CommsSession |
createCommsSession(ConfigurationContext context) |
<K,V> AtomicCacheEntry<K,V,java.lang.Long> |
fetch(K key,
Serializer<K> keySerializer,
Deserializer<V> valueDeserializer)
Fetch a CacheEntry with a key.
|
protected void |
finalize() |
<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 returns
null |
<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 given
Serializer s. |
protected java.util.List<PropertyDescriptor> |
getSupportedPropertyDescriptors()
Allows subclasses to register which property descriptor objects are
supported.
|
void |
onStopped() |
<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.
|
<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 given
Serializer s. |
<K> boolean |
remove(K key,
Serializer<K> serializer)
Removes the entry with the given key from the cache, if it is present.
|
long |
removeByPattern(java.lang.String regex)
Removes entries whose keys match the specified pattern
|
<K,V> boolean |
replace(AtomicCacheEntry<K,V,java.lang.Long> entry,
Serializer<K> keySerializer,
Serializer<V> valueSerializer)
Replace an existing key with new value.
|
abstractClearConfigContext, abstractStoreConfigContext, disabled, enabled, getConfigurationContext, getControllerServiceLookup, getIdentifier, getLogger, getProperty, getStateManager, init, initialize, isEnabled
customValidate, equals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, onPropertyModified, toString, validate
initialize
getIdentifier, getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validate
public static final PropertyDescriptor HOSTNAME
public static final PropertyDescriptor PORT
public static final PropertyDescriptor SSL_CONTEXT_SERVICE
public static final PropertyDescriptor COMMUNICATIONS_TIMEOUT
protected java.util.List<PropertyDescriptor> getSupportedPropertyDescriptors()
AbstractConfigurableComponent
getSupportedPropertyDescriptors
in class AbstractConfigurableComponent
@OnEnabled public void cacheConfig(ConfigurationContext context)
@OnStopped public void onStopped() throws java.io.IOException
java.io.IOException
public <K,V> boolean putIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws java.io.IOException
DistributedMapCacheClient
Serializer
s.putIfAbsent
in interface DistributedMapCacheClient
K
- type of keyV
- type of valuekey
- the key for into the mapvalue
- the value to add to the map if and only if the key is absentkeySerializer
- key serializervalueSerializer
- value serializerjava.io.IOException
- if unable to communicate with the remote instancepublic <K,V> void put(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws java.io.IOException
DistributedMapCacheClient
put
in interface DistributedMapCacheClient
K
- the key typeV
- the value typekey
- 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 bytesjava.io.IOException
- if unable to communicate with the remote instancepublic <K> boolean containsKey(K key, Serializer<K> keySerializer) throws java.io.IOException
DistributedMapCacheClient
true
, else returns false
containsKey
in interface DistributedMapCacheClient
K
- type of keykey
- keykeySerializer
- key serializertrue
, else returns false
java.io.IOException
- if unable to communicate with the remote instancepublic <K,V> V getAndPutIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer, Deserializer<V> valueDeserializer) throws java.io.IOException
DistributedMapCacheClient
Serializer
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.getAndPutIfAbsent
in interface DistributedMapCacheClient
K
- type of keyV
- type of valuekey
- keyvalue
- valuekeySerializer
- key serializervalueSerializer
- key serializervalueDeserializer
- value deserializerjava.io.IOException
- expublic <K,V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws java.io.IOException
DistributedMapCacheClient
null
get
in interface DistributedMapCacheClient
K
- the key typeV
- the value typekey
- the key to lookup in the mapkeySerializer
- key serializervalueDeserializer
- value serializernull
java.io.IOException
- expublic <K> boolean remove(K key, Serializer<K> serializer) throws java.io.IOException
DistributedMapCacheClient
remove
in interface DistributedMapCacheClient
K
- type of keykey
- keyserializer
- serializertrue
if the entry is removed, false
if
the key did not exist in the cachejava.io.IOException
- expublic long removeByPattern(java.lang.String regex) throws java.io.IOException
DistributedMapCacheClient
removeByPattern
in interface DistributedMapCacheClient
regex
- The regular expression / pattern on which to match the keys to be removedjava.io.IOException
- if any error occurred while removing an entrypublic <K,V> AtomicCacheEntry<K,V,java.lang.Long> fetch(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws java.io.IOException
AtomicDistributedMapCacheClient
fetch
in interface AtomicDistributedMapCacheClient<java.lang.Long>
K
- the key typeV
- the value typekey
- the key to lookup in the mapkeySerializer
- key serializervalueDeserializer
- value deserializerjava.io.IOException
- if unable to communicate with the remote instancepublic <K,V> boolean replace(AtomicCacheEntry<K,V,java.lang.Long> entry, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws java.io.IOException
AtomicDistributedMapCacheClient
replace
in interface AtomicDistributedMapCacheClient<java.lang.Long>
K
- the key typeV
- the value typeentry
- should provide the new value for AtomicCacheEntry.getValue()
,
and the same revision in the cache storage for AtomicCacheEntry.getRevision()
,
if the revision does not match with the one in the cache storage, value will not be replaced.keySerializer
- key serializervalueSerializer
- value serializerjava.io.IOException
- if unable to communicate with the remote instancepublic CommsSession createCommsSession(ConfigurationContext context) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
DistributedMapCacheClient
close
in interface DistributedMapCacheClient
java.io.IOException
- exprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable