@Override public void handlePatch(Operation patch){
  State task=getState(patch);
  State body=getBody(patch);
  if (!validateTransition(patch,task,body)) {
    return;
  }
  TaskState.TaskStage currentStage=task.taskInfo.stage;
  SubStage currentSubStage=task.subStage;
  if (task.subStage == SubStage.RESTART) {
    task.taskInfo.stage=TaskState.TaskStage.STARTED;
    task.subStage=SubStage.QUERY;
  }
 else {
    updateState(task,body);
  }
  if (this.isDetailedLoggingEnabled) {
    logInfo("Transitioning task from %s-%s to %s-%s",currentStage,currentSubStage,task.taskInfo.stage,task.subStage);
  }
  boolean isTaskFinished=!TaskState.isInProgress(task.taskInfo);
  if (isTaskFinished) {
    setFactoryAvailability(task,true,null,patch);
  }
 else {
    patch.complete();
  }
switch (task.taskInfo.stage) {
case STARTED:
    handleSubStage(task);
  break;
case CANCELLED:
logInfo("Task canceled: not implemented, ignoring");
break;
case FINISHED:
break;
case FAILED:
logWarning("Task failed: %s",(task.failureMessage != null ? task.failureMessage : "No reason given"));
break;
default :
break;
}
}

@ Override public void handlePatch ( Operation patch ) { State task = getState ( patch ) ; State body = getBody ( patch ) ; if ( ! validateTransition ( patch , task , body ) ) { return ; } TaskState . TaskStage currentStage = task . taskInfo . stage ; SubStage currentSubStage = task . subStage ; if ( task . subStage == SubStage . RESTART ) { task . taskInfo . stage = TaskState . TaskStage . STARTED ; task . subStage = SubStage . QUERY ; } else { updateState ( task , body ) ; } if ( this . isDetailedLoggingEnabled ) { logInfo ( "Transitioning task from %s-%s to %s-%s" , currentStage , currentSubStage , task . taskInfo . stage , task . subStage ) ; } boolean isTaskFinished = ! TaskState . isInProgress ( task . taskInfo ) ; if ( isTaskFinished ) { setFactoryAvailability ( task , true , null , patch ) ; } else { patch . complete ( ) ; } switch ( task . taskInfo . stage ) { case STARTED : handleSubStage ( task ) ; break ; case CANCELLED : logInfo ( "Task canceled: not implemented, ignoring" ) ; break ; case FINISHED : break ; case FAILED : logWarning ( "Task failed: %s" , ( task . failureMessage != null ? task . failureMessage : "No reason given" ) ) ; break ; default : break ; } }
synchronization - task self - patches as it progress through the state - machine . handlepatch checks for state transitions and invokes the correct behavior given the task ' s next stage .
