/**
  * This method is the completion handler for the setMetadataTask.
  *
  * @param currentState Supplies the current state object.
  * @param task Supplies the task object.
  */
 private void processSetMetadataTask(final State currentState, final Task task) {
   switch (task.getState().toUpperCase()) {
     case "QUEUED":
     case "STARTED":
       scheduleSetMetadataTaskCall(this, currentState, task.getId());
       break;
     case "ERROR":
       throw new RuntimeException(ApiUtils.getErrors(task));
     case "COMPLETED":
       TaskUtils.sendSelfPatch(this, buildPatch(TaskState.TaskStage.FINISHED, (Throwable) null));
       break;
     default:
       throw new RuntimeException("Unknown task state: " + task.getState());
   }
 }
  private void processTask(final State currentState, final Task task) {
    FutureCallback<Task> pollTaskCallback =
        new FutureCallback<Task>() {
          @Override
          public void onSuccess(@Nullable Task result) {
            try {
              createTenantEntity(result.getEntity().getId());
            } catch (Throwable t) {
              failTask(t);
            }
          }

          @Override
          public void onFailure(Throwable t) {
            failTask(t);
          }
        };

    ApiUtils.pollTaskAsync(
        task, HostUtils.getApiClient(this), this, currentState.taskPollDelay, pollTaskCallback);
  }