public interface StatefulFunction
StatefulFunction is a user-defined function that can be invoked with a given input.
This is the primitive building block for a Stateful Functions application.
Each individual StatefulFunction is an uniquely invokable "instance" of a FunctionType. Each function is identified by an Address, representing the function's
unique id (a string) within its type. From a user's perspective, it would seem as if for each
unique function id, there exists a stateful instance of the function that is always available to
be invoked within a Stateful Functions application.
StatefulFunctionAn individual StatefulFunction can be invoked with arbitrary input from any another
StatefulFunction (including itself), or routed from ingresses via a Router. To
invoke a StatefulFunction, the caller simply needs to know the Address of the
target function.
As a result of invoking a StatefulFunction, the function may continue to invoke other
functions, modify its state, or send messages to egresses addressed by an EgressIdentifier.
Each individual StatefulFunction may have state that is maintained by the system,
providing exactly-once guarantees. Below is a code example of how to register and access state in
functions:
public class MyFunction implements StatefulFunction {
{@code @Persisted}
PersistedValue<Integer> intState = PersistedValue.of("state-name", Integer.class);
{@code @Override}
public void invoke(Context context, Object input) {
Integer stateValue = intState.get();
//...
intState.set(1108);
// send messages using context
}
}
Address,
FunctionType,
Persisted,
PersistedValue| Modifier and Type | Method and Description |
|---|---|
void |
invoke(Context context,
java.lang.Object input)
Invokes this function with a given input.
|
void invoke(Context context, java.lang.Object input)
context - context for the current invocation. The provided context instance should not be
used outside the scope of the current invocation.input - input for the current invocation.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.