This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
     new ca05da490a NIFI-11595 Backported StateMap.getStateVersion() for 
StateProviders
ca05da490a is described below

commit ca05da490a54a80e21e10ed2073b4921f39d8809
Author: exceptionfactory <exceptionfact...@apache.org>
AuthorDate: Wed Sep 20 14:17:00 2023 -0500

    NIFI-11595 Backported StateMap.getStateVersion() for StateProviders
    
    Signed-off-by: David Handermann <exceptionfact...@apache.org>
---
 .../java/org/apache/nifi/components/state/StateMap.java     | 13 +++++++++++++
 .../state/providers/zookeeper/ZooKeeperStateProvider.java   |  1 +
 2 files changed, 14 insertions(+)

diff --git 
a/nifi-api/src/main/java/org/apache/nifi/components/state/StateMap.java 
b/nifi-api/src/main/java/org/apache/nifi/components/state/StateMap.java
index 4d67164fa4..3defe51915 100644
--- a/nifi-api/src/main/java/org/apache/nifi/components/state/StateMap.java
+++ b/nifi-api/src/main/java/org/apache/nifi/components/state/StateMap.java
@@ -18,6 +18,7 @@
 package org.apache.nifi.components.state;
 
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Provides a representation of a component's state at some point in time.
@@ -31,8 +32,20 @@ public interface StateMap {
      *
      * @return the version associated with the state
      */
+    @Deprecated
     long getVersion();
 
+    /**
+     * Get state version is not guaranteed to be numeric, but can be used to 
compare against an expected version.
+     * The default implementation uses the available version number and 
considers -1 as indicating an empty version
+     *
+     * @return State version or empty when not known
+     */
+    default Optional<String> getStateVersion() {
+        final long version = getVersion();
+        return version == -1 ? Optional.empty() : 
Optional.of(String.valueOf(version));
+    }
+
     /**
      * Returns the value associated with the given key
      *
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
index 747aa56ae6..a201abb13d 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
@@ -64,6 +64,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;

Reply via email to