public interface StateBootstrapFunction
StateBootstrapFunction
defines how to bootstrap state for a StatefulFunction
instance with a given input.
Each StateBootstrapFunction
instance directly corresponds to a StatefulFunction
instance. Likewise, each instance is uniquely identified by an Address
,
represented by the type and id of the function being bootstrapped. Any state that is persisted by
a StateBootstrapFunction
instance will be available to the corresponding live StatefulFunction
instance having the same address.
For example, consider the following state bootstrap function:
public class MyStateBootstrapFunction implements StateBootstrapFunction {
{@code @Persisted}
private PersistedValue<MyState> state = PersistedValue.of("my-state", MyState.class);
{@code @Override}
public void bootstrap(Context context, Object input) {
state.set(extractStateFromInput(input));
}
}
Assume that this bootstrap function was provided for function type MyFunctionType, and the id of the bootstrap function instance was id-13. The function writes persisted state of name my-state using the given bootstrap data. After restoring a Stateful Functions application from the savepoint generated using this bootstrap function, the stateful function instance with address (MyFunctionType, id-13) will already have state values available under state name my-state.
Modifier and Type | Method and Description |
---|---|
void |
bootstrap(Context context,
java.lang.Object bootstrapData)
Bootstraps state for this function with the given bootstrap data.
|
void bootstrap(Context context, java.lang.Object bootstrapData)
context
- context for the current bootstrap invocation. The provided context instance
should not be used outside the scope of the current invocation.bootstrapData
- input to be used for bootstrapping state.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.