{@link ClientBootstrap} 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 ClientBootstrap} 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.
|
|