ons for a parent channel b.setOption("localAddress", new {@link InetSocketAddress}(8080)); b.setOption("reuseAddress", true); // Options for its children b.setOption("child.tcpNoDelay", true); b.setOption("child.receiveBufferSize", 1048576); For the detailed list of available options, please refer to {@link ChannelConfig} and its sub-types.
Configuring a parent channel pipeline
It is rare to customize the pipeline of a parent channel because what it is supposed to do is very typical. However, you might want to add a handler to deal with some special needs such as degrading the process
UID from a
superuser to a normal user and changing the current VM security manager for better security. To support such a case, the {@link #setParentHandler(ChannelHandler) parentHandler} property isprovided.
Configuring a child channel pipeline
Every channel has its own {@link ChannelPipeline} and you can configure itin two ways. The recommended approach is to specify a {@link ChannelPipelineFactory} bycalling {@link #setPipelineFactory(ChannelPipelineFactory)}.
{@link ServerBootstrap} 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 ServerBootstrap} 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.
Applying different settings for different {@link Channel}s
{@link ServerBootstrap} is just a helper class. It neither allocates normanages any resources. What manages the resources is the {@link ChannelFactory} implementation you specified in the constructor of{@link ServerBootstrap}. Therefore, it is OK to create as many {@link ServerBootstrap} instances as you want with the same{@link ChannelFactory} to apply different settings for different{@link Channel}s.
@apiviz.landmark