@Override public void consume(int delta) { super.consume(delta); clientDataInfo.consume(delta); } };
private DataInfo toDataInfo(ByteBuffer buffer, boolean close) { return new ByteBufferDataInfo(buffer, close); }
@Override public int readInto(byte[] bytes, int offset, int length) { int available = available(); if (available < length) length = available; buffer.get(bytes, offset, length); return length; }
@Override public void consume(int delta) { super.consume(delta); flowControlStrategy.onDataConsumed(StandardSession.this, stream, this, delta); } };
@Override public void onSuccess(Response response) { if (LOG.isDebugEnabled()) LOG.debug("onSuccess called. Closing client stream."); clientStream.data(new ByteBufferDataInfo(BufferUtil.EMPTY_BUFFER, true), LOGGING_CALLBACK); }
@Override public int readInto(ByteBuffer output) { int space = output.remaining(); if (available() > space) { int limit = buffer.limit(); buffer.limit(buffer.position() + space); output.put(buffer); buffer.limit(limit); } else { space = buffer.remaining(); output.put(buffer); } return space; }
@Override public void consume(int delta) { super.consume(delta); clientDataInfo.consume(delta); } };
ByteBufferDataInfo copyDataInfo = new ByteBufferDataInfo(dataInfo.asByteBuffer(false), dataInfo.isClose(), dataInfo.isCompress())
@Override public void consume(int delta) { super.consume(delta); serverDataInfo.consume(delta); } };
private DataInfo toDataInfo(Buffer buffer, boolean close) { if (buffer instanceof ByteArrayBuffer) return new BytesDataInfo(buffer.array(), buffer.getIndex(), buffer.length(), close); if (buffer instanceof NIOBuffer) { ByteBuffer byteBuffer = ((NIOBuffer)buffer).getByteBuffer(); byteBuffer.limit(buffer.putIndex()); byteBuffer.position(buffer.getIndex()); return new ByteBufferDataInfo(byteBuffer, close); } return new BytesDataInfo(buffer.asArray(), close); }
@Override public void consume(int delta) { super.consume(delta); dataInfo.consume(delta); } };
@Override public void complete() throws IOException { Buffer content = getContentBuffer(); if (content != null) { closed = true; _state = STATE_END; flush(getMaxIdleTime()); } else if (!closed) { closed = true; _state = STATE_END; // Send the last, empty, data frame stream.data(new ByteBufferDataInfo(ZERO_BYTES, true)); } } }
@Override public void consume(int delta) { super.consume(delta); dataInfo.consume(delta); } };
private DataInfo toDataInfo(Buffer buffer, boolean close) { if (buffer instanceof ByteArrayBuffer) return new BytesDataInfo(buffer.array(), buffer.getIndex(), buffer.length(), close); if (buffer instanceof NIOBuffer) { ByteBuffer byteBuffer = ((NIOBuffer)buffer).getByteBuffer(); byteBuffer.limit(buffer.putIndex()); byteBuffer.position(buffer.getIndex()); return new ByteBufferDataInfo(byteBuffer, close); } return new BytesDataInfo(buffer.asArray(), close); }
@Override public void consume(int delta) { super.consume(delta); serverDataInfo.consume(delta); } };
@Override public void onContent(final Response response, ByteBuffer content) { if (LOG.isDebugEnabled()) LOG.debug("onContent called with response: {} and content: {}. Sending response content to client.", response, content); final ByteBuffer contentCopy = httpClient.getByteBufferPool().acquire(content.remaining(), true); BufferUtil.flipPutFlip(content, contentCopy); ByteBufferDataInfo dataInfo = new ByteBufferDataInfo(contentCopy, false); clientStream.data(dataInfo, new Callback() { @Override public void failed(Throwable x) { LOG.debug("failed: ", x); releaseBuffer(); response.abort(x); } @Override public void succeeded() { releaseBuffer(); } private void releaseBuffer() { httpClient.getByteBufferPool().release(contentCopy); } }); }
@Override public void consume(int delta) { super.consume(delta); serverDataInfo.consume(delta); } };
LOG.debug("Send content: {} on stream: {} lastContent={}", BufferUtil.toDetailString(content), stream, lastContent); stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS, content, lastContent ), callback); stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS, BufferUtil.EMPTY_BUFFER, lastContent), callback);