In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "detailed introduction of watch mechanism of zk". In daily operation, I believe many people have doubts about the detailed introduction of watch mechanism of zk. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "detailed introduction of watch mechanism of zk"! Next, please follow the editor to study!
Watch Mechanism in WatchManager
Watcher function: the API for notification status and event type defines process method and Event interface, including KeeperState (zk status on notification), and EventType specifies the event type.
Void process (WatchedEvent event); callback function implements this function, indicating that the event executes behavior-related logic
WatchedEvent
Describe the state change event detected by zk, respond to the change, what happened, the current state of zk, the path to the event znode
/ * * convert attributes to WatcherEvent for network transmission
* Convert WatchedEvent to type that can be sent over network
, /
Public WatcherEvent getWrapper () {
Return new WatcherEvent (eventType.getIntValue (), keeperState.getIntValue (), path)
}
WatcherEvent
It is an interface that implements Record, and the attribute has type,state,path, which is the encapsulation of network transmission.
ClientWatchManager interface
Get the watcher collection that needs to be notified according to event, and the implementation class is ZKWatcherManager
Attributes:
Private final Map dataWatches = new HashMap (); / / data listening collection private final Map existWatches = new HashMap (); / / existing listening collection private final Map childWatches = new HashMap (); / / child node listening collection private boolean disableAutoWatchReset;ZKWatchManager (boolean disableAutoWatchReset) {this.disableAutoWatchReset = disableAutoWatchReset;} protected volatile Watcher defaultWatcher
Delete the set changes of three types of watcher nodes
Involves listening types enum WatcherType {Children (1), Data (2), Any (3);}
Implementation method of materialize ()
WatcherSetEventPair
It is a wrapper class that binds event and the corresponding watches collection to be triggered.
Private static class WatcherSetEventPair {private final Set watchers; private final WatchedEvent event; public WatcherSetEventPair (Set watchers, WatchedEvent event) {this.watchers = watchers; this.event = event;}}
UML class diagram
Watcher mechanism is introduced into zk to realize notification function.
Zk allows the client to register a monitor with the server, and specifies that when the event triggers the monitoring, the server sends the monitoring event notification to the client, so that the client can complete the logical operation.
Properties:
Once, watcher is triggered, and zk removes it from the corresponding storage, registers once, triggers once.
Client serial execution, client watcher callback is a serial process
Lightweight: contains event type notification status, node path
At this point, the study of "detailed introduction to the watch mechanism of zk" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.