@Override public int write(ByteBuffer src) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); if (buffer.remaining() > src.remaining()) { int put = src.remaining(); buffer.put(src); return put; } else { return (int) flushBufferWithUserData(new ByteBuffer[]{src}, 0, 1); } }
/** * Flushes the cached data. * <p> * This should be called when a read thread fails to read any more request data, to make sure that any * buffered data is flushed after the last pipelined request. * <p> * If this returns false the read thread should suspend reads and resume writes * * @return <code>true</code> If the flush succeeded, false otherwise * @throws IOException */ public boolean flushPipelinedData() throws IOException { if (buffer == null || (buffer.getBuffer().position() == 0 && allAreClear(state, FLUSHING))) { return next.flush(); } return flushBuffer(); }
@Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); long total = Buffers.remaining(srcs, offset, length); if (buffer.remaining() > total) { long put = total; Buffers.copy(buffer, srcs, offset, length); return put; } else { return flushBufferWithUserData(srcs, offset, length); } }
@Override public boolean flush() throws IOException { if (anyAreSet(state, SHUTDOWN)) { if (!flushBuffer()) { return false; } if (anyAreSet(state, SHUTDOWN) && anyAreClear(state, DELEGATE_SHUTDOWN)) { state |= DELEGATE_SHUTDOWN; next.terminateWrites(); } return next.flush(); } return true; }
@Override public int write(ByteBuffer src) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); if (buffer.remaining() > src.remaining()) { int put = src.remaining(); buffer.put(src); return put; } else { return (int) flushBufferWithUserData(new ByteBuffer[]{src}, 0, 1); } }
/** * Flushes the cached data. * <p> * This should be called when a read thread fails to read any more request data, to make sure that any * buffered data is flushed after the last pipelined request. * <p> * If this returns false the read thread should suspend reads and resume writes * * @return <code>true</code> If the flush succeeded, false otherwise * @throws IOException */ public boolean flushPipelinedData() throws IOException { if (buffer == null || (buffer.getBuffer().position() == 0 && allAreClear(state, FLUSHING))) { return next.flush(); } return flushBuffer(); }
@Override public int write(ByteBuffer src) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); if (buffer.remaining() > src.remaining()) { int put = src.remaining(); buffer.put(src); return put; } else { return (int) flushBufferWithUserData(new ByteBuffer[]{src}, 0, 1); } }
/** * Flushes the cached data. * <p> * This should be called when a read thread fails to read any more request data, to make sure that any * buffered data is flushed after the last pipelined request. * <p> * If this returns false the read thread should suspend reads and resume writes * * @return <code>true</code> If the flush succeeded, false otherwise * @throws IOException */ public boolean flushPipelinedData() throws IOException { if (buffer == null || (buffer.getBuffer().position() == 0 && allAreClear(state, FLUSHING))) { return next.flush(); } return flushBuffer(); }
@Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); long total = Buffers.remaining(srcs, offset, length); if (buffer.remaining() > total) { long put = total; Buffers.copy(buffer, srcs, offset, length); return put; } else { return flushBufferWithUserData(srcs, offset, length); } }
@Override public boolean flush() throws IOException { if (anyAreSet(state, SHUTDOWN)) { if (!flushBuffer()) { return false; } if (anyAreSet(state, SHUTDOWN) && anyAreClear(state, DELEGATE_SHUTDOWN)) { state |= DELEGATE_SHUTDOWN; next.terminateWrites(); } return next.flush(); } return true; }
@Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { if (anyAreSet(state, SHUTDOWN)) { throw new ClosedChannelException(); } if (anyAreSet(state, FLUSHING)) { boolean res = flushBuffer(); if (!res) { return 0; } } PooledByteBuffer pooled = this.buffer; if (pooled == null) { this.buffer = pooled = pool.allocate(); } final ByteBuffer buffer = pooled.getBuffer(); long total = Buffers.remaining(srcs, offset, length); if (buffer.remaining() > total) { long put = total; Buffers.copy(buffer, srcs, offset, length); return put; } else { return flushBufferWithUserData(srcs, offset, length); } }
@Override public boolean flush() throws IOException { if (anyAreSet(state, SHUTDOWN)) { if (!flushBuffer()) { return false; } if (anyAreSet(state, SHUTDOWN) && anyAreClear(state, DELEGATE_SHUTDOWN)) { state |= DELEGATE_SHUTDOWN; next.terminateWrites(); } return next.flush(); } return true; }