@Override public int consumeContent(final ContentDecoder decoder) throws IOException { setInputMode(); int totalRead = 0; int bytesRead; while ((bytesRead = decoder.read(this.buffer)) != -1) { if (bytesRead == 0) { if (!this.buffer.hasRemaining()) { expand(); } else { break; } } else { totalRead += bytesRead; } } if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true; } return totalRead; }
/** * Helper method to mark as producer completed. The normal behavior only set the boolean param to true only when * decoder is completed. However in some cases it is needed to intentionally close chunk stream and mark as * producer completed in order to prevent consumer further waiting on end of stream condition. * * @param decoder decoder instance to consume input */ public void forceProducerComplete(final ContentDecoder decoder) { //no need to mark EoS if decoder is completed if (!decoder.isCompleted()) { lock.lock(); try { producerCompleted = true; //there can be edge cases where consumer already waiting on read condition ( buffer is empty ) //in that case marking producer complete is not enough need to clear the read condition //consumer is waiting on readCondition.signalAll(); //let consumer complete = clear consumerIoControl.suspendOutput(); if (consumerIoControl != null) { consumerIoControl.requestOutput(); } } finally { lock.unlock(); } } }
@Override public int read(final ByteBuffer dst) throws IOException { return decoder.read(dst); }
@Override protected void onContentReceived(final ContentDecoder decoder, final IOControl ioctrl) throws IOException { Asserts.notNull(this.fileChannel, "File channel"); final long transferred; if (decoder instanceof FileContentDecoder) { transferred = ((FileContentDecoder) decoder).transfer(this.fileChannel, this.fileStreamIdx, Integer.MAX_VALUE); } else { transferred = this.fileChannel.transferFrom(new ContentDecoderChannel(decoder), this.fileStreamIdx, Integer.MAX_VALUE); } if (transferred > 0) { this.fileStreamIdx += transferred; this.downloadedBytes += transferred; } if (decoder.isCompleted()) { this.fileChannel.close(); } }
@Override public int read(final ByteBuffer dst) throws IOException { return decoder.read(dst); }
@Override public int consumeContent(final ContentDecoder decoder) throws IOException { setInputMode(); int totalRead = 0; int bytesRead; while ((bytesRead = decoder.read(this.buffer)) != -1) { if (bytesRead == 0) { if (!this.buffer.hasRemaining()) { expand(); } else { break; } } else { totalRead += bytesRead; } } if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true; } return totalRead; }
/** * Produce the content in to the pipe. * @param conn the connection * @param decoder content decoder * * @throws java.io.IOException if an error occurs * @return number of bytes read */ public int read(NHttpServerConnection conn, ContentDecoder decoder) throws IOException { if (pipe == null) { throw new IllegalStateException("A Pipe must be connected before calling read"); } if (entityEnclosing) { int bytes = pipe.produce(decoder); if (decoder.isCompleted()) { conn.getContext().setAttribute(PassThroughConstants.REQ_FROM_CLIENT_READ_END_TIME,System.currentTimeMillis()); sourceConfiguration.getMetrics(). notifyReceivedMessageSize(conn.getMetrics().getReceivedBytesCount()); // Update connection state SourceContext.updateState(conn, ProtocolState.REQUEST_DONE); // Suspend client input conn.suspendInput(); } return bytes; } else { throw new IllegalStateException("Only Entity Enclosing Requests " + "can read content in to the pipe"); } }
@Override public void consumeContent( final ContentDecoder decoder, final IOControl ioctrl) throws IOException { int lastRead; do { this.buffer.clear(); lastRead = decoder.read(this.buffer); } while (lastRead > 0); }
int bytesRead; if (waitingBuffer != null && this.buffer.position() == 0) { while ((bytesRead = decoder.read(this.waitingBuffer)) > 0) { totalRead += bytesRead; while ((bytesRead = decoder.read(this.buffer)) > 0) { totalRead += bytesRead; if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true;
if (decoder.isCompleted()) {
@Override public void consumeContent( final ContentDecoder decoder, final IOControl ioctrl) throws IOException { int lastRead; do { this.buffer.clear(); lastRead = decoder.read(this.buffer); } while (lastRead > 0); }
@Override protected void onContentReceived(ContentDecoder decoder, IOControl ioctrl) throws IOException { log.debug("complete {}", decoder.isCompleted()); ByteBuffer buffer = ByteBuffer.allocate(1024); decoder.read(buffer); log.debug("content {} received {},{}", new Object[]{buffer, decoder, ioctrl}); // TODO : currently it always triggers pull request on /, should this be configurable? DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.PULL, "/"); handler.handle(null, distributionRequest); log.info("distribution request to agent {} sent ({} {})", new Object[]{ handler, distributionRequest.getRequestType(), distributionRequest.getPaths()}); super.onContentReceived(decoder, ioctrl); }
@Override public void inputReady( final NHttpClientConnection conn, final ContentDecoder decoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getResponseState() == MessageState.BODY_STREAM, "Unexpected request state %s", state.getResponseState()); final HttpAsyncClientExchangeHandler handler = getHandler(conn); Asserts.notNull(handler, "Client exchange handler"); handler.consumeContent(decoder, conn); if (decoder.isCompleted()) { processResponse(conn, state, handler); } }
int totalRead = 0; int bytesRead; while ((bytesRead = decoder.read(this.buffer)) > 0) { totalRead += bytesRead; if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true;
@Override public void inputReady( final NHttpClientConnection conn, final ContentDecoder decoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getResponseState() == MessageState.BODY_STREAM, "Unexpected request state %s", state.getResponseState()); final HttpAsyncClientExchangeHandler handler = getHandler(conn); Asserts.notNull(handler, "Client exchange handler"); handler.consumeContent(decoder, conn); if (decoder.isCompleted()) { processResponse(conn, state, handler); } }
int totalRead = 0; int bytesRead; while ((bytesRead = decoder.read(this.buffer)) > 0) { totalRead += bytesRead; if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true;
@Override public void inputReady( final NHttpServerConnection conn, final ContentDecoder decoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getRequestState() == MessageState.BODY_STREAM, "Unexpected request state %s", state.getRequestState()); final Incoming incoming = state.getIncoming(); Asserts.notNull(incoming, "Incoming request"); final HttpAsyncRequestConsumer<?> consumer = incoming.getConsumer(); consumer.consumeContent(decoder, conn); if (decoder.isCompleted()) { completeRequest(incoming, conn, state); } }
int bytesRead=0; try{ bytesRead = decoder.read(buffer.getByteBuffer()); } catch(MalformedChunkCodingException ignore) { if (buffer.position() > 0 || decoder.isCompleted()) { if (consumerIoControl != null) { consumerIoControl.requestOutput(); if (decoder.isCompleted()) { producerCompleted = true;
@Override public void inputReady( final NHttpServerConnection conn, final ContentDecoder decoder) throws IOException, HttpException { final State state = getState(conn); Asserts.notNull(state, "Connection state"); Asserts.check(state.getRequestState() == MessageState.BODY_STREAM, "Unexpected request state %s", state.getRequestState()); final Incoming incoming = state.getIncoming(); Asserts.notNull(incoming, "Incoming request"); final HttpAsyncRequestConsumer<?> consumer = incoming.getConsumer(); consumer.consumeContent(decoder, conn); if (decoder.isCompleted()) { completeRequest(incoming, conn, state); } }
if (decoder.isCompleted()) { conn.getContext().setAttribute(PassThroughConstants.RES_FROM_BACKEND_READ_END_TIME,System.currentTimeMillis()); conn.getContext().setAttribute(PassThroughConstants.RES_ARRIVAL_TIME,System.currentTimeMillis());