@Override protected boolean isFinished() { return anyAreSet(state, RESPONSE_TERMINATED); } };
public int write(final ByteBuffer src) throws IOException { if (anyAreSet(state, FLAG_CLOSE_COMPLETE)) { throw new ClosedChannelException(); } int remaining = src.remaining(); src.position(src.position() + remaining); return remaining; }
public void suspendWrites() { long val = state; if (anyAreSet(val, FLAG_CLOSE_COMPLETE)) { return; } next.suspendWrites(); }
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException { if (anyAreSet(state, FLAG_CLOSED | FLAG_FINISHED)) { return; } delegate.awaitReadable(time, timeUnit); }
@Override public void resumeReads() { if(anyAreSet(state, FLAG_READS_RESUMED)) { //already resumed return; } resumeReads(false); } @Override
public void wakeupReads() { int oldVal, newVal; do { oldVal = state; if (anyAreSet(oldVal, CLOSED)) { return; } newVal = RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); thread.execute(readRunnable); }
@Override public boolean isUpgraded() { if(http2Delegate != null) { return http2Delegate.isUpgraded(); } return anyAreSet(state, UPGRADE_REQUESTED | UPGRADED); }
@Override public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED)) { throw new ClosedChannelException(); } if (!performFlushIfRequired()) { return 0; } return src.transferTo(position, count, new ConduitWritableByteChannel(this)); }
public void resumeWrites() { int oldVal, newVal; do { oldVal = state; if (anyAreSet(oldVal, FLAG_RESUMED | FLAG_CLOSED)) { return; } newVal = oldVal | FLAG_RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); thread.execute(ChannelListeners.getChannelListenerTask(this, writeListener)); }
@Override public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { if (anyAreSet(state, FLAG_WRITES_SHUTDOWN)) { throw new ClosedChannelException(); } return IoUtils.transfer(source, count, throughBuffer, new ConduitWritableByteChannel(this)); }
/** {@inheritDoc} */ public void wakeupReads() { if (anyAreSet(state, READ_SHUT_DOWN)) { return; } setFlags(READ_REQUESTED); channel.wakeupReads(); }
@Override public void terminateWrites() throws IOException { if (anyAreSet(state, FLAG_WRITES_SHUTDOWN)) { return; } if (chunkReader.getChunkRemaining() != -1) { throw UndertowMessages.MESSAGES.chunkedChannelClosedMidChunk(); } state |= FLAG_WRITES_SHUTDOWN; }
void terminateRequest() { state |= REQUEST_TERMINATED; if(!clientConnection.isOpen()) { state |= RESPONSE_TERMINATED; } if (anyAreSet(state, RESPONSE_TERMINATED)) { clientConnection.requestDone(); } }
public boolean flush() throws IOException { int val = state; if (anyAreSet(val, FLAG_CLOSE_COMPLETE)) { return true; } boolean flushed = false; try { return flushed = next.flush(); } finally { exitFlush(val, flushed); } }
private void resumeReads(boolean wakeup) { state |= FLAG_READS_RESUMED; if(anyAreSet(state, FLAG_READ_REQUIRES_WRITE)) { delegate.getSinkChannel().resumeWrites(); } else { if(anyAreSet(state, FLAG_DATA_TO_UNWRAP) || wakeup || unwrappedData != null) { runReadListener(true); } else { delegate.getSourceChannel().resumeReads(); } } }
void terminateResponse() { if(anyAreSet(state, RESPONSE_TERMINATED)) { return; } log.debugf("response terminated for request to %s %s", clientConnection.getPeerAddress(), getRequest().getPath()); state |= RESPONSE_TERMINATED; if (anyAreSet(state, REQUEST_TERMINATED)) { clientConnection.exchangeDone(); } }
@Override public void awaitReadable() throws IOException { try { if (anyAreSet(state, STATE_READING)) { next.awaitReadable(); } } catch (IOException | RuntimeException e) { IoUtils.safeClose(exchange.getConnection()); throw e; } }
/** {@inheritDoc} */ public void wakeupWrites() { if (anyAreSet(state, WRITE_SHUT_DOWN)) { return; } setFlags(WRITE_REQUESTED); channel.wakeupWrites(); unparkWriteWaiters(); }
private void readIntoBuffer() throws IOException { if (pooled == null && !anyAreSet(state, FLAG_FINISHED)) { pooled = bufferPool.allocate(); int res = Channels.readBlocking(channel, pooled.getBuffer()); pooled.getBuffer().flip(); if (res == -1) { state |= FLAG_FINISHED; pooled.close(); pooled = null; } } }
@Override public void resumeWrites() { if (isInCall()) { state |= FLAG_SHOULD_RESUME_WRITES; if(anyAreSet(state, FLAG_DISPATCHED)) { throw UndertowMessages.MESSAGES.resumedAndDispatched(); } } else if(!isFinished()){ delegate.resumeWrites(); } }