private List<Endpoint> rebuildEndpoints() {
        for (;;) {
            // Get the current endpoints before making a new endpoints list.
            final List<Endpoint> oldEndpoints = merged.get();
            final List<Endpoint> newEndpoints = new ArrayList<>();
            for (EndpointGroup endpointGroup : endpointGroups) {
                newEndpoints.addAll(endpointGroup.endpoints());
            }
            // Do not use ImmutableList because the empty ImmutableList uses a singleton instance.
            final List<Endpoint> endpoints = Collections.unmodifiableList(newEndpoints);
            if (merged.compareAndSet(oldEndpoints, endpoints)) {
                return endpoints;
            }
            // Changed by another thread while we were building a new one. Try again.
        }
    }
Constructs a new {@link CompositeEndpointGroup} that merges all the given {@code endpointGroups}.
core/src/main/java/com/linecorp/armeria/client/endpoint/CompositeEndpointGroup.java