static void registerForClose(boolean shouldCleanupOnClose, String name, NettyContext context) { if (!shouldCleanupOnClose) return; context.onClose(() -> context.removeHandler(name)); }
static void autoAddHttpExtractor(NettyContext c, String name, ChannelHandler handler){ if (handler instanceof ByteToMessageDecoder || handler instanceof ByteToMessageCodec || handler instanceof CombinedChannelDuplexHandler) { String extractorName = name+"$extractor"; if(c.channel().pipeline().context(extractorName) != null){ return; } c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR); if(NettyContext.isPersistent(c.channel())){ c.onClose(() -> c.removeHandler(extractorName)); } } }
/** * Assign a {@link Runnable} to be invoked when writes have become idle for the given * timeout. This replaces any previously set idle callback. * * @param idleTimeout the idle timeout * @param onWriteIdle the idle timeout handler * * @return {@literal this} */ default NettyOutbound onWriteIdle(long idleTimeout, Runnable onWriteIdle) { context().removeHandler(NettyPipeline.OnChannelWriteIdle); context().addHandlerFirst(NettyPipeline.OnChannelWriteIdle, new ReactorNetty.OutboundIdleStateHandler(idleTimeout, onWriteIdle)); return this; }
/** * Assign a {@link Runnable} to be invoked when reads have become idle for the given * timeout. This replaces any previously set idle callback. * * @param idleTimeout the idle timeout * @param onReadIdle the idle timeout handler * * @return {@literal this} */ default NettyInbound onReadIdle(long idleTimeout, Runnable onReadIdle) { context().removeHandler(NettyPipeline.OnChannelReadIdle); context().addHandlerFirst(NettyPipeline.OnChannelReadIdle, new ReactorNetty.InboundIdleStateHandler(idleTimeout, onReadIdle)); return this; }