private void compareInstances(final List<Instance> previousInstances, final List<Instance> currentInstances, final ChangedEventListener listener) {
        Set<Instance> addedInstances = currentInstances.stream()
                .filter(item -> !previousInstances.contains(item))
                .collect(Collectors.toSet());
        if (!addedInstances.isEmpty()) {
            for (Instance instance: addedInstances) {
                listener.onEvent(instance.getServiceName(), buildUpstreamJsonFromInstance(instance), ChangedEventListener.Event.ADDED);
            }
        }

        Set<Instance> deletedInstances = previousInstances.stream()
                .filter(item -> !currentInstances.contains(item))
                .collect(Collectors.toSet());
        if (!deletedInstances.isEmpty()) {
            for (Instance instance: deletedInstances) {
                instance.setHealthy(false);
                listener.onEvent(instance.getServiceName(), buildUpstreamJsonFromInstance(instance), ChangedEventListener.Event.DELETED);
            }
        }

        Set<Instance> updatedInstances = currentInstances.stream()
                .filter(currentInstance -> previousInstances.stream()
                        .anyMatch(previousInstance -> currentInstance.getInstanceId().equals(previousInstance.getInstanceId()) && !currentInstance.equals(previousInstance)))
                .collect(Collectors.toSet());
        if (!updatedInstances.isEmpty()) {
            for (Instance instance: updatedInstances) {
                listener.onEvent(instance.getServiceName(), buildUpstreamJsonFromInstance(instance), ChangedEventListener.Event.UPDATED);
            }
        }
    }
The type Nacos instance register repository.
shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java