@Override protected void doRegister() throws Exception { if (peer != null) { state = 2; peer.remoteAddress = parent().localAddress(); peer.state = 2; // Always call peer.eventLoop().execute() even if peer.eventLoop().inEventLoop() is true. // This ensures that if both channels are on the same event loop, the peer's channelActive // event is triggered *after* this channel's channelRegistered event, so that this channel's // pipeline is fully initialized by ChannelInitializer before any channelRead events. peer.eventLoop().execute(new Runnable() { @Override public void run() { peer.pipeline().fireChannelActive(); peer.connectPromise.setSuccess(); } }); } ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); }
@Override protected void doRegister() throws Exception { if (peer != null) { state = State.CONNECTED; peer.remoteAddress = parent() == null ? null : parent().localAddress(); peer.state = State.CONNECTED; // Always call peer.eventLoop().execute() even if peer.eventLoop().inEventLoop() is true. // This ensures that if both channels are on the same event loop, the peer's channelActive // event is triggered *after* this channel's channelRegistered event, so that this channel's // pipeline is fully initialized by ChannelInitializer before any channelRead events. peer.eventLoop().execute(new Runnable() { @Override public void run() { peer.pipeline().fireChannelActive(); peer.connectPromise.setSuccess(); } }); } ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); }
public NettyQueuesMetricsInitializer(final MetricFactory metricFactory, final EventLoopGroup elg) { if (metricFactory == null || elg == null) { return; } int index = 0; for (final EventExecutor eventExecutor : elg) { if (eventExecutor instanceof SingleThreadEventExecutor) { final SingleThreadEventExecutor singleExecutor = (SingleThreadEventExecutor) eventExecutor; metricFactory.registerGauge("GruffaloEventLoopGroup", "EventLoop-" + index, new Gauge<Integer>() { @Override public Integer getValue() { return singleExecutor.pendingTasks(); } }); index++; } } }
@Override protected void doDeregister() throws Exception { if (isOpen()) { unsafe().close(unsafe().voidPromise()); } ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); }
public static void registerQueueGauges(final MetricFactory factory, final EventLoopGroup elg, final String componentName) { if (factory == null || elg == null) { return; } int index = 0; for (final EventExecutor eventExecutor : elg) { if (eventExecutor instanceof SingleThreadEventExecutor) { final SingleThreadEventExecutor singleExecutor = (SingleThreadEventExecutor) eventExecutor; factory.registerGauge("EventLoopGroup-" + componentName, "EventLoop-" + index, singleExecutor::pendingTasks); index++; } } }
@Override protected void doDeregister() throws Exception { // Just remove the shutdownHook as this Channel may be closed later or registered to another EventLoop ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); }
@Override protected void doRegister() throws Exception { ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); }
@Override protected void doDeregister() throws Exception { ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); }