@Override
  public void handleStart(Operation startOperation) {
    ServiceUtils.logInfo(this, "Starting service %s", getSelfLink());
    State startState = startOperation.getBody(State.class);
    InitializationUtils.initialize(startState);

    if (null == startState.taskPollDelay) {
      startState.taskPollDelay = HostUtils.getDeployerContext(this).getTaskPollDelay();
    }

    validateState(startState);

    if (TaskState.TaskStage.CREATED == startState.taskState.stage) {
      startState.taskState.stage = TaskState.TaskStage.STARTED;
    }

    startOperation.setBody(startState).complete();

    try {
      if (ControlFlags.isOperationProcessingDisabled(startState.controlFlags)) {
        ServiceUtils.logInfo(this, "Skipping start operation processing (disabled)");
      } else if (TaskState.TaskStage.STARTED == startState.taskState.stage) {
        sendStageProgressPatch(startState.taskState.stage);
      }
    } catch (Throwable t) {
      failTask(t);
    }
  }
  void handlePatchForDeposit(Operation patch) {
    BankAccountServiceState currentState = getState(patch);
    BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class);

    currentState.balance += body.amount;

    setState(patch, currentState);
    patch.setBody(currentState);
    patch.complete();
  }
  void handlePatchForWithdraw(Operation patch) {
    BankAccountServiceState currentState = getState(patch);
    BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class);

    if (body.amount > currentState.balance) {
      patch.fail(new IllegalArgumentException("Not enough funds to withdraw"));
      return;
    }
    currentState.balance -= body.amount;

    setState(patch, currentState);
    patch.setBody(currentState);
    patch.complete();
  }