private boolean _suspend(long time, TimeUnit unit, boolean failOnError)
      throws IllegalStateException {
    boolean suspendSuccessful = false;

    try {
      executionStateMonitor.enter();
      switch (executionState) {
        case RESUMED:
          break;
        case SUSPENDED:
        case CANCELLED:
          if (failOnError) {
            throw new IllegalStateException(
                LocalizationMessages.ILLEGAL_INVOCATION_CONTEXT_STATE(executionState, "suspend"));
          }
          break;
        case RUNNING:
          executionState = State.SUSPENDED;
          suspendSuccessful = true;
      }
    } finally {
      executionStateMonitor.leave();
    }

    // we don't want to invoke the callback or log message
    // as part of the synchronized code
    if (suspendSuccessful) {
      callback.suspended(time, unit, this);
    } else {
      // already resumed - just log fine message & ignore the call
      LOGGER.log(Level.FINE, LocalizationMessages.REQUEST_SUSPEND_FAILED(executionState));
    }

    return suspendSuccessful;
  }
 private void resume(final Runnable resumeHandler) {
   if (executionStateMonitor.enterIf(resumableState)) {
     final boolean invokeCallback;
     try {
       invokeCallback = executionState == State.SUSPENDED;
       executionState = State.RESUMED;
     } finally {
       executionStateMonitor.leave();
     }
     try {
       resumeHandler.run();
     } finally {
       if (invokeCallback) {
         callback.resumed();
       }
     }
   } else {
     throw new IllegalStateException(
         LocalizationMessages.ILLEGAL_INVOCATION_CONTEXT_STATE(executionState, "resume"));
   }
 }