@Override public void handlePatch(Operation patch){
  State currentState=getState(patch);
  State patchState=patch.getBody(State.class);
  try {
    validatePatch(currentState,patchState);
    applyPatch(currentState,patchState);
    validateState(currentState);
    patch.complete();
switch (currentState.taskInfo.stage) {
case STARTED:
      handleStartedStage(currentState,patchState);
    break;
case FAILED:
case FINISHED:
case CANCELLED:
  break;
default :
throw new IllegalStateException(String.format("Invalid stage %s",currentState.taskInfo.stage));
}
}
 catch (Throwable e) {
ServiceUtils.logSevere(this,e);
if (!OperationUtils.isCompleted(patch)) {
patch.fail(e);
}
}
}

@ Override public void handlePatch ( Operation patch ) { State currentState = getState ( patch ) ; State patchState = patch . getBody ( State . class ) ; try { validatePatch ( currentState , patchState ) ; applyPatch ( currentState , patchState ) ; validateState ( currentState ) ; patch . complete ( ) ; switch ( currentState . taskInfo . stage ) { case STARTED : handleStartedStage ( currentState , patchState ) ; break ; case FAILED : case FINISHED : case CANCELLED : break ; default : throw new IllegalStateException ( String . format ( "Invalid stage %s" , currentState . taskInfo . stage ) ) ; } } catch ( Throwable e ) { ServiceUtils . logSevere ( this , e ) ; if ( ! OperationUtils . isCompleted ( patch ) ) { patch . fail ( e ) ; } } }
patch operation handler . implements all logic to drive our state machine .
