Interface StateExecution
-
- All Known Implementing Classes:
StateExecutionImpl
public interface StateExecutionProvides access to workflow instance information. Variables are persisted after processing the state handler method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddChildWorkflows(WorkflowInstance... childWorkflows)Add new child workflows.voidaddWorkflows(WorkflowInstance... workflows)Add new workflows.List<WorkflowInstance>getAllChildWorkflows()Return all child workflows for current workflow.StringgetBusinessKey()Return the business key associated to the workflow instance.Optional<Long>getParentId()Return the parent workflow instance id if this is a child workflow, otherwise return empty.intgetRetries()Return the number of retry attempts in the current state.Optional<Integer>getSignal()Return the signal value from database if it has been set, otherwise return empty.StringgetVariable(String name)Return a string value of the given variable.<T> TgetVariable(String name, Class<T> type)Return the value of the given variable.<T> TgetVariable(String name, Class<T> type, T defaultValue)Return the value of the given variable, or {code defaultValue} if the variable does not exist.StringgetVariable(String name, String defaultValue)Return the string value of the given variable, or {code defaultValue} if the variable does not exist.StringgetWorkflowInstanceExternalId()Return the external id of the workflow instance.longgetWorkflowInstanceId()Return the id of the workflow instance.booleanhasUnfinishedChildWorkflows()Return true if this workflow instance has unfinished child workflow instances.List<WorkflowInstance>queryChildWorkflows(QueryWorkflowInstances query)Return child workflow instances for current workflow.voidsetBusinessKey(String businessKey)Set the business key associated to the workflow instance.voidsetCreateAction(boolean createAction)Control if action is created when workflow instance is updated to the database after state processing.voidsetHistoryCleaningForced(boolean historyCleaningForced)Set to true to force workflow instance history cleaning when workflow instance is updated to the database after state processing.voidsetSignal(Optional<Integer> signal, String reason)Set the signal value to the database.voidsetVariable(String name, Object value)Set the value for the given varible.voidsetVariable(String name, String value)Set the string value of the given variable.voidwakeUpParentWorkflow(String... expectedStates)Notify parent workflow that it may start processing again.WorkflowInstance.BuilderworkflowInstanceBuilder()Create a builder for creating child workflows.
-
-
-
Method Detail
-
getWorkflowInstanceId
long getWorkflowInstanceId()
Return the id of the workflow instance.- Returns:
- The workflow instance id.
-
getBusinessKey
String getBusinessKey()
Return the business key associated to the workflow instance.- Returns:
- The business key.
-
setBusinessKey
void setBusinessKey(String businessKey)
Set the business key associated to the workflow instance.- Parameters:
businessKey- The business key.
-
getRetries
int getRetries()
Return the number of retry attempts in the current state.- Returns:
- Number of retries. Zero when the state is executed for the first time. Increased by one every time the same state is executed again.
-
getVariable
String getVariable(String name)
Return a string value of the given variable.- Parameters:
name- The name of the variable.- Returns:
- The string value of the variable, or null if the variable does not exist.
-
getVariable
<T> T getVariable(String name, Class<T> type)
Return the value of the given variable. The value is deserialized by the object mapper.- Type Parameters:
T- The type of object to be deserialized.- Parameters:
name- The name of the variable.type- The class of the variable.- Returns:
- The deserialized value of class {code T}, or null if the variable does not exist.
-
getVariable
String getVariable(String name, String defaultValue)
Return the string value of the given variable, or {code defaultValue} if the variable does not exist.- Parameters:
name- The name of the variable.defaultValue- The default value if the variable does not exist.- Returns:
- The string value of the variable or the default value.
-
getVariable
<T> T getVariable(String name, Class<T> type, T defaultValue)
Return the value of the given variable, or {code defaultValue} if the variable does not exist. The value is deserialized by the object mapper.- Type Parameters:
T- The type of object to be deserialized.- Parameters:
name- The name of the variable.type- The class of the variable.defaultValue- The default value if the variable does not exist.- Returns:
- The deserialized value of class {code T}.
-
setVariable
void setVariable(String name, String value)
Set the string value of the given variable.- Parameters:
name- The name of the variable.value- The string value for the varible.
-
setVariable
void setVariable(String name, Object value)
Set the value for the given varible. The value must be serializable by the object mapper.- Parameters:
name- The name of the variable.value- The value for the variable.
-
getWorkflowInstanceExternalId
String getWorkflowInstanceExternalId()
Return the external id of the workflow instance.- Returns:
- The external id of the workflow instance.
-
addChildWorkflows
void addChildWorkflows(WorkflowInstance... childWorkflows)
Add new child workflows. Child workflows are stored to database after current state method processing completes successfully. Note that child workflows are not visible to queryChildWorkflows() method before they are stored to database.- Parameters:
childWorkflows- Child workflows to create.
-
addWorkflows
void addWorkflows(WorkflowInstance... workflows)
Add new workflows. Workflows are stored to database after current state method processing completes successfully.- Parameters:
workflows- Workflows to create.
-
queryChildWorkflows
List<WorkflowInstance> queryChildWorkflows(QueryWorkflowInstances query)
Return child workflow instances for current workflow. Query is restricted to childs of current workflow.- Parameters:
query- The query criterias.- Returns:
- List of child workflows that match the query.
-
getAllChildWorkflows
List<WorkflowInstance> getAllChildWorkflows()
Return all child workflows for current workflow.- Returns:
- List of all child workflows.
-
wakeUpParentWorkflow
void wakeUpParentWorkflow(String... expectedStates)
Notify parent workflow that it may start processing again. Calling this schedules parent workflow for immediate execution. Scheduling is performed when current state method processing completes successfully.- Parameters:
expectedStates- If parent state is not one of the expected states, it is not woken up. If no expected states are given, parent workflow is woken up regardless of the state.
-
workflowInstanceBuilder
WorkflowInstance.Builder workflowInstanceBuilder()
Create a builder for creating child workflows. Created builder has nextActivation set to current time.- Returns:
- Builder for creating child workflows.
-
setCreateAction
void setCreateAction(boolean createAction)
Control if action is created when workflow instance is updated to the database after state processing. By default the action is created. Additionally, the action is always created when new workflows or child workflows are created or when the state variables are updated, regardless of this setting.- Parameters:
createAction- Whether action should be created or not.
-
setHistoryCleaningForced
void setHistoryCleaningForced(boolean historyCleaningForced)
Set to true to force workflow instance history cleaning when workflow instance is updated to the database after state processing. By default (or if set to false) the cleaning is done according to workflow definition settings. Cleaning also requires WorkflowSettings.setHistoryDeletableAfterHours to be set.- Parameters:
historyCleaningForced- Whether history cleaning should be forced or not.
-
getSignal
Optional<Integer> getSignal()
Return the signal value from database if it has been set, otherwise return empty.- Returns:
- The signal value.
-
setSignal
void setSignal(Optional<Integer> signal, String reason)
Set the signal value to the database. Use Optional.empty() to clear the signal value.- Parameters:
signal- Signal value to be set.reason- The reason for setting the signal.
-
getParentId
Optional<Long> getParentId()
Return the parent workflow instance id if this is a child workflow, otherwise return empty.- Returns:
- The parent workflow instance id or empty.
-
hasUnfinishedChildWorkflows
boolean hasUnfinishedChildWorkflows()
Return true if this workflow instance has unfinished child workflow instances.- Returns:
- True if unfinished child workflow instances are found, false otherwise.
-
-