void delayedStart() { // If we won the race against onSubscribe, we need to tell it // know not to delay, because we won't be called again. Subscription subscription = deferredSubscription.getAndSet(DO_NOT_DELAY); if (subscription != null) { super.onSubscribe(subscription); } }
@Override public void operationComplete(ChannelFuture channelFuture) throws Exception { complete(); } });
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { complete(); }
@Override protected void requestDemand() { bodyRequested(ctx); super.requestDemand(); } };
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { if (state == DEMANDING) { requestDemand(); } }
private void provideChannelContext(ChannelHandlerContext ctx) { switch(state) { case NO_SUBSCRIBER_OR_CONTEXT: verifyRegisteredWithRightExecutor(ctx); this.ctx = ctx; // It's set, we don't have a subscriber state = NO_SUBSCRIBER; break; case NO_CONTEXT: verifyRegisteredWithRightExecutor(ctx); this.ctx = ctx; state = IDLE; subscriber.onSubscribe(new ChannelSubscription()); break; default: // Ignore, this could be invoked twice by both handlerAdded and channelRegistered. } }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { cancel(); }
/** * Override for custom error handling. By default, it closes the channel. * * @param error The error to handle. */ protected void error(Throwable error) { doClose(); }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { if (state == INACTIVE) { state = RUNNING; maybeRequestMore(); } ctx.fireChannelActive(); }
private boolean addDemand(long demand) { if (demand <= 0) { illegalDemand(); return false; } else { if (outstandingDemand < Long.MAX_VALUE) { outstandingDemand += demand; if (outstandingDemand < 0) { outstandingDemand = Long.MAX_VALUE; } } return true; } }
@Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { provideChannelContext(ctx); ctx.fireChannelRegistered(); }
@Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { verifyRegisteredWithRightExecutor(ctx); ctx.fireChannelRegistered(); }
private void provideSubscription() { switch (state) { case NO_SUBSCRIPTION_OR_CONTEXT: state = NO_CONTEXT; break; case NO_SUBSCRIPTION: maybeStart(); break; case CANCELLED: subscription.cancel(); break; } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cancel(); ctx.fireExceptionCaught(cause); }
@Override public void onSubscribe(Subscription subscription) { if (!deferredSubscription.compareAndSet(null, subscription)) { super.onSubscribe(subscription); } }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { complete(); }
/** * Override for custom completion handling. By default, it closes the channel. */ protected void complete() { doClose(); }
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { maybeRequestMore(); ctx.fireChannelWritabilityChanged(); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { cancel(); ctx.fireChannelInactive(); }