Interface StateProvider

All Superinterfaces:
ConfigurableComponent

public interface StateProvider extends ConfigurableComponent

Provides a mechanism by which components can store and retrieve state. Depending on the Provider, the state may be stored locally, or it may be stored on a remote resource.

Which implementation should be used for local and clustered state is configured in the NiFi properties file. It is therefore possible to provide custom implementations of this interface. Note, however, that this interface is new as of version 0.5.0 of Apache NiFi and may not be considered "stable" as of yet. Therefore, it is subject to change without notice, so providing custom implementations is cautioned against until the API becomes more stable.

Since:
0.5.0
  • Method Details

    • initialize

      void initialize(StateProviderInitializationContext context) throws IOException
      Initializes the StateProvider so that it is capable of being used. This method will be called once before any of the other methods are called and will not be called again until the shutdown() method has been called
      Parameters:
      context - the initialization context that can be used to prepare the state provider for use
      Throws:
      IOException
    • shutdown

      void shutdown()
      Shuts down the StateProvider and cleans up any resources held by it. Once this method has returned, the StateProvider may be initialized once again via the initialize(StateProviderInitializationContext) method.
    • setState

      void setState(Map<String,String> state, String componentId) throws IOException
      Updates the value of the component's state, setting the new value to the given state
      Parameters:
      state - the value to change the state to
      componentId - the id of the component for which state is being set
      Throws:
      IOException - if unable to communicate with the underlying storage mechanism
    • getState

      StateMap getState(String componentId) throws IOException
      Returns the currently configured state for the component. The returned StateMap will never be null. The version of the StateMap will be -1 and the state will contain no key/value pairs if the state has never been set.
      Parameters:
      componentId - the id of the component for which state is to be retrieved
      Returns:
      the currently configured value for the component's state
      Throws:
      IOException - if unable to communicate with the underlying storage mechanism
    • replace

      boolean replace(StateMap oldValue, Map<String,String> newValue, String componentId) throws IOException
      Updates the value of the component's state to the new value if and only if the value currently is the same as the given oldValue.
      Parameters:
      oldValue - the old value to compare against
      newValue - the new value to use if and only if the state's value is the same as the given oldValue
      componentId - the id of the component for which state is being retrieved
      Returns:
      true if the state was updated to the new value, false if the state's value was not equal to oldValue
      Throws:
      IOException - if unable to communicate with the underlying storage mechanism
    • clear

      void clear(String componentId) throws IOException
      Removes all values from the component's state that is stored using the given scope
      Parameters:
      componentId - the id of the component for which state is being cleared
      Throws:
      IOException - if unable to communicate with the underlying storage mechanism
    • onComponentRemoved

      void onComponentRemoved(String componentId) throws IOException
      This method is called whenever a component is removed from the NiFi instance. This allows the State Provider to perform tasks when a component is removed in order to clean up resources that may be associated with that component
      Parameters:
      componentId - the ID of the component that was added to the NiFi instance
      Throws:
      IOException - if unable to perform the necessary cleanup
    • enable

      void enable()
      Notifies the state provider that it should begin servicing requests to store and retrieve state
    • disable

      void disable()
      Notifies the state provider that it should stop servicing requests to store and retrieve state and instead throw a ProviderDisabledException if any request is made to do so
    • isEnabled

      boolean isEnabled()
      Returns:
      true if the provider is enabled, false otherwise.
    • getSupportedScopes

      Scope[] getSupportedScopes()
      Provides a listing of Scopes supported by the StateProvider
      Returns:
      the Scopes supported by the configuration
    • isComponentEnumerationSupported

      default boolean isComponentEnumerationSupported()
      Indicates whether the State Provider supports enumerating component identifiers with stored state information
      Returns:
      Component enumeration supported status
    • getStoredComponentIds

      default Collection<String> getStoredComponentIds() throws IOException
      Get Component Identifiers with associated state stored in the Provider
      Returns:
      Collection of Component Identifiers with stored state defaults to empty
      Throws:
      IOException - Thrown on failures to retrieve component identifiers