@Override public void onContent(Response response, ByteBuffer content) { int remaining = content.remaining(); byte[] bytes = new byte[remaining]; content.get(bytes); LOG.debug("Queuing {}/{} bytes", bytes, bytes.length); queue.offer(bytes); long newLength = length.addAndGet(remaining); while (newLength >= maxBufferSize) { LOG.debug("Queued bytes limit {}/{} exceeded, waiting", newLength, maxBufferSize); if (!await()) break; newLength = length.get(); LOG.debug("Queued bytes limit {}/{} exceeded, woken up", newLength, maxBufferSize); } }
@Override public void onContent(Response response, ByteBuffer content) { int remaining = content.remaining(); byte[] bytes = new byte[remaining]; content.get(bytes); LOG.debug("Queuing {}/{} bytes", bytes, bytes.length); queue.offer(bytes); long newLength = length.addAndGet(remaining); while (newLength >= maxBufferSize) { LOG.debug("Queued bytes limit {}/{} exceeded, waiting", newLength, maxBufferSize); if (!await()) break; newLength = length.get(); LOG.debug("Queued bytes limit {}/{} exceeded, woken up", newLength, maxBufferSize); } }