Package io.nflow.engine.service
Class WorkflowInstanceService
java.lang.Object
io.nflow.engine.service.WorkflowInstanceService
Service for managing workflow instances.
-
Constructor Summary
ConstructorsConstructorDescriptionWorkflowInstanceService(WorkflowInstanceDao workflowInstanceDao, WorkflowDefinitionService workflowDefinitionService, WorkflowInstancePreProcessor workflowInstancePreProcessor) -
Method Summary
Modifier and TypeMethodDescriptiongetSignal(long workflowInstanceId) Return current signal value for given workflow instance.getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions) Return the workflow instance matching the given id.getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions, boolean queryArchive) Return the workflow instance matching the given id.booleanhasUnfinishedChildWorkflows(long workflowInstanceId) Return true if this workflow instance has unfinished child workflow instances.longinsertWorkflowInstance(WorkflowInstance instance) Insert the workflow instance to the database and return the id of the instance.Return workflow instances matching the given query.Return workflow instances matching the given query.booleansetSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowInstanceAction.WorkflowActionType actionType) Set signal value for given workflow instance.booleanupdateWorkflowInstance(WorkflowInstance instance, WorkflowInstanceAction action) Update the workflow instance in the database if it is currently not running, and insert the workflow instance action.booleanwakeupWorkflowInstance(long id, List<String> expectedStates) Wake up the workflow instance matching the given id if it is in one of the expected states.
-
Constructor Details
-
WorkflowInstanceService
@Inject public WorkflowInstanceService(WorkflowInstanceDao workflowInstanceDao, WorkflowDefinitionService workflowDefinitionService, WorkflowInstancePreProcessor workflowInstancePreProcessor)
-
-
Method Details
-
getWorkflowInstance
public WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions) Return the workflow instance matching the given id.- Parameters:
id- Workflow instance id.includes- Set of properties to be loaded.maxActions- Maximum number of actions to be loaded.- Returns:
- The workflow instance.
- Throws:
NflowNotFoundException- If workflow instance is not found.
-
getWorkflowInstance
public WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions, boolean queryArchive) Return the workflow instance matching the given id.- Parameters:
id- Workflow instance id.includes- Set of properties to be loaded.maxActions- Maximum number of actions to be loaded.queryArchive- Query archive tables if not found from main tables.- Returns:
- The workflow instance
- Throws:
EmptyResultDataAccessException- if not found
-
insertWorkflowInstance
Insert the workflow instance to the database and return the id of the instance. If the instance already exists, return the id of the existing instance.- Parameters:
instance- The workflow instance to be inserted.- Returns:
- The id of the inserted or existing workflow instance.
-
updateWorkflowInstance
@Transactional public boolean updateWorkflowInstance(WorkflowInstance instance, WorkflowInstanceAction action) Update the workflow instance in the database if it is currently not running, and insert the workflow instance action. If the state of the instance is not null, the status of the instance is updated based on the new state. If the state of the instance is null, neither state nor status are updated.- Parameters:
instance- The instance to be updated.action- The action to be inserted.- Returns:
- True if the update was successful, false otherwise.
-
wakeupWorkflowInstance
Wake up the workflow instance matching the given id if it is in one of the expected states.- Parameters:
id- Workflow instance id.expectedStates- The expected states, empty for any.- Returns:
- True if the instance was woken up, false otherwise.
-
listWorkflowInstances
Return workflow instances matching the given query.- Parameters:
query- The query parameters.- Returns:
- Matching workflow instances, or empty collection if none found.
-
listWorkflowInstancesAsStream
Return workflow instances matching the given query.- Parameters:
query- The query parameters.- Returns:
- Matching workflow instances as Stream. The stream does not need to be closed.
-
getSignal
Return current signal value for given workflow instance.- Parameters:
workflowInstanceId- Workflow instance id.- Returns:
- Current signal value.
-
setSignal
public boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowInstanceAction.WorkflowActionType actionType) Set signal value for given workflow instance.- Parameters:
workflowInstanceId- Workflow instance id.signal- New value for the signal.reason- The reason for setting the signal.actionType- The type of workflow action that is stored to instance actions.- Returns:
- True when signal was set, false otherwise.
-
hasUnfinishedChildWorkflows
public boolean hasUnfinishedChildWorkflows(long workflowInstanceId) Return true if this workflow instance has unfinished child workflow instances.- Parameters:
workflowInstanceId- The parent workflow instance id.- Returns:
- True if the workflow instance has unfinished child workflow instances, false otherwise.
-