Netty3 Source Analysis-Channel

Source: Internet
Author: User

Netty3 Source Analysis-Channel
What is a channel? Represents a connection point (Nexus) for a network socket. the content of a channel abstraction includes:1) Current channel status, whether open, whether binding, etc.;2) The configuration parameter information of the channel, such as the size of the socket buffer;3) The IO operation supported by the channel;4) Handle the IO events associated with this channel and the channelpipeline of the request.
all IO operations in Netty are asynchronous, that is, the execution of an IO call does not block until the operation is complete, and then immediately returns a Channelfuture object, whichthe Channelfuture object notifies us at some point of the result of the IO Operation Execution (success, failure, or cancellation).
Channel is hierarchical (related to transport layer implementation), such as a listening socket serversocketchannel creates a connection socket corresponding channel Socketchannel after receiving a connection request. Then the Listener channel entity is returned when GetParent () is called on a connection channel.
Each channel also has a Interestops property, similar to the select Mechanism, which informs the kernel that the channel is interested in an event that has two bit identifier components:Op_read: If this identity is set and the data on the peer arrives, then a read operation is performed, otherwise even if the data is not read (read hanging), a bit of edge-triggered flavor. Op_write: If this bit is set, the write request does not send the data to the peer, but is appended to the queue, and if the identity is clear, the write request is flush from the queue. Op_read_write: Only write requests will be hoisted (suspend). Op_none: Only read requests will be hoisted. such as in the interfacesetreadableThis method can be set/cleared by Op_read:suspends or resumes the read operation of the I/O thread asynchronously. The equivalent code is:int interestops = Getinterestops ();if (readable) {Setinterestops (Interestops | Op_read);} else {//clear the flagsetinterestops (Interestops & ~op_read); }
Note that it is not asset/clear Op_read to suspend or resume write operations, op_write This identification is only used to tell whether a suspended write request exceeds a certain threshold value. For example, a low water/high water mark can be set through niosocketconfig in a NIO socket.
The source code for this interface is as follows: Public  InterfaceChannel extendscomparable<channel> {
      int   Op_none= 0;      int   Op_read= 1;      int   Op_write= 4;      int   Op_read_write =  Op_read |  Op_write;
Integer getId ();
ChannelFactory getfactory ();
Channel getParent ();
channelconfig GetConfig ();
channelpipeline getpipeline ();
      Boolean IsOpen ();
      Boolean Isbound ();
      Boolean isconnected ();
socketaddress getlocaladdress ();
socketaddress getremoteaddress ();
channelfuture Write (Object message);
channelfuture Write (Object message, socketaddress remoteaddress);
channelfuture bind (socketaddress localaddress);
channelfuture Connect (socketaddress remoteaddress);
channelfuture Disconnect ();
channelfuture unbind ();
channelfuture close ();
channelfuture getclosefuture ();
      int getinterestops ();
      Boolean isreadable ();
      Boolean iswritable ();
channelfuture setinterestops ( int interestops);
channelfuture setreadable ( Boolean readable);
Object getattachment ();
      void setattachment (Object attachment);}

Netty3 Source Analysis-Channel

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.