NIFI-14832 Added dropStateKeySupported to Stateful annotation (#12)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
diff --git a/src/main/java/org/apache/nifi/annotation/behavior/Stateful.java b/src/main/java/org/apache/nifi/annotation/behavior/Stateful.java
index cfcc820..cb3135f 100644
--- a/src/main/java/org/apache/nifi/annotation/behavior/Stateful.java
+++ b/src/main/java/org/apache/nifi/annotation/behavior/Stateful.java
@@ -17,14 +17,15 @@
package org.apache.nifi.annotation.behavior;
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.components.state.StateManager;
+
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.nifi.components.state.Scope;
-import org.apache.nifi.components.state.StateManager;
/**
* <p>
@@ -54,4 +55,14 @@
* @return Array of scopes for information stored
*/
Scope[] scopes();
+
+ /**
+ * Indicates whether the component supports dropping a specific state key when
+ * the API to clear the state of the component is being called. This should be
+ * used with caution as it can lead to inconsistent state across the cluster if
+ * not handled properly in the component's code.
+ *
+ * @return true if dropping specific state keys is supported, false otherwise
+ */
+ boolean dropStateKeySupported() default false;
}
diff --git a/src/main/java/org/apache/nifi/components/state/StateManager.java b/src/main/java/org/apache/nifi/components/state/StateManager.java
index 1669ea1..5d9a64f 100644
--- a/src/main/java/org/apache/nifi/components/state/StateManager.java
+++ b/src/main/java/org/apache/nifi/components/state/StateManager.java
@@ -17,11 +17,12 @@
package org.apache.nifi.components.state;
-import java.io.IOException;
-import java.util.Map;
import org.apache.nifi.annotation.behavior.Stateful;
import org.apache.nifi.components.state.exception.StateTooLargeException;
+import java.io.IOException;
+import java.util.Map;
+
/**
* <p>
* The StateManager is responsible for providing NiFi components a mechanism for storing
@@ -98,4 +99,15 @@
* @throws IOException if unable to communicate with the underlying storage mechanism
*/
void clear(Scope scope) throws IOException;
+
+ /**
+ * Indicates whether the underlying provider supports removing individual keys.
+ * Dropping keys is not supported by default. It can be enabled for components
+ * via the Stateful annotation.
+ *
+ * @return true if dropping state keys is supported
+ */
+ default boolean isStateKeyDropSupported() {
+ return false;
+ }
}