Package org.apache.nifi.components.state
Interface StateProvider
- All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptionvoid
Removes all values from the component's state that is stored using the given scopevoid
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 sovoid
enable()
Notifies the state provider that it should begin servicing requests to store and retrieve stateReturns the currently configured state for the component.default Collection
<String> Get Component Identifiers with associated state stored in the ProviderScope[]
Provides a listing ofScope
s supported by the StateProvidervoid
Initializes the StateProvider so that it is capable of being used.default boolean
Indicates whether the State Provider supports enumerating component identifiers with stored state informationboolean
void
onComponentRemoved
(String componentId) This method is called whenever a component is removed from the NiFi instance.boolean
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.void
Updates the value of the component's state, setting the new value to the given statevoid
shutdown()
Shuts down the StateProvider and cleans up any resources held by it.Methods inherited from interface org.apache.nifi.components.ConfigurableComponent
getIdentifier, getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validate
-
Method Details
-
initialize
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 theshutdown()
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 theinitialize(StateProviderInitializationContext)
method. -
setState
Updates the value of the component's state, setting the new value to the given state- Parameters:
state
- the value to change the state tocomponentId
- the id of the component for which state is being set- Throws:
IOException
- if unable to communicate with the underlying storage mechanism
-
getState
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 IOExceptionUpdates 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 againstnewValue
- the new value to use if and only if the state's value is the same as the given oldValuecomponentId
- 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
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
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 ofScope
s supported by the StateProvider- Returns:
- the
Scope
s 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
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
-