@Override protected int remaining(DataInfo item) { return item.available(); }
@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); }
/** * @return a {@link ByteBuffer} with the content of this {@link DataInfo} * @param consume whether to consume the content */ public ByteBuffer asByteBuffer(boolean consume) { ByteBuffer buffer = allocate(available()); if (consume) consumeInto(buffer); else readInto(buffer); buffer.flip(); return buffer; }
@Override public void onData(final Stream stream, final DataInfo dataInfo) { logger.debug("S -> P {} on {}", dataInfo, stream); if (replyInfo != null) { if (dataInfo.isClose()) replyInfo.getHeaders().put("content-length", String.valueOf(dataInfo.available())); reply(stream); } data(stream, dataInfo); }
size = dataInfo.available(); if (size > windowSize) size = windowSize;
@Override public void succeeded() { bufferPool.release(buffer); IStream stream = getStream(); dataInfo.consume(size); flowControlStrategy.updateWindow(StandardSession.this, stream, -size); if (dataInfo.available() > 0) { // We have written a frame out of this DataInfo, but there is more to write. // We need to keep the correct ordering of frames, to avoid that another // DataInfo for the same stream is written before this one is finished. flush(this, flusher.prepend(this)); } else { super.succeeded(); stream.updateCloseState(dataInfo.isClose(), true); if (stream.isClosed()) removeStream(stream); } }