Package io.iworkflow.core
Interface WorkflowState<I>
-
public interface WorkflowState<I>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description StateDecision
execute(Context context, I input, CommandResults commandResults, Persistence persistence, Communication communication)
Implement this method to execute the state business, when requested commands are ready ifwaitUntil(io.iworkflow.core.Context, I, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
is implemented IfwaitUntil(io.iworkflow.core.Context, I, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
is not implemented, the state will invoke this execute API directlyjava.lang.Class<I>
getInputType()
This input type is needed for deserializing data back into Java objectstatic java.lang.String
getStateExecutionId(java.lang.Class<? extends WorkflowState> state, int number)
default java.lang.String
getStateId()
a unique identifier of the state It must be unique in any workflow definition By default just the simple name of the implementation classdefault WorkflowStateOptions
getStateOptions()
Optional configuration to adjust the state behaviors.static boolean
shouldSkipWaitUntil(WorkflowState state)
default CommandRequest
waitUntil(Context context, I input, Persistence persistence, Communication communication)
Optionally implement this method to set up condition for the state.
-
-
-
Method Detail
-
getInputType
java.lang.Class<I> getInputType()
This input type is needed for deserializing data back into Java object- Returns:
- the type of the state input
-
waitUntil
default CommandRequest waitUntil(Context context, I input, Persistence persistence, Communication communication)
Optionally implement this method to set up condition for the state. If implemented, this will be the first API invoked when state started. Then the state will be waiting until the requested commands are completed. If not implemented, the state will invoke theexecute(io.iworkflow.core.Context, I, io.iworkflow.core.command.CommandResults, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
directlyThe condition is setup using commands. There are three types commands in a
CommandRequest
: signal, timer and InternalChannel; Also with three types ofCommandWaitingType
- Parameters:
context
- the context info of this API invocation, like workflow start time, workflowId, etcinput
- the state input which is deserialized byObjectEncoder
withgetInputType()
persistence
- persistence API for 1) data attributes, 2) search attributes and 3) stateExecutionLocals 4) recordEvent DataAttributes and SearchAttributes are defined byObjectWorkflow
interface. StateExecutionLocals are for passing data within the state execution from this waitUntil API toexecute(io.iworkflow.core.Context, I, io.iworkflow.core.command.CommandResults, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
API RecordEvent is for storing some tracking info(e.g. RPC call input/output) when executing the API. Note that any write API will be recorded to server after the whole waitUntil API response is accepted by server.communication
- communication API, right now only for publishing value to InternalChannel Note that any write API will be recorded to server after the whole waitUntil API response is accepted by server.- Returns:
- the requested commands for this step
-
execute
StateDecision execute(Context context, I input, CommandResults commandResults, Persistence persistence, Communication communication)
Implement this method to execute the state business, when requested commands are ready ifwaitUntil(io.iworkflow.core.Context, I, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
is implemented IfwaitUntil(io.iworkflow.core.Context, I, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
is not implemented, the state will invoke this execute API directly- Parameters:
context
- the context info of this API invocation, like workflow start time, workflowId, etcinput
- the state input which is deserialized byObjectEncoder
withgetInputType()
commandResults
- the results of the command that executed bywaitUntil(io.iworkflow.core.Context, I, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
persistence
- persistence API for 1) data attributes, 2) search attributes and 3) stateExecutionLocals 4) recordEvent DataAttributes and SearchAttributes are defined byObjectWorkflow
interface. StateExecutionLocals are for passing data within the state execution from this API toexecute(io.iworkflow.core.Context, I, io.iworkflow.core.command.CommandResults, io.iworkflow.core.persistence.Persistence, io.iworkflow.core.communication.Communication)
API RecordEvent is for storing some tracking info(e.g. RPC call input/output) when executing the API. Note that the write API will be recorded to server after the whole execute API response is accepted by server.communication
- communication API, right now only for publishing value to InternalChannel Note that the write API will be recorded to server after the whole execute API response is accepted by server.- Returns:
- the decision of what to do next(e.g. transition to next states)
-
getStateId
default java.lang.String getStateId()
a unique identifier of the state It must be unique in any workflow definition By default just the simple name of the implementation class- Returns:
- the StateId of the state
-
getStateOptions
default WorkflowStateOptions getStateOptions()
Optional configuration to adjust the state behaviors. Default values if not set: - waitUntilApiFailurePolicy: FAIL_WORKFLOW_ON_FAILURE - PersistenceLoadingPolicy for dataAttributes/searchAttributes: LOAD_ALL_WITHOUT_LOCKING , - waitUntil/execute API: - timeout: 30s - retryPolicy: - InitialIntervalSeconds: 1 - MaxInternalSeconds:100 - MaximumAttempts: 0 - BackoffCoefficient: 2 SeeWorkflowStateOptionsExtension
for some helpers to build the options.- Returns:
- the optional options
-
shouldSkipWaitUntil
static boolean shouldSkipWaitUntil(WorkflowState state)
-
getStateExecutionId
static java.lang.String getStateExecutionId(java.lang.Class<? extends WorkflowState> state, int number)
-
-