Exemplo n.º 1
0
 protected void cancelTimeout() {
   final AsyncContextEvent event;
   try (Locker.Lock lock = _locker.lock()) {
     event = _event;
   }
   cancelTimeout(event);
 }
Exemplo n.º 2
0
  public void complete() {

    // just like resume, except don't set _dispatched=true;
    boolean handle = false;
    AsyncContextEvent event;
    try (Locker.Lock lock = _locker.lock()) {
      if (DEBUG) LOG.debug("complete {}", toStringLocked());

      boolean started = false;
      event = _event;

      switch (_async) {
        case STARTED:
          started = true;
          break;
        case EXPIRING:
        case ERRORING:
        case ERRORED:
          break;
        case COMPLETE:
          return;
        default:
          throw new IllegalStateException(this.getStatusStringLocked());
      }
      _async = Async.COMPLETE;

      if (started && _state == State.ASYNC_WAIT) {
        handle = true;
        _state = State.ASYNC_WOKEN;
      }
    }

    cancelTimeout(event);
    if (handle) runInContext(event, _channel);
  }
Exemplo n.º 3
0
  public void errorComplete() {
    try (Locker.Lock lock = _locker.lock()) {
      if (DEBUG) LOG.debug("error complete {}", toStringLocked());

      _async = Async.COMPLETE;
      _event.setDispatchContext(null);
      _event.setDispatchPath(null);
    }

    cancelTimeout();
  }
Exemplo n.º 4
0
  public void dispatch(ServletContext context, String path) {
    boolean dispatch = false;
    AsyncContextEvent event;
    try (Locker.Lock lock = _locker.lock()) {
      if (DEBUG) LOG.debug("dispatch {} -> {}", toStringLocked(), path);

      boolean started = false;
      event = _event;
      switch (_async) {
        case STARTED:
          started = true;
          break;
        case EXPIRING:
        case ERRORING:
        case ERRORED:
          break;
        default:
          throw new IllegalStateException(this.getStatusStringLocked());
      }
      _async = Async.DISPATCH;

      if (context != null) _event.setDispatchContext(context);
      if (path != null) _event.setDispatchPath(path);

      if (started) {
        switch (_state) {
          case DISPATCHED:
          case ASYNC_IO:
          case ASYNC_WOKEN:
            break;
          case ASYNC_WAIT:
            _state = State.ASYNC_WOKEN;
            dispatch = true;
            break;
          default:
            LOG.warn("async dispatched when complete {}", this);
            break;
        }
      }
    }

    cancelTimeout(event);
    if (dispatch) scheduleDispatch();
  }
Exemplo n.º 5
0
  public void upgrade() {
    cancelTimeout();
    try (Locker.Lock lock = _locker.lock()) {
      if (DEBUG) LOG.debug("upgrade {}", toStringLocked());

      switch (_state) {
        case IDLE:
        case COMPLETED:
          break;
        default:
          throw new IllegalStateException(getStatusStringLocked());
      }
      _asyncListeners = null;
      _state = State.UPGRADED;
      _async = null;
      _initial = true;
      _asyncReadPossible = _asyncReadUnready = false;
      _asyncWrite = false;
      _timeoutMs = DEFAULT_TIMEOUT;
      _event = null;
    }
  }
Exemplo n.º 6
0
  protected void recycle() {
    cancelTimeout();
    try (Locker.Lock lock = _locker.lock()) {
      if (DEBUG) LOG.debug("recycle {}", toStringLocked());

      switch (_state) {
        case DISPATCHED:
        case ASYNC_IO:
          throw new IllegalStateException(getStatusStringLocked());
        case UPGRADED:
          return;
        default:
          break;
      }
      _asyncListeners = null;
      _state = State.IDLE;
      _async = null;
      _initial = true;
      _asyncReadPossible = _asyncReadUnready = false;
      _asyncWrite = false;
      _timeoutMs = DEFAULT_TIMEOUT;
      _event = null;
    }
  }