in foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/DiscoveryManager.java [94:139]
private void onInstancesChanged(String registryName, String application, String serviceName,
List<? extends DiscoveryInstance> instances) {
Map<String, StatefulDiscoveryInstance> statefulInstances = allInstances.computeIfAbsent(application, key ->
new ConcurrentHashMapEx<>()).computeIfAbsent(serviceName, key -> new ConcurrentHashMapEx<>());
for (StatefulDiscoveryInstance statefulInstance : statefulInstances.values()) {
if (registryName == null || registryName.equals(statefulInstance.getRegistryName())) {
if (!instances.contains(statefulInstance)) {
statefulInstance.setPingTime(0);
statefulInstance.setHistoryStatus(HistoryStatus.HISTORY);
}
}
}
for (DiscoveryInstance instance : instances) {
StatefulDiscoveryInstance target = new StatefulDiscoveryInstance(instance);
StatefulDiscoveryInstance origin = statefulInstances.get(instance.getInstanceId());
if (origin == null) {
statefulInstances.put(instance.getInstanceId(), target);
continue;
}
target.setPingTime(origin.getPingTime());
target.setPingStatus(origin.getPingStatus());
target.setIsolateDuration(origin.getIsolateDuration());
target.setIsolationStatus(origin.getIsolationStatus());
statefulInstances.put(instance.getInstanceId(), target);
}
StringBuilder instanceInfo = new StringBuilder();
for (DiscoveryInstance instance : instances) {
instanceInfo.append("{")
.append(instance.getInstanceId()).append(",")
.append(instance.getStatus()).append(",")
.append(instance.getEndpoints()).append(",")
.append(instance.getRegistryName())
.append("}");
}
LOGGER.info("Applying new instance list for {}/{}/{}. Endpoints {}",
application, serviceName, instances.size(), instanceInfo);
rebuildVersionCache(application, serviceName);
for (InstanceChangeListener listener : this.instanceChangeListeners) {
listener.onInstancesChanged(registryName, application, serviceName, instances);
}
}