@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { if (state == DEMANDING) { requestDemand(); } }
@Override protected void requestDemand() { bodyRequested(ctx); super.requestDemand(); } };
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // If we subscribed before the channel was active, then our read would have been ignored. if (state == DEMANDING) { requestDemand(); } ctx.fireChannelActive(); }
private void flushBuffer() { while (!buffer.isEmpty() && (outstandingDemand > 0 || outstandingDemand == Long.MAX_VALUE)) { publishMessage(buffer.remove()); } if (buffer.isEmpty()) { if (outstandingDemand > 0) { if (state == BUFFERING) { state = DEMANDING; } // otherwise we're draining requestDemand(); } else if (state == BUFFERING) { state = IDLE; } } }
private void receivedDemand(long demand) { switch (state) { case BUFFERING: case DRAINING: if (addDemand(demand)) { flushBuffer(); } break; case DEMANDING: addDemand(demand); break; case IDLE: if (addDemand(demand)) { // Important to change state to demanding before doing a read, in case we get a synchronous // read back. state = DEMANDING; requestDemand(); } break; default: } }