In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the example analysis of Netty distributed monitoring read events, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
Let's go back to AbstractUnsafe's register0 () method:
Private void register0 (ChannelPromise promise) {try {/ / omit the code / / do the actual registration doRegister (); neverRegistered = false; registered = true; / / trigger event pipeline.invokeHandlerAddedIfNeeded (); safeSetSuccess (promise); / / trigger registration success event pipeline.fireChannelRegistered () If (isActive ()) {if (firstRegistration) {/ / propagate active events (4) pipeline.fireChannelActive ();} else if (config (). IsAutoRead ()) {beginRead ();} catch (Throwable t) {/ / omit code}}
After doRegister () completes the actual registration, it will go to the judgment of if (isActive ()). Because the link has been completed at this time, this is true, and the default judgment condition if (firstRegistration) is also true, so here it will go to pipeline.fireChannelActive ().
We will analyze pipeline in detail in the next chapter. All we need to know here is that it will eventually flow to the beginRead () method of AbstractUnsafe.
Follow to the beginRead () method:
Public final void beginRead () {assertEventLoop (); if (! isActive ()) {return;} try {doBeginRead ();} catch (final Exception e) {/ / Code ellipsis}}
We are also familiar with this piece of code, because we have also analyzed this step by analyzing NioServerSocketChannel.
Let's continue to follow doBeginRead ():
Protected void doBeginRead () throws Exception {/ / get selectionKey final SelectionKey selectionKey = this.selectionKey; if (! selectionKey.isValid ()) {return;} readPending = true; / / get the event final int interestOps = selectionKey.interestOps () / / determine whether if ((interestOps & readInterestOp) = = 0) is not monitored for any event. {/ / this condition holds / / registers the previous accept event. ReadInterest represents the meaning of a new connection selectionKey.interestOps (interestOps | readInterestOp);}}
I believe you will be familiar with this code, because we have come here after the registration of channel on our server.
Because we initialize the read event when we create the NioSocketChannel, and selectionKey is the key returned by channel when registering, the selectionKey.interestOps (interestOps | readInterestOp) step registers the read event of the current channel into the selector
After registration, NioEventLoop can poll the current channel for read events
The above is all the contents of the article "sample Analysis of Netty distributed Monitoring read events". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.