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 ServiceManager's removeInstance?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "what is the role of nacos ServiceManager's removeInstance". In daily operation, I believe many people have doubts about the role of nacos ServiceManager's removeInstance. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what is the role of nacos ServiceManager's removeInstance?" Next, please follow the editor to study!

Order

This paper mainly studies the removeInstance of nacos ServiceManager.

ServiceManager

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

@ Component@DependsOn ("nacosApplicationContext") public class ServiceManager implements RecordListener {/ * * Map * / private Map serviceMap = new ConcurrentHashMap (); private LinkedBlockingDeque toBeUpdatedServicesQueue = new LinkedBlockingDeque (1024 * 1024); private Synchronizer synchronizer = new ServiceStatusSynchronizer (); private final Lock lock = new ReentrantLock (); @ Resource (name = "consistencyDelegate") private ConsistencyService consistencyService; @ Autowired private SwitchDomain switchDomain; @ Autowired private DistroMapper distroMapper; @ Autowired private ServerListManager serverListManager; @ Autowired private PushService pushService Private final Object putServiceLock = new Object () /. Public void removeInstance (String namespaceId, String serviceName, boolean ephemeral, Instance... Ips) throws NacosException {Service service = getService (namespaceId, serviceName); removeInstance (namespaceId, serviceName, ephemeral, service, ips);} public void removeInstance (String namespaceId, String serviceName, boolean ephemeral, Service service, Instance... Ips) throws NacosException {String key = KeyBuilder.buildInstanceListKey (namespaceId, serviceName, ephemeral); List instanceList = substractIpAddresses (service, ephemeral, ips); Instances instances = new Instances (); instances.setInstanceList (instanceList); consistencyService.put (key, instances);} public List substractIpAddresses (Service service, boolean ephemeral, Instance...) Ips) throws NacosException {return updateIpAddresses (service, UtilsAndCommons.UPDATE_INSTANCE_ACTION_REMOVE, ephemeral, ips);} public List updateIpAddresses (Service service, String action, boolean ephemeral, Instance...) Ips) throws NacosException {Datum datum = consistencyService.get (KeyBuilder.buildInstanceListKey (service.getNamespaceId (), service.getName (), ephemeral)); Map oldInstanceMap = new HashMap (16); List currentIPs = service.allIPs (ephemeral); Map map = new ConcurrentHashMap (currentIPs.size ()); for (Instance instance: currentIPs) {map.put (instance.toIPAddr (), instance) } if (datum! = null) {oldInstanceMap = setValid (Instances) datum.value) .getInstanceList (), map);} / / use HashMap for deep copy: HashMap instanceMap = new HashMap (oldInstanceMap.size ()); instanceMap.putAll (oldInstanceMap) For (Instance instance: ips) {if (! service.getClusterMap (). ContainsKey (instance.getClusterName () {Cluster cluster = new Cluster (instance.getClusterName (), service); cluster.init (); service.getClusterMap () .put (instance.getClusterName (), cluster) Loggers.SRV_LOG.warn ("cluster: {} not found, ip: {}, will create new cluster with default configuration.", instance.getClusterName (), instance.toJSON ());} if (UtilsAndCommons.UPDATE_INSTANCE_ACTION_REMOVE.equals (action)) {instanceMap.remove (instance.getDatumKey ()) } else {instanceMap.put (instance.getDatumKey (), instance);}} if (instanceMap.size ()

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