Practical netty (4) Parent-Child channel relationship: Relationship between channels and Pipelines

Source: Internet
Author: User
Practical netty (4) Parent-Child channel relationship: Relationship between channels and Pipelines
  • Author: Liu Da-poechant (Zhong Chao)
  • Email: zhongchao. USTC # gmail.com (#-> @)
  • Blog: blog.csdn.net/poechant
  • Weibo: weibo.com/lauginhom
  • Date: June 10Th, 2012

(The following section is written after the completion of this article.) We call the parent channel as the parent channel, the Child channel as the subchannel, the channel as the channel, and the channelpipeline as the pipeline. Only one such purpose is to shorten the title in the csdn blog... Of course, the English names are still used in the text below, because the Chinese names mentioned above are what I did when I started the title after writing this article.

1. Core netty concepts 3: parent channel and child Channels

After a serverbootstrap is started, a parent channel is created, which is used to accept connections. Each connection is allocated to a child channel for subsequent processing.

The options of parent channel and child channels are set by serverbootstrap. The configurable key and value types are as follows:

  • "localAddress",InetSocketAddress
  • "keepAlive",boolean
  • "reuseAddress",boolean
  • "soLinger",int
  • "tcpNoDelay",boolean
  • "receiveBufferSize",int
  • "sendBufferSize",int
  • "trafficClass",int

Sample Code:

bootstrap.setOption("reuseAddress", true);bootstrap.setOption("localAddress", new InetSocketAddress(port));bootstrap.setOption("child.tcpNoDelay", true);bootstrap.setOption("child.receiveBufferSize", 1048576);

For more information, see the csdn blog blog.csdn.net/poechant,weibo.com/lauginhom.

2. core concepts of netty 4: Channel and channelpipeline

Let's take a look at the official document of netty:

For each new channel, a new pipeline must be created and attached to thechannel. Once attached, the coupling between the channel and the pipelineis permanent; the channel cannot attach another pipeline to it nor detachthe current pipeline from it.

Each channel has a corresponding channelpipe and must have one. For a bootstrap, you must specify how channelpipeline is generated:

bootstrap.setPipelineFactory(ChannelPipelineFactory factory);

.ChannelPipelineFactoryIsInterface, So you needimplementsFor example:

bootstrap.setPipelineFactory(new ChannelPipelineFactory() {    ChannelPipeline p = Channels.pipeline();    p.addLast("handler", new PoechantProxyHandler());});

This is an implementation method for anonymous classes. You should also understand real-name classes. The official saying tells us that you can only attach one channelpipeline to a channel, and once attach, you cannot detach it. This is why setpipelinefactory is created, it defines the rule for binding channelpipeline to your channel (including what kind of channelpipeline ).

-

For more information, see the csdn blog blog.csdn.net/poechant,weibo.com/lauginhom.

-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.