{@link ConnectionlessBootstrap} b = ...;b.setPipelineFactory(new MyPipelineFactory()); public class MyPipelineFactory implements {@link ChannelPipelineFactory} {public {@link ChannelPipeline} getPipeline() throws Exception {// Create and configure a new pipeline for a new channel. {@link ChannelPipeline} p = {@link Channels}.pipeline(); p.addLast("encoder", new EncodingHandler()); p.addLast("decoder", new DecodingHandler()); p.addLast("logic", new LogicHandler()); return p; } }
The alternative approach, which works only in a certain situation, is to use the default pipeline and let the bootstrap to shallow-copy the default pipeline for each new channel:
{@link ConnectionlessBootstrap} b = ...;{@link ChannelPipeline} p = b.getPipeline();// Add handlers to the default pipeline. p.addLast("encoder", new EncodingHandler()); p.addLast("decoder", new DecodingHandler()); p.addLast("logic", new LogicHandler());Please note 'shallow-copy' here means that the added {@link ChannelHandler}s are not cloned but only their references are added to the new pipeline. Therefore, you cannot use this approach if you are going to open more than one {@link Channel}s or run a server that accepts incoming connections to create its child channels.
{@linkplain #setPipeline(ChannelPipeline) The first approach} is to usethe default pipeline and let the bootstrap to shallow-copy the default pipeline for each new channel:
ConnectionlessBootstrap b = ...; {@link ChannelPipeline} p = b.getPipeline();// Add handlers to the pipeline. p.addLast("encoder", new EncodingHandler()); p.addLast("decoder", new DecodingHandler()); p.addLast("logic", new LogicHandler());Please note 'shallow-copy' here means that the added {@link ChannelHandler}s are not cloned but only their references are added to the new pipeline. Therefore, you have to choose the second approach if you are going to open more than one {@link Channel} whose {@link ChannelPipeline} contains any{@link ChannelHandler} whose {@link ChannelPipelineCoverage} is {@code "one"}.
{@linkplain #setPipelineFactory(ChannelPipelineFactory) The second approach}is to specify a {@link ChannelPipelineFactory} by yourself and have fullcontrol over how a new pipeline is created. This approach is more complex:
ConnectionlessBootstrap b = ...; b.setPipelineFactory(new MyPipelineFactory()); public class MyPipelineFactory implements {@link ChannelPipelineFactory} {// Create a new pipeline for a new channel and configure it here ... }
|
|
|
|