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 Details

  • Method Details

    • 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: StateExecution
      Return the id of the workflow instance.
      Specified by:
      getWorkflowInstanceId in interface StateExecution
      Returns:
      The workflow instance id.
    • getWorkflowInstanceExternalId

      public String getWorkflowInstanceExternalId()
      Description copied from interface: StateExecution
      Return the external id of the workflow instance.
      Specified by:
      getWorkflowInstanceExternalId in interface StateExecution
      Returns:
      The external id of the workflow instance.
    • getBusinessKey

      public String getBusinessKey()
      Description copied from interface: StateExecution
      Return the business key associated to the workflow instance.
      Specified by:
      getBusinessKey in interface StateExecution
      Returns:
      The business key.
    • setBusinessKey

      public void setBusinessKey(String businessKey)
      Description copied from interface: StateExecution
      Set the business key associated to the workflow instance.
      Specified by:
      setBusinessKey in interface StateExecution
      Parameters:
      businessKey - The business key.
    • getNewBusinessKey

      public String getNewBusinessKey()
    • getRetries

      public int getRetries()
      Description copied from interface: StateExecution
      Return the number of retry attempts in the current state.
      Specified by:
      getRetries in interface StateExecution
      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: StateExecution
      Return a string value of the given variable.
      Specified by:
      getVariable in interface StateExecution
      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: StateExecution
      Return the value of the given variable. The value is deserialized by the object mapper.
      Specified by:
      getVariable in interface StateExecution
      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: StateExecution
      Return 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:
      getVariable in interface StateExecution
      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: StateExecution
      Return the string value of the given variable, or {code defaultValue} if the variable does not exist.
      Specified by:
      getVariable in interface StateExecution
      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: StateExecution
      Set the string value of the given variable.
      Specified by:
      setVariable in interface StateExecution
      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: StateExecution
      Set the value for the given varible. The value must be serializable by the object mapper.
      Specified by:
      setVariable in interface StateExecution
      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: StateExecution
      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.
      Specified by:
      addChildWorkflows in interface StateExecution
      Parameters:
      childWorkflows - Child workflows to create.
    • addWorkflows

      public void addWorkflows(WorkflowInstance... workflows)
      Description copied from interface: StateExecution
      Add new workflows. Workflows are stored to database after current state method processing completes successfully.
      Specified by:
      addWorkflows in interface StateExecution
      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: StateExecution
      Return child workflow instances for current workflow. Query is restricted to childs of current workflow.
      Specified by:
      queryChildWorkflows in interface StateExecution
      Parameters:
      query - The query criterias.
      Returns:
      List of child workflows that match the query.
    • getAllChildWorkflows

      public List<WorkflowInstance> getAllChildWorkflows()
      Description copied from interface: StateExecution
      Return all child workflows for current workflow.
      Specified by:
      getAllChildWorkflows in interface StateExecution
      Returns:
      List of all child workflows.
    • wakeUpParentWorkflow

      public void wakeUpParentWorkflow(String... expectedStates)
      Description copied from interface: StateExecution
      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.
      Specified by:
      wakeUpParentWorkflow in interface StateExecution
      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.
    • getWakeUpParentWorkflowStates

      public Optional<List<String>> getWakeUpParentWorkflowStates()
    • workflowInstanceBuilder

      public WorkflowInstance.Builder workflowInstanceBuilder()
      Description copied from interface: StateExecution
      Create a builder for creating child workflows. Created builder has nextActivation set to current time.
      Specified by:
      workflowInstanceBuilder in interface StateExecution
      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: StateExecution
      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.
      Specified by:
      setCreateAction in interface StateExecution
      Parameters:
      createAction - Whether action should be created or not.
    • createAction

      public boolean createAction()
    • getSignal

      public Optional<Integer> getSignal()
      Description copied from interface: StateExecution
      Return the signal value from database if it has been set, otherwise return empty.
      Specified by:
      getSignal in interface StateExecution
      Returns:
      The signal value.
    • setSignal

      public void setSignal(Optional<Integer> signal, String reason)
      Description copied from interface: StateExecution
      Set the signal value to the database. Use Optional.empty() to clear the signal value.
      Specified by:
      setSignal in interface StateExecution
      Parameters:
      signal - Signal value to be set.
      reason - The reason for setting the signal.
    • getParentId

      public Optional<Long> getParentId()
      Description copied from interface: StateExecution
      Return the parent workflow instance id if this is a child workflow, otherwise return empty.
      Specified by:
      getParentId in interface StateExecution
      Returns:
      The parent workflow instance id or empty.
    • setHistoryCleaningForced

      public void setHistoryCleaningForced(boolean historyCleaningForced)
      Description copied from interface: StateExecution
      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.
      Specified by:
      setHistoryCleaningForced in interface StateExecution
      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: StateExecution
      Return true if this workflow instance has unfinished child workflow instances.
      Specified by:
      hasUnfinishedChildWorkflows in interface StateExecution
      Returns:
      True if unfinished child workflow instances are found, false otherwise.