NIFI-11595 Backported StateMap.getStateVersion() for StateProviders

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
exceptionfactory 2023-09-20 14:17:00 -05:00
parent bf0bb81361
commit ca05da490a
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
2 changed files with 14 additions and 0 deletions

View File

@ -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
*

View File

@ -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;