Class StateMachine
- java.lang.Object
-
- fr.gouv.vitam.processing.management.core.StateMachine
-
- All Implemented Interfaces:
IEventsProcessEngine,IEventsState
public class StateMachine extends java.lang.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, LogbookOperationsClientFactory logbookOperationsClientFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel as soon as possible the processWorkflow, To do that, the step pauseCancelAction is updated to be PauseOrCancelAction.ACTION_CANCEL Unlike pause, - The finally step should be executed, - PauseOrCancelAction.ACTION_CANCEL have no impact on the finally step - The finally step cannot be cancelledprotected voiddoCompleted()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 completedprotected voiddoPause(PauseRecover pauseRecover)Change state of the process to pause Can be called only from running state If last step then change state to completedprotected voiddoReplay(WorkerParameters workerParameters, ProcessState targetState)Change state of the process to running Can be called only from pause stateprotected voiddoRunning(WorkerParameters workerParameters, ProcessState targetState)Change state of the process to running Can be called only from pause stateprotected voidexecuteFinallyStep(WorkerParameters workerParameters)Execute the finally step of the workflow Update global status of the workflow Persist the process workflowprotected voidexecuteSteps(WorkerParameters workerParameters, PauseRecover pauseRecover, boolean backwards)Execute steps of the workflow and manage index of the current step Call engine to execute the current stepprotected voidfinalizeLogbook(WorkerParameters workParams)Create the final logbook entry for the corresponding process workflow This entry was created in ingest internal and as the process is full async we moved it to herejava.lang.StringgetContextId()LogbookTypeProcessgetLogbookTypeProcess()intgetTenant()java.lang.StringgetWorkflowId()booleanisCompleted()Check if the state is completedbooleanisDone()protected booleanisLastStep()Check if the current step is the last oneprotected booleanisPause()Check if the state is pausebooleanisRecover()protected booleanisRunning()Check if the state is runningbooleanisStepByStep()voidnext(WorkerParameters workerParameters)Like a resume but pause at the next stepvoidonComplete(ItemStatus itemStatus, WorkerParameters workerParameters)The ProcessEngine callback on complete step (for any status code)voidonError(java.lang.Throwable throwable)The ProcessEngine callback on system error occurredvoidonPauseOrCancel(PauseOrCancelAction pauseCancelAction, WorkerParameters workerParameters)The ProcessEngine callback onPauseOrCancel when the step is paused or cancelledvoidonUpdate(StatusCode statusCode)Update the current step status codevoidonUpdate(java.lang.String messageIdentifier, java.lang.String originatingAgency)voidpause()Pause the processWorkflow, If the last step the just wait the finally 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 stepprotected booleanpersistProcessWorkflow()Persist the process workflow in the workspacevoidreplay(WorkerParameters workerParameters)Replay the last executed step, or if it s stated, the step passed as a parametervoidresume(WorkerParameters workerParameters)Do an evaluation of the State RUNNING If the state is not permitted a StateNotAllowedException is thrown Else call doRunning methodvoidshutdown()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
-
-
-
Constructor Detail
-
StateMachine
public StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine)
-
StateMachine
public StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine, ProcessDataManagement dataManagement, WorkspaceClientFactory workspaceClientFactory, LogbookOperationsClientFactory logbookOperationsClientFactory)
-
-
Method Detail
-
resume
public void resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
Description copied from interface:IEventsStateDo an evaluation of the State RUNNING If the state is not permitted a StateNotAllowedException is thrown Else call doRunning method- Specified by:
resumein interfaceIEventsState- Throws:
StateNotAllowedExceptionProcessingException
-
next
public void next(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
Description copied from interface:IEventsStateLike a resume but pause at the next step- Specified by:
nextin interfaceIEventsState- Throws:
StateNotAllowedExceptionProcessingException
-
replay
public void replay(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException
Description copied from interface:IEventsStateReplay the last executed step, or if it s stated, the step passed as a parameter- Specified by:
replayin interfaceIEventsState- Throws:
StateNotAllowedExceptionProcessingException
-
pause
public void pause() throws StateNotAllowedExceptionDescription copied from interface:IEventsStatePause the processWorkflow, If the last step the just wait the finally 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:
pausein interfaceIEventsState- Throws:
StateNotAllowedException
-
shutdown
public void shutdown()
Description copied from interface:IEventsStateShould 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:
shutdownin interfaceIEventsState
-
cancel
public void cancel() throws StateNotAllowedExceptionDescription copied from interface:IEventsStateCancel as soon as possible the processWorkflow, To do that, the step pauseCancelAction is updated to be PauseOrCancelAction.ACTION_CANCEL Unlike pause, - The finally step should be executed, - PauseOrCancelAction.ACTION_CANCEL have no impact on the finally step - The finally step cannot be cancelled- Specified by:
cancelin interfaceIEventsState- Throws:
StateNotAllowedException
-
isDone
public boolean isDone()
- Specified by:
isDonein interfaceIEventsState- Returns:
- true is processWorkflow is completed or Pause
-
getTenant
public int getTenant()
- Specified by:
getTenantin interfaceIEventsState- Returns:
- The tenantId of the processWorkflow
-
getWorkflowId
public java.lang.String getWorkflowId()
- Specified by:
getWorkflowIdin interfaceIEventsState- Returns:
- The workflow Id
-
getContextId
public java.lang.String getContextId()
- Specified by:
getContextIdin interfaceIEventsState
-
isStepByStep
public boolean isStepByStep()
- Specified by:
isStepByStepin interfaceIEventsState- Returns:
- true if processWorkflow is running in stepByStep (next) mode or in continue mode (resume)
-
getLogbookTypeProcess
public LogbookTypeProcess getLogbookTypeProcess()
- Specified by:
getLogbookTypeProcessin interfaceIEventsState- 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
-
doCompleted
protected void doCompleted()
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 distributortargetState- if true, run ony the next step- Throws:
StateNotAllowedExceptionProcessingException
-
doReplay
protected void doReplay(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 distributortargetState- if true, run ony the next step- Throws:
StateNotAllowedExceptionProcessingException
-
executeSteps
protected void executeSteps(WorkerParameters workerParameters, PauseRecover pauseRecover, boolean backwards) throws ProcessingException
Execute steps of the workflow and manage index of the current step Call engine to execute the current step- Parameters:
workerParameters-- Throws:
ProcessingException
-
executeFinallyStep
protected void executeFinallyStep(WorkerParameters workerParameters)
Execute the finally 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:IEventsProcessEngineUpdate the current step status code- Specified by:
onUpdatein interfaceIEventsProcessEngine
-
onUpdate
public void onUpdate(java.lang.String messageIdentifier, java.lang.String originatingAgency)- Specified by:
onUpdatein interfaceIEventsProcessEngine
-
onError
public void onError(java.lang.Throwable throwable)
Description copied from interface:IEventsProcessEngineThe ProcessEngine callback on system error occurred- Specified by:
onErrorin interfaceIEventsProcessEngine
-
onPauseOrCancel
public void onPauseOrCancel(PauseOrCancelAction pauseCancelAction, WorkerParameters workerParameters)
Description copied from interface:IEventsProcessEngineThe ProcessEngine callback onPauseOrCancel when the step is paused or cancelled- Specified by:
onPauseOrCancelin interfaceIEventsProcessEngine
-
onComplete
public void onComplete(ItemStatus itemStatus, WorkerParameters workerParameters)
Description copied from interface:IEventsProcessEngineThe ProcessEngine callback on complete step (for any status code)- Specified by:
onCompletein interfaceIEventsProcessEngine
-
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:
isRecoverin interfaceIEventsState- 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
-
persistProcessWorkflow
protected boolean persistProcessWorkflow()
Persist the process workflow in the workspace- Returns:
- true is success, false else
-
finalizeLogbook
protected void finalizeLogbook(WorkerParameters workParams)
Create the final logbook entry for the corresponding process workflow This entry was created in ingest internal and as the process is full async we moved it to here
-
-