示例#1
0
  @Override
  public void close() {
    while (true) {
      OutputState state = _state.get();
      switch (state) {
        case CLOSED:
          {
            return;
          }

        case ASYNC:
        case UNREADY:
        case PENDING:
          {
            if (!_state.compareAndSet(state, OutputState.CLOSED)) break;
            IOException ex = new IOException("Closed while Pending/Unready");
            LOG.warn(ex.toString());
            LOG.debug(ex);
            _channel.abort(ex);
          }
        default:
          {
            if (!_state.compareAndSet(state, OutputState.CLOSED)) break;

            try {
              write(
                  BufferUtil.hasContent(_aggregate) ? _aggregate : BufferUtil.EMPTY_BUFFER,
                  !_channel.getResponse().isIncluding());
            } catch (IOException x) {
              // Ignore it, it's been already logged in write().
            } finally {
              releaseBuffer();
            }
            // Return even if an exception is thrown by write().
            return;
          }
      }
    }
  }
示例#2
0
 private void abort(Throwable failure) {
   closed();
   _channel.abort(failure);
 }