/** * Dependency injection friendly convenience method for * {@link #getPipeline()} which returns the default pipeline of this * bootstrap as an ordered map. * <p> * Please note that this method is a convenience method that works only * when <b>1)</b> you create only one channel from this bootstrap (e.g. * one-time client-side or connectionless channel) or <b>2)</b> all handlers * in the pipeline is stateless. You have to use * {@link #setPipelineFactory(ChannelPipelineFactory)} if <b>1)</b> your * pipeline contains a stateful {@link ChannelHandler} and <b>2)</b> one or * more channels are going to be created by this bootstrap (e.g. server-side * channels). * * @throws IllegalStateException * if {@link #setPipelineFactory(ChannelPipelineFactory)} was * called by a user last time. */ public Map<String, ChannelHandler> getPipelineAsMap() { ChannelPipeline pipeline = this.pipeline; if (pipeline == null) { throw new IllegalStateException("pipelineFactory in use"); } return pipeline.toMap(); }
/** * Creates a new {@link ChannelPipeline} which contains the same entries * with the specified {@code pipeline}. Please note that only the names * and the references of the {@link ChannelHandler}s will be copied; a new * {@link ChannelHandler} instance will never be created. */ public static ChannelPipeline pipeline(ChannelPipeline pipeline) { ChannelPipeline newPipeline = pipeline(); for (Map.Entry<String, ChannelHandler> e: pipeline.toMap().entrySet()) { newPipeline.addLast(e.getKey(), e.getValue()); } return newPipeline; }
@Override public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception { final Channel childChannel = e.getChildChannel(); if (channelGroup != null) { channelGroup.add(childChannel); } ChannelPipeline childPipeline = childChannel.getPipeline(); if (pipelineFactory != null) { ChannelPipeline newChildPipeline = pipelineFactory.getPipeline(); for (Map.Entry<String, ChannelHandler> entry : newChildPipeline.toMap().entrySet()) { String key = entry.getKey(); ChannelHandler handler = entry.getValue(); childPipeline.addLast(key, handler); } } childPipeline.addLast("factory", new IoSessionFactoryChannelHandler(acceptor, null, acceptor.getIoSessionInitializer())); super.childChannelOpen(ctx, e); }
private void stopStreamAligned(final ChannelPipeline pipeline) { LOGGER.debug("Stopping pipeline"); for (ChannelHandler handler : pipeline.toMap().values()) { if (LOGGER.isDebugEnabled()) { Channel channel = pipeline.getChannel(); int id = (channel != null) ? channel.getId() : 0; LOGGER.debug(format("[id: 0x%08x] %s", id, handler)); } // note: removing this handler can trigger script completion // which in turn can re-attempt to stop this pipeline pipeline.remove(handler); } // non-empty pipeline required to avoid warnings if (pipeline.getContext(closeOnExceptionHandler) == null) { pipeline.addLast("closeOnException", closeOnExceptionHandler); } }