public synchronized <T extends ChannelHandler> T get(Class<T> handlerType) { ChannelHandlerContext ctx = getContext(handlerType); if (ctx == null) { return null; } else { @SuppressWarnings("unchecked") T handler = (T) ctx.getHandler(); return handler; } }
private static void callAfterRemove(ChannelHandlerContext ctx) { if (!(ctx.getHandler() instanceof LifeCycleAwareChannelHandler)) { return; } LifeCycleAwareChannelHandler h = (LifeCycleAwareChannelHandler) ctx.getHandler(); try { h.afterRemove(ctx); } catch (Throwable t) { throw new ChannelHandlerLifeCycleException( h.getClass().getName() + ".afterRemove() has thrown an exception.", t); } }
private static void callBeforeAdd(ChannelHandlerContext ctx) { if (!(ctx.getHandler() instanceof LifeCycleAwareChannelHandler)) { return; } LifeCycleAwareChannelHandler h = (LifeCycleAwareChannelHandler) ctx.getHandler(); try { h.beforeAdd(ctx); } catch (Throwable t) { throw new ChannelHandlerLifeCycleException( h.getClass().getName() + ".beforeAdd() has thrown an exception; not adding.", t); } }
private static void callBeforeRemove(ChannelHandlerContext ctx) { if (!(ctx.getHandler() instanceof LifeCycleAwareChannelHandler)) { return; } LifeCycleAwareChannelHandler h = (LifeCycleAwareChannelHandler) ctx.getHandler(); try { h.beforeRemove(ctx); } catch (Throwable t) { throw new ChannelHandlerLifeCycleException( h.getClass().getName() + ".beforeRemove() has thrown an exception; not removing.", t); } }
private void callAfterAdd(ChannelHandlerContext ctx) { if (!(ctx.getHandler() instanceof LifeCycleAwareChannelHandler)) { return; } LifeCycleAwareChannelHandler h = (LifeCycleAwareChannelHandler) ctx.getHandler(); try { h.afterAdd(ctx); } catch (Throwable t) { boolean removed = false; try { remove((DefaultChannelHandlerContext) ctx); removed = true; } catch (Throwable t2) { if (logger.isWarnEnabled()) { logger.warn("Failed to remove a handler: " + ctx.getName(), t2); } } if (removed) { throw new ChannelHandlerLifeCycleException( h.getClass().getName() + ".afterAdd() has thrown an exception; removed.", t); } else { throw new ChannelHandlerLifeCycleException( h.getClass().getName() + ".afterAdd() has thrown an exception; also failed to remove.", t); } } }
if (ctx.getHandler() instanceof ExecutionHandler) {
if (ctx.getHandler() instanceof ExecutionHandler) {
@Override public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception { LOGGER.debug("Control Channel Opened"); Channel childChannel = e.getChildChannel(); channelGroup.add(childChannel); final ControlServerHandler controller = (ControlServerHandler) childChannel.getPipeline().getContext("control.handler").getHandler(); // Add the controller to our list controlHandlers.add(controller); // And remove it when the channel is closed. controller.getChannelClosedFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { controlHandlers.remove(controller); } }); }
@Override public void operationComplete(ChannelFuture connectFuture) throws Exception { if (connectFuture.isSuccess()) { transport = connectFuture.getChannel(); transport.getConfig().setBufferFactory(httpConnectConfig.getBufferFactory()); ChannelPipeline pipeline = transport.getPipeline(); ChannelHandlerContext ctx = pipeline.getContext(HttpClientChannelSource.class); HttpClientChannelSource channelSource = (HttpClientChannelSource) ctx.getHandler(); if (!httpConnectChannel.isBound()) { ChannelAddress httpLocalAddress = httpRemoteAddress; httpConnectChannel.setLocalAddress(httpLocalAddress); httpConnectChannel.setBound(); fireChannelBound(httpConnectChannel, httpLocalAddress); } channelSource.setHttpChannel(httpConnectChannel); httpConnectChannel.setRemoteAddress(httpRemoteAddress); httpConnectChannel.setConnected(); httpConnectFuture.setSuccess(); fireChannelConnected(httpConnectChannel, httpRemoteAddress); } else { httpConnectFuture.setFailure(connectFuture.getCause()); } } });
HttpResponseDecoder httpDecoder = (HttpResponseDecoder) httpDecoderCtx.getHandler(); httpDecoder.replace(format("%s.noop", httpDecoderCtx.getName()), NOOP_HANDLER);