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 configure 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 child channel has its own {@link ChannelPipeline} and you canconfigure it in two ways. {@linkplain #setPipeline(ChannelPipeline) The first approach} is to usethe default pipeline property and let the bootstrap to clone it for each new child channel:
ServerBootstrap 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());
{@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:
ServerBootstrap b = ...; b.setPipelineFactory(new MyPipelineFactory()); public class MyPipelineFactory implements {@link ChannelPipelineFactory} {// Create a new pipeline for a new child channel and configure it here ... }
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 to apply different settingsfor different {@link Channel}s. TODO: Show how to shut down a service.
@author The Netty Project (netty-dev@lists.jboss.org)
@author Trustin Lee (tlee@redhat.com)
@version $Rev: 536 $, $Date: 2008-11-28 20:18:21 +0900 (Fri, 28 Nov 2008) $
@apiviz.landmark