Class StateExecutionImpl
- java.lang.Object
-
- io.nflow.engine.model.ModelObject
-
- io.nflow.engine.internal.workflow.StateExecutionImpl
-
- All Implemented Interfaces:
StateExecution
public class StateExecutionImpl extends ModelObject implements StateExecution
-
-
Constructor Summary
Constructors Constructor Description StateExecutionImpl(WorkflowInstance instance, ObjectStringMapper objectMapper, WorkflowInstanceDao workflowDao, WorkflowInstancePreProcessor workflowInstancePreProcessor, WorkflowInstanceService workflowInstanceService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChildWorkflows(WorkflowInstance... childWorkflows)Add new child workflows.voidaddWorkflows(WorkflowInstance... workflows)Add new workflows.booleancreateAction()List<WorkflowInstance>getAllChildWorkflows()Return all child workflows for current workflow.StringgetBusinessKey()Return the business key associated to the workflow instance.StringgetCurrentStateName()StringgetNewBusinessKey()List<WorkflowInstance>getNewChildWorkflows()List<WorkflowInstance>getNewWorkflows()org.joda.time.DateTimegetNextActivation()WorkflowStategetNextState()StringgetNextStateReason()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.ThrowablegetThrown()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.Optional<List<String>>getWakeUpParentWorkflowStates()StringgetWorkflowInstanceExternalId()Return the external id of the workflow instance.longgetWorkflowInstanceId()Return the id of the workflow instance.voidhandleFailure(WorkflowDefinition definition, String failureReason)voidhandleRetryAfter(org.joda.time.DateTime activation, WorkflowDefinition definition)booleanhasUnfinishedChildWorkflows()Return true if this workflow instance has unfinished child workflow instances.booleanisFailed()booleanisHistoryCleaningForced()booleanisRetry()booleanisRetryCountExceeded()booleanisStateProcessInvoked()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.voidsetFailed()voidsetFailed(Throwable t)voidsetHistoryCleaningForced(boolean historyCleaningForced)Set to true to force workflow instance history cleaning when workflow instance is updated to the database after state processing.voidsetNextActivation(org.joda.time.DateTime activation)voidsetNextState(WorkflowState state)voidsetNextStateReason(String reason)voidsetRetry(boolean isRetry)voidsetSignal(Optional<Integer> signal, String reason)Set the signal value to the database.voidsetStateProcessInvoked(boolean isStateProcessInvoked)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.-
Methods inherited from class io.nflow.engine.model.ModelObject
equals, hashCode, toString
-
-
-
-
Constructor Detail
-
StateExecutionImpl
public StateExecutionImpl(WorkflowInstance instance, ObjectStringMapper objectMapper, WorkflowInstanceDao workflowDao, WorkflowInstancePreProcessor workflowInstancePreProcessor, WorkflowInstanceService workflowInstanceService)
-
-
Method Detail
-
getNextActivation
public org.joda.time.DateTime getNextActivation()
-
getNextState
public WorkflowState getNextState()
-
getNextStateReason
public String getNextStateReason()
-
getCurrentStateName
public String getCurrentStateName()
-
getWorkflowInstanceId
public long getWorkflowInstanceId()
Description copied from interface:StateExecutionReturn the id of the workflow instance.- Specified by:
getWorkflowInstanceIdin interfaceStateExecution- Returns:
- The workflow instance id.
-
getWorkflowInstanceExternalId
public String getWorkflowInstanceExternalId()
Description copied from interface:StateExecutionReturn the external id of the workflow instance.- Specified by:
getWorkflowInstanceExternalIdin interfaceStateExecution- Returns:
- The external id of the workflow instance.
-
getBusinessKey
public String getBusinessKey()
Description copied from interface:StateExecutionReturn the business key associated to the workflow instance.- Specified by:
getBusinessKeyin interfaceStateExecution- Returns:
- The business key.
-
setBusinessKey
public void setBusinessKey(String businessKey)
Description copied from interface:StateExecutionSet the business key associated to the workflow instance.- Specified by:
setBusinessKeyin interfaceStateExecution- Parameters:
businessKey- The business key.
-
getNewBusinessKey
public String getNewBusinessKey()
-
getRetries
public int getRetries()
Description copied from interface:StateExecutionReturn the number of retry attempts in the current state.- Specified by:
getRetriesin interfaceStateExecution- 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
public String getVariable(String name)
Description copied from interface:StateExecutionReturn a string value of the given variable.- Specified by:
getVariablein interfaceStateExecution- Parameters:
name- The name of the variable.- Returns:
- The string value of the variable, or null if the variable does not exist.
-
getVariable
public <T> T getVariable(String name, Class<T> type)
Description copied from interface:StateExecutionReturn the value of the given variable. The value is deserialized by the object mapper.- Specified by:
getVariablein interfaceStateExecution- 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
public <T> T getVariable(String name, Class<T> type, T defaultValue)
Description copied from interface:StateExecutionReturn the value of the given variable, or {code defaultValue} if the variable does not exist. The value is deserialized by the object mapper.- Specified by:
getVariablein interfaceStateExecution- 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}.
-
getVariable
public String getVariable(String name, String defaultValue)
Description copied from interface:StateExecutionReturn the string value of the given variable, or {code defaultValue} if the variable does not exist.- Specified by:
getVariablein interfaceStateExecution- 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.
-
setVariable
public void setVariable(String name, String value)
Description copied from interface:StateExecutionSet the string value of the given variable.- Specified by:
setVariablein interfaceStateExecution- Parameters:
name- The name of the variable.value- The string value for the varible.
-
setVariable
public void setVariable(String name, Object value)
Description copied from interface:StateExecutionSet the value for the given varible. The value must be serializable by the object mapper.- Specified by:
setVariablein interfaceStateExecution- Parameters:
name- The name of the variable.value- The value for the variable.
-
setNextActivation
public void setNextActivation(org.joda.time.DateTime activation)
-
setNextState
public void setNextState(WorkflowState state)
-
setNextStateReason
public void setNextStateReason(String reason)
-
isRetry
public boolean isRetry()
-
setRetry
public void setRetry(boolean isRetry)
-
isFailed
public boolean isFailed()
-
getThrown
public Throwable getThrown()
-
setFailed
public void setFailed()
-
setFailed
public void setFailed(Throwable t)
-
isRetryCountExceeded
public boolean isRetryCountExceeded()
-
addChildWorkflows
public void addChildWorkflows(WorkflowInstance... childWorkflows)
Description copied from interface:StateExecutionAdd 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.- Specified by:
addChildWorkflowsin interfaceStateExecution- Parameters:
childWorkflows- Child workflows to create.
-
addWorkflows
public void addWorkflows(WorkflowInstance... workflows)
Description copied from interface:StateExecutionAdd new workflows. Workflows are stored to database after current state method processing completes successfully.- Specified by:
addWorkflowsin interfaceStateExecution- Parameters:
workflows- Workflows to create.
-
getNewChildWorkflows
public List<WorkflowInstance> getNewChildWorkflows()
-
getNewWorkflows
public List<WorkflowInstance> getNewWorkflows()
-
queryChildWorkflows
public List<WorkflowInstance> queryChildWorkflows(QueryWorkflowInstances query)
Description copied from interface:StateExecutionReturn child workflow instances for current workflow. Query is restricted to childs of current workflow.- Specified by:
queryChildWorkflowsin interfaceStateExecution- Parameters:
query- The query criterias.- Returns:
- List of child workflows that match the query.
-
getAllChildWorkflows
public List<WorkflowInstance> getAllChildWorkflows()
Description copied from interface:StateExecutionReturn all child workflows for current workflow.- Specified by:
getAllChildWorkflowsin interfaceStateExecution- Returns:
- List of all child workflows.
-
wakeUpParentWorkflow
public void wakeUpParentWorkflow(String... expectedStates)
Description copied from interface:StateExecutionNotify 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.- Specified by:
wakeUpParentWorkflowin interfaceStateExecution- 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
public WorkflowInstance.Builder workflowInstanceBuilder()
Description copied from interface:StateExecutionCreate a builder for creating child workflows. Created builder has nextActivation set to current time.- Specified by:
workflowInstanceBuilderin interfaceStateExecution- Returns:
- Builder for creating child workflows.
-
setStateProcessInvoked
public void setStateProcessInvoked(boolean isStateProcessInvoked)
-
isStateProcessInvoked
public boolean isStateProcessInvoked()
-
setCreateAction
public void setCreateAction(boolean createAction)
Description copied from interface:StateExecutionControl 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.- Specified by:
setCreateActionin interfaceStateExecution- Parameters:
createAction- Whether action should be created or not.
-
createAction
public boolean createAction()
-
getSignal
public Optional<Integer> getSignal()
Description copied from interface:StateExecutionReturn the signal value from database if it has been set, otherwise return empty.- Specified by:
getSignalin interfaceStateExecution- Returns:
- The signal value.
-
setSignal
public void setSignal(Optional<Integer> signal, String reason)
Description copied from interface:StateExecutionSet the signal value to the database. Use Optional.empty() to clear the signal value.- Specified by:
setSignalin interfaceStateExecution- Parameters:
signal- Signal value to be set.reason- The reason for setting the signal.
-
getParentId
public Optional<Long> getParentId()
Description copied from interface:StateExecutionReturn the parent workflow instance id if this is a child workflow, otherwise return empty.- Specified by:
getParentIdin interfaceStateExecution- Returns:
- The parent workflow instance id or empty.
-
setHistoryCleaningForced
public void setHistoryCleaningForced(boolean historyCleaningForced)
Description copied from interface:StateExecutionSet 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.- Specified by:
setHistoryCleaningForcedin interfaceStateExecution- Parameters:
historyCleaningForced- Whether history cleaning should be forced or not.
-
isHistoryCleaningForced
public boolean isHistoryCleaningForced()
-
handleRetryAfter
public void handleRetryAfter(org.joda.time.DateTime activation, WorkflowDefinition definition)
-
handleFailure
public void handleFailure(WorkflowDefinition definition, String failureReason)
-
hasUnfinishedChildWorkflows
public boolean hasUnfinishedChildWorkflows()
Description copied from interface:StateExecutionReturn true if this workflow instance has unfinished child workflow instances.- Specified by:
hasUnfinishedChildWorkflowsin interfaceStateExecution- Returns:
- True if unfinished child workflow instances are found, false otherwise.
-
-