@Override
    public void onFailure(Throwable t) {
      SettableFuture<WmTezSession> future;
      WmTezSession session;
      boolean wasCanceled = false, doRetry = false;
      lock.lock();
      try {
        wasCanceled = (state == SessionInitState.CANCELED);
        session = this.session;
        this.session = null;
        doRetry = !wasCanceled && (attemptNumber < MAX_ATTEMPT_NUMBER);
        if (doRetry) {
          ++attemptNumber;
          this.state = SessionInitState.GETTING;
          future = null;
        } else {
          future = this.future;
          this.future = null;
          if (!wasCanceled) {
            this.state = SessionInitState.DONE;
          }
        }
      } finally {
        lock.unlock();
      }
      if (doRetry) {
        try {
          start();
          return;
        } catch (Exception e) {
          LOG.error("Failed to retry; propagating original error. The new error is ", e);
        } finally {
          discardSessionOnFailure(session);
        }
      }
      if (!wasCanceled) {
        LOG.debug("Queueing the initialization failure with {}", session);
        notifyInitializationCompleted(this); // Report failure to the main thread.
      }
      future.setException(t);
      discardSessionOnFailure(session);
    }
The class that serves as a synchronization point, and future callback,
for async session initialization, as well as parallel cancellation.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/WorkloadManager.java