private void updateLocalClusterInstances()

in src/main/java/org/apache/sling/discovery/impl/support/MetricReporter.java [294:313]


    private void updateLocalClusterInstances(TopologyView oldViewOrNull, TopologyView newView) {
        final ClusterView newLocalClusterView = newView.getLocalInstance().getClusterView();
        localClusterInstances.set(newLocalClusterView.getInstances().size());

        if (oldViewOrNull == null) {
            localClusterJoins.addAndGet(newLocalClusterView.getInstances().size());
        } else {
            final ClusterView oldLocalClusterView = oldViewOrNull.getLocalInstance().getClusterView();
            final InstancesDiff diff = new InstancesDiff(oldLocalClusterView, newLocalClusterView);
            final Collection<InstanceDescription> added = diff.added().get();
            final Collection<InstanceDescription> removed = diff.removed().get();

            if (added.size() > 0) {
                localClusterJoins.addAndGet(added.size());
            }
            if (removed.size() > 0) {
                localClusterLeaves.addAndGet(removed.size());
            }
        }
    }