private void data(final Stream stream, final DataInfo dataInfo) { clientStream.data(dataInfo, getTimeout(), TimeUnit.MILLISECONDS, new Handler<Void>() { @Override public void completed(Void context) { dataInfo.consume(dataInfo.length()); logger.debug("P -> C {} from {} to {}", dataInfo, stream, clientStream); } @Override public void failed(Void context, Throwable x) { logger.debug(x); rst(clientStream); } }); } }
private void flush(Stream receiverStream, DataInfoCallback dataInfoCallback) { if (LOG.isDebugEnabled()) LOG.debug("P -> S {} on {}", dataInfoCallback.dataInfo, receiverStream); receiverStream.data(dataInfoCallback.dataInfo, dataInfoCallback); //TODO: timeout??? }
private void flush(Stream serverStream, DataInfoHandler dataInfoHandler) { logger.debug("P -> S {} on {}", dataInfoHandler.dataInfo, serverStream); serverStream.data(dataInfoHandler.dataInfo, getTimeout(), TimeUnit.MILLISECONDS, dataInfoHandler); }
@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); }
private void data(final Stream stream, final DataInfo serverDataInfo) { final ByteBufferDataInfo clientDataInfo = new ByteBufferDataInfo(serverDataInfo.asByteBuffer(false), serverDataInfo.isClose()) { @Override public void consume(int delta) { super.consume(delta); serverDataInfo.consume(delta); } }; receiverStream.data(clientDataInfo, new Callback() //TODO: timeout??? { @Override public void succeeded() { if (LOG.isDebugEnabled()) LOG.debug("P -> C {} from {} to {}", clientDataInfo, stream, receiverStream); } @Override public void failed(Throwable x) { LOG.debug(x); rst(receiverStream); } }); } }
@Override public void flush(long maxIdleTime) throws IOException { try { Buffer content = getContentBuffer(); while (content != null) { DataInfo dataInfo = toDataInfo(content, closed); logger.debug("HTTP < {} bytes of content", dataInfo.length()); stream.data(dataInfo).get(maxIdleTime, TimeUnit.MILLISECONDS); content.clear(); _bypass = false; content = getContentBuffer(); } } catch (TimeoutException x) { stream.getSession().goAway(); throw new EOFException("write timeout"); } catch (InterruptedException x) { throw new InterruptedIOException(); } catch (ExecutionException x) { throw new IOException(x.getCause()); } }
@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 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); } }); }
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);