Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of nacos's DistroMapper?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the role of DistroMapper of nacos". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Order

This paper mainly studies the DistroMapper of nacos.

ServerChangeListener

Nacos-1.1.3/naming/src/main/java/com/alibaba/nacos/naming/cluster/servers/ServerChangeListener.java

Public interface ServerChangeListener {/ * * If member list changed, this method is invoked. * * @ param servers servers after change * / void onChangeServerList (List servers); / * * If reachable member list changed, this method is invoked. * * @ param healthyServer reachable servers after change * / void onChangeHealthyServerList (List healthyServer);}

ServerChangeListener defines onChangeServerList and onChangeHealthyServerList methods.

DistroMapper

Nacos-1.1.3/naming/src/main/java/com/alibaba/nacos/naming/core/DistroMapper.java

@ Component ("distroMapper") public class DistroMapper implements ServerChangeListener {private List healthyList = new ArrayList (); public List getHealthyList () {return healthyList;} @ Autowired private SwitchDomain switchDomain; @ Autowired private ServerListManager serverListManager; / * * init server list * / @ PostConstruct public void init () {serverListManager.listen (this) } public boolean responsible (Cluster cluster, Instance instance) {return switchDomain.isHealthCheckEnabled (cluster.getServiceName ()) & &! cluster.getHealthCheckTask (). IsCancelled () & & responsible (cluster.getServiceName ()) & & cluster.contains (instance);} public boolean responsible (String serviceName) {if (! switchDomain.isDistroEnabled () | | SystemUtils.STANDALONE_MODE) {return true } if (CollectionUtils.isEmpty (healthyList)) {/ / means distro config is not ready yet return false;} int index = healthyList.indexOf (NetUtils.localServer ()); int lastIndex = healthyList.lastIndexOf (NetUtils.localServer ()); if (lastIndex)

< 0 || index < 0) { return true; } int target = distroHash(serviceName) % healthyList.size(); return target >

= index & & target

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report