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 Type
    Method
    Description
    void
    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
    <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 Serializers.
    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 given Serializers.
    <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 returns null

    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 given Serializers.
      Type Parameters:
      K - type of key
      V - type of value
      Parameters:
      key - the key for into the map
      value - the value to add to the map if and only if the key is absent
      keySerializer - key serializer
      valueSerializer - 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 given Serializers. 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 key
      V - type of value
      Parameters:
      key - key
      value - value
      keySerializer - key serializer
      valueSerializer - key serializer
      valueDeserializer - 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

      <K> boolean containsKey(K key, Serializer<K> keySerializer) throws IOException
      Determines if the given value is present in the cache and if so returns true, else returns false
      Type Parameters:
      K - type of key
      Parameters:
      key - key
      keySerializer - key serializer
      Returns:
      Determines if the given value is present in the cache and if so returns true, else returns false
      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 type
      V - the value type
      Parameters:
      key - The key to set
      value - The value to associate with the given Key
      keySerializer - the Serializer that will be used to serialize the key into bytes
      valueSerializer - the Serializer that will be used to serialize the value into bytes
      Throws:
      IOException - if unable to communicate with the remote instance
      NullPointerException - 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 IOException
      Performs 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 type
      V - 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 bytes
      valueSerializer - 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 returns null
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key to lookup in the map
      keySerializer - key serializer
      valueDeserializer - 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 returns null
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keys - a set of keys whose values to lookup in the map
      keySerializer - key serializer
      valueDeserializer - value serializer
      Returns:
      the value in the cache for the given key, if one exists; otherwise returns null
      Throws:
      IOException - ex
    • close

      void close() throws IOException
      Attempts to notify the server that we are finished communicating with it and cleans up resources
      Throws:
      IOException - ex
    • remove

      <K> boolean remove(K key, Serializer<K> serializer) throws IOException
      Removes the entry with the given key from the cache, if it is present.
      Type Parameters:
      K - type of key
      Parameters:
      key - key
      serializer - 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 key
      V - type of value
      Parameters:
      key - key
      keySerializer - key serializer
      valueDeserializer - 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

      default <K> Set<K> keySet(Deserializer<K> keyDeserializer) throws IOException
      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