T
- type of the state.public final class PersistedValue<T>
extends java.lang.Object
PersistedValue
is a value registered within StatefulFunction
s and is persisted
and maintained by the system for fault-tolerance.
Created persisted values must be registered by using the Persisted
annotation. Please
see the class-level Javadoc of StatefulFunction
for an example on how to do that.
StatefulFunction
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the persisted value.
|
Expiration |
expiration() |
T |
get()
Returns the persisted value.
|
T |
getOrDefault(java.util.function.Supplier<T> defaultSupplier)
Attempts to get the persisted value.
|
T |
getOrDefault(T orElse)
Attempts to get the persisted value.
|
java.lang.String |
name()
Returns the unique name of the persisted value.
|
static <T> PersistedValue<T> |
of(java.lang.String name,
java.lang.Class<T> type)
Creates a
PersistedValue instance that may be used to access persisted state managed by
the system. |
static <T> PersistedValue<T> |
of(java.lang.String name,
java.lang.Class<T> type,
Expiration expiration)
Creates a
PersistedValue instance that may be used to access persisted state managed by
the system. |
void |
set(T value)
Updates the persisted value.
|
java.lang.String |
toString() |
java.lang.Class<T> |
type()
Returns the type of the persisted values.
|
T |
updateAndGet(java.util.function.Function<T,T> update)
Updates the persisted value and returns it, in a single operation.
|
public static <T> PersistedValue<T> of(java.lang.String name, java.lang.Class<T> type)
PersistedValue
instance that may be used to access persisted state managed by
the system. Access to the persisted value is identified by an unique name and type of the
value. These may not change across multiple executions of the application.T
- the type of the state values.name
- the unique name of the persisted state.type
- the type of the state values of this PersistedValue
.PersistedValue
instance.public static <T> PersistedValue<T> of(java.lang.String name, java.lang.Class<T> type, Expiration expiration)
PersistedValue
instance that may be used to access persisted state managed by
the system. Access to the persisted value is identified by an unique name and type of the
value. These may not change across multiple executions of the application.T
- the type of the state values.name
- the unique name of the persisted state.type
- the type of the state values of this PersistedValue
.expiration
- state expiration configuration.PersistedValue
instance.public java.lang.String name()
public java.lang.Class<T> type()
public Expiration expiration()
public T get()
public void set(T value)
value
- the new value.public void clear()
null
.public T updateAndGet(java.util.function.Function<T,T> update)
update
- function to process the previous value to obtain the new value.public T getOrDefault(T orElse)
null
, then a specified
default is returned instead.orElse
- the default value to return if the current value is not present.public T getOrDefault(java.util.function.Supplier<T> defaultSupplier)
null
, then a default value
obtained from a specified supplier is returned instead.defaultSupplier
- supplier for a default value to be used if the current value is not
present.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.