@Override public String toString() { return String.format("DATA bytes @%x available=%d consumed=%d on %s", dataInfo.hashCode(), dataInfo.available(), dataInfo.consumed(), getStream()); } }
@Override public String toString() { return String.format("DATA @%x available=%d consumed=%d close=%b", hashCode(), available(), consumed(), isClose()); } }
/** * <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); }
logger.debug("Consumed {} content bytes, queue size {}", dataInfo.consumed(), dataInfos.size()); dataInfo = null; buffer = 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); } } }