Package fr.gouv.vitam.processing.management.core

# Class StateMachine

java.lang.Object
fr.gouv.vitam.processing.management.core.StateMachine

All Implemented Interfaces:
  `IEventsProcessEngine`, `IEventsState`

public class StateMachine extends Object implements IEventsState, IEventsProcessEngine
State Machine class implementing the Interface. Dealing with evolution of workflow

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine)`
  `StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine, ProcessDataManagement dataManagement, WorkspaceClientFactory workspaceClientFactory)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cancel(boolean force)`
  Cancel as soon as possible the processWorkflow, To do that, the step pauseCancelAction is updated to be PauseOrCancelAction.ACTION_CANCEL Unlike pause, - The final step should be executed, - PauseOrCancelAction.ACTION_CANCEL have no impact on the final step - The final step cannot be cancelled
  `protected void`
  `doCancel(boolean force)`
  Change the state of the process to completed Can be called only from running or pause state If running state, the next step will be completed
  `protected void`
  `doPause(PauseRecover pauseRecover)`
  Change state of the process to pause Can be called only from running state If last step then change state to completed
  `protected void`
  `doReplay(WorkerParameters workerParameters)`
  Change state of the process to running Can be called only from pause state
  `protected void`
  `doRunning(WorkerParameters workerParameters, ProcessState targetState)`
  Change state of the process to running Can be called only from pause state
  `protected void`
  `executeFinalStep(WorkerParameters workerParameters)`
  Execute the final step of the workflow Update global status of the workflow Persist the process workflow
  `protected void`
  `finalizeOperation()`
  `protected void`
  `findAndExecuteNextStep(WorkerParameters workerParameters, boolean replayCurrentStep)`
  `String`
  `getContextId()`
  `StatusCode`
  `getCurrentProcessWorkflowStatus()`
  `ProcessStep`
  `getCurrentStep()`
  `LogbookTypeProcess`
  `getLogbookTypeProcess()`
  `int`
  `getStepIndex()`
  `int`
  `getTenant()`
  `String`
  `getWorkflowId()`
  `Map<String,String>`
  `getWorkflowParameters()`
  `boolean`
  `isCompleted()`
  Check if the state is completed
  `boolean`
  `isDone()`
  `protected boolean`
  `isLastStep()`
  Check if the current step is the last one
  `protected boolean`
  `isPause()`
  Check if the state is pause
  `boolean`
  `isRecover()`
  `protected boolean`
  `isRunning()`
  Check if the state is running
  `boolean`
  `isStepByStep()`
  `void`
  `next(WorkerParameters workerParameters)`
  Like a resume but pause at the next step
  `void`
  `onError(Throwable throwable)`
  The ProcessEngine callback on system error occurred
  `void`
  `onProcessEngineCancel(WorkerParameters workerParameters)`
  The ProcessEngine callback when the step is cancelled
  `void`
  `onProcessEngineCompleteStep(ItemStatus itemStatus, WorkerParameters workerParameters)`
  The ProcessEngine callback on complete step (for any status code)
  `void`
  `onUpdate(StatusCode statusCode)`
  Update the current step status code
  `void`
  `onUpdate(String messageIdentifier, String originatingAgency)`
  `void`
  `pause()`
  Pause the processWorkflow, If the last step the just wait the final step Else pause the processWorkflow as soon as possible Do not wait all elements of the current step to be executed The step pauseCancelAction will be updated to PauseOrCancelAction.ACTION_PAUSE If all elements of the current step are executed then stop correctly and step pauseCancelAction will be updated to PauseOrCancelAction.ACTION_COMPLETE After next or resume occurs on paused processWorkflow, It will starts from the step pauseCancelAction equals to PauseOrCancelAction.ACTION_PAUSE if exists and update pauseCancelAction to be PauseOrCancelAction.ACTION_RECOVER Else starts normally from the next step
  `void`
  `replay(WorkerParameters workerParameters)`
  Replay the last executed step, or if it s stated, the step passed as a parameter
  `void`
  `resume(WorkerParameters workerParameters)`
  Do an evaluation of the State RUNNING If the state is not permitted a StateNotAllowedException is thrown Else call doRunning method
  `void`
  `shutdown()`
  Should used only when server is shutting down To prevent deadlock, this method is not synchronized, Because onComplete and onPauseOrCancel are synchronized and called from ProcessEngine
  `protected boolean`
  `tryPersistProcessWorkflow()`
  Persist the process workflow in the workspace

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### StateMachine

    public StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine)

  - ### StateMachine

    public StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine, ProcessDataManagement dataManagement, WorkspaceClientFactory workspaceClientFactory)

- ## Method Details

  - ### resume

    public void resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
    Description copied from interface: `IEventsState`
    Do an evaluation of the State RUNNING If the state is not permitted a StateNotAllowedException is thrown Else call doRunning method
    Specified by:
      `resume` in interface `IEventsState`
    Parameters:
      `workerParameters` -
    Throws:
      `StateNotAllowedException`
      `ProcessingException`

  - ### next

    public void next(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
    Description copied from interface: `IEventsState`
    Like a resume but pause at the next step
    Specified by:
      `next` in interface `IEventsState`
    Parameters:
      `workerParameters` -
    Throws:
      `StateNotAllowedException`
      `ProcessingException`

  - ### replay

    public void replay(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
    Description copied from interface: `IEventsState`
    Replay the last executed step, or if it s stated, the step passed as a parameter
    Specified by:
      `replay` in interface `IEventsState`
    Parameters:
      `workerParameters` -
    Throws:
      `StateNotAllowedException`
      `ProcessingException`

  - ### pause

    public void pause() throws StateNotAllowedException
    Description copied from interface: `IEventsState`
    Pause the processWorkflow, If the last step the just wait the final step Else pause the processWorkflow as soon as possible Do not wait all elements of the current step to be executed The step pauseCancelAction will be updated to PauseOrCancelAction.ACTION_PAUSE If all elements of the current step are executed then stop correctly and step pauseCancelAction will be updated to PauseOrCancelAction.ACTION_COMPLETE After next or resume occurs on paused processWorkflow, It will starts from the step pauseCancelAction equals to PauseOrCancelAction.ACTION_PAUSE if exists and update pauseCancelAction to be PauseOrCancelAction.ACTION_RECOVER Else starts normally from the next step
    Specified by:
      `pause` in interface `IEventsState`
    Throws:
      `StateNotAllowedException`

  - ### shutdown

    public void shutdown()
    Description copied from interface: `IEventsState`
    Should used only when server is shutting down To prevent deadlock, this method is not synchronized, Because onComplete and onPauseOrCancel are synchronized and called from ProcessEngine
    Specified by:
      `shutdown` in interface `IEventsState`

  - ### cancel

    public void cancel(boolean force) throws StateNotAllowedException
    Description copied from interface: `IEventsState`
    Cancel as soon as possible the processWorkflow, To do that, the step pauseCancelAction is updated to be PauseOrCancelAction.ACTION_CANCEL Unlike pause, - The final step should be executed, - PauseOrCancelAction.ACTION_CANCEL have no impact on the final step - The final step cannot be cancelled
    Specified by:
      `cancel` in interface `IEventsState`
    Parameters:
      `force` - force cancellation if the current step is not cancellable. If false, and the current step is not cancellable, the method will throw a StateNotAllowedException.
    Throws:
      `StateNotAllowedException`

  - ### isDone

    public boolean isDone()
    Specified by:
      `isDone` in interface `IEventsState`
    Returns:
      true is processWorkflow is completed or Pause

  - ### getTenant

    public int getTenant()
    Specified by:
      `getTenant` in interface `IEventsState`
    Returns:
      The tenantId of the processWorkflow

  - ### getWorkflowId

    public String getWorkflowId()
    Specified by:
      `getWorkflowId` in interface `IEventsState`
    Returns:
      The workflow Id

  - ### getContextId

    public String getContextId()
    Specified by:
      `getContextId` in interface `IEventsState`

  - ### getWorkflowParameters

    public Map<String,String> getWorkflowParameters()
    Specified by:
      `getWorkflowParameters` in interface `IEventsState`

  - ### isStepByStep

    public boolean isStepByStep()
    Specified by:
      `isStepByStep` in interface `IEventsState`
    Returns:
      true if processWorkflow is running in stepByStep (next) mode or in continue mode (resume)

  - ### getLogbookTypeProcess

    public LogbookTypeProcess getLogbookTypeProcess()
    Specified by:
      `getLogbookTypeProcess` in interface `IEventsState`
    Returns:
      The LogbookTypeProcess

  - ### doPause

    protected void doPause(PauseRecover pauseRecover)
    Change state of the process to pause Can be called only from running state If last step then change state to completed
    Parameters:
      `pauseRecover` - if RECOVER_FROM_SERVER_PAUSE then wait until pause is done

  - ### doCancel

    protected void doCancel(boolean force)
    Change the state of the process to completed Can be called only from running or pause state If running state, the next step will be completed

  - ### doRunning

    protected void doRunning(WorkerParameters workerParameters, ProcessState targetState) throws ProcessingException
    Change state of the process to running Can be called only from pause state
    Parameters:
      `workerParameters` - the parameters to be passed to the distributor
      `targetState` - if true, run ony the next step
    Throws:
      `ProcessingException`

  - ### doReplay

    protected void doReplay(WorkerParameters workerParameters) throws ProcessingException
    Change state of the process to running Can be called only from pause state
    Parameters:
      `workerParameters` - the parameters to be passed to the distributor
    Throws:
      `ProcessingException`

  - ### findAndExecuteNextStep

    protected void findAndExecuteNextStep(WorkerParameters workerParameters, boolean replayCurrentStep)
    Parameters:
      `workerParameters` -
      `replayCurrentStep` -

  - ### executeFinalStep

    protected void executeFinalStep(WorkerParameters workerParameters)
    Execute the final step of the workflow Update global status of the workflow Persist the process workflow
    Parameters:
      `workerParameters` -

  - ### onUpdate

    public void onUpdate(StatusCode statusCode)
    Description copied from interface: `IEventsProcessEngine`
    Update the current step status code
    Specified by:
      `onUpdate` in interface `IEventsProcessEngine`
    Parameters:
      `statusCode` -

  - ### getCurrentProcessWorkflowStatus

    public StatusCode getCurrentProcessWorkflowStatus()
    Specified by:
      `getCurrentProcessWorkflowStatus` in interface `IEventsProcessEngine`

  - ### onUpdate

    public void onUpdate(String messageIdentifier, String originatingAgency)
    Specified by:
      `onUpdate` in interface `IEventsProcessEngine`
    Parameters:
      `messageIdentifier` -
      `originatingAgency` -

  - ### onError

    public void onError(Throwable throwable)
    Description copied from interface: `IEventsProcessEngine`
    The ProcessEngine callback on system error occurred
    Specified by:
      `onError` in interface `IEventsProcessEngine`
    Parameters:
      `throwable` -

  - ### onProcessEngineCancel

    public void onProcessEngineCancel(WorkerParameters workerParameters)
    Description copied from interface: `IEventsProcessEngine`
    The ProcessEngine callback when the step is cancelled
    Specified by:
      `onProcessEngineCancel` in interface `IEventsProcessEngine`
    Parameters:
      `workerParameters` -

  - ### onProcessEngineCompleteStep

    public void onProcessEngineCompleteStep(ItemStatus itemStatus, WorkerParameters workerParameters)
    Description copied from interface: `IEventsProcessEngine`
    The ProcessEngine callback on complete step (for any status code)
    Specified by:
      `onProcessEngineCompleteStep` in interface `IEventsProcessEngine`
    Parameters:
      `itemStatus` -
      `workerParameters` -

  - ### isRunning

    protected boolean isRunning()
    Check if the state is running
    Returns:
      true if the current state is running

  - ### isPause

    protected boolean isPause()
    Check if the state is pause
    Returns:
      true if the current state is pause

  - ### isCompleted

    public boolean isCompleted()
    Check if the state is completed
    Returns:
      true if the current state is completed

  - ### isRecover

    public boolean isRecover()
    Specified by:
      `isRecover` in interface `IEventsState`
    Returns:
      true is processWorkflow is Pause

  - ### isLastStep

    protected boolean isLastStep()
    Check if the current step is the last one
    Returns:
      true if the current step is the last one

  - ### tryPersistProcessWorkflow

    protected boolean tryPersistProcessWorkflow()
    Persist the process workflow in the workspace
    Returns:
      true is success, false else

  - ### finalizeOperation

    protected void finalizeOperation()

  - ### getCurrentStep

    public ProcessStep getCurrentStep()

  - ### getStepIndex

    public int getStepIndex()