@Override protected void onContentConsumed(DataInfo dataInfo) { dataInfo.consume(dataInfo.length()); } }
/** * <p>Consumes the given number of bytes from this {@link DataInfo}.</p> * * @param delta the number of bytes consumed */ public void consume(int delta) { if (delta < 0) throw new IllegalArgumentException(); int read = length() - available(); int newConsumed = consumed() + delta; // if (newConsumed > read) // throw new IllegalStateException("Consuming without reading: consumed " + newConsumed + " but only read " + read); consumed.addAndGet(delta); }
@Override public void completed(Void context) { dataInfo.consume(dataInfo.length()); logger.debug("P -> C {} from {} to {}", dataInfo, stream, clientStream); }
@Override public void run() { logger.debug("HTTP > {} bytes of content", dataInfo.length()); if (state == State.HEADERS) { updateState(State.HEADERS_COMPLETE); handle(); } updateState(State.CONTENT); handle(); } });
@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()); } }
dataInfo.consume(dataInfo.length()); logger.debug("Consumed {} content bytes, queue size {}", dataInfo.consumed(), dataInfos.size()); dataInfo = null;
@Override public void onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta) { // This is the algorithm for flow control. // This method may be called multiple times with delta=1, but we only send a window // update when the whole dataInfo has been consumed. // Other policies may be to send window updates when consumed() is greater than // a certain threshold, etc. but for now the policy is not pluggable for simplicity. // Note that the frequency of window updates depends on the read buffer, that // should not be too smaller than the window size to avoid frequent window updates. // Therefore, a pluggable policy should be able to modify the read buffer capacity. int length = dataInfo.length(); if (dataInfo.consumed() == length && !stream.isClosed() && length > 0) { WindowUpdateFrame windowUpdateFrame = new WindowUpdateFrame(session.getVersion(), stream.getId(), length); session.control(stream, windowUpdateFrame, 0, TimeUnit.MILLISECONDS, Callback.Adapter.INSTANCE); } } }
LOG.debug("HTTP > {} bytes of content", dataInfo.length());