protected void updatePeerEurekaNodes(List<String> newPeerUrls) {
        if (newPeerUrls.isEmpty()) {
            logger.warn("The replica size seems to be empty. Check the route 53 DNS Registry");
            return;
        }

        Set<String> toShutdown = new HashSet<>(peerEurekaNodeUrls);
        toShutdown.removeAll(newPeerUrls);
        Set<String> toAdd = new HashSet<>(newPeerUrls);
        toAdd.removeAll(peerEurekaNodeUrls);

        if (toShutdown.isEmpty() && toAdd.isEmpty()) { // No change
            return;
        }

        // Remove peers no long available
        List<PeerEurekaNode> newNodeList = new ArrayList<>(peerEurekaNodes);

        if (!toShutdown.isEmpty()) {
            logger.info("Removing no longer available peer nodes {}", toShutdown);
            int i = 0;
            while (i < newNodeList.size()) {
                PeerEurekaNode eurekaNode = newNodeList.get(i);
                if (toShutdown.contains(eurekaNode.getServiceUrl())) {
                    newNodeList.remove(i);
                    eurekaNode.shutDown();
                } else {
                    i++;
                }
            }
        }

        // Add new peers
        if (!toAdd.isEmpty()) {
            logger.info("Adding new peer nodes {}", toAdd);
            for (String peerUrl : toAdd) {
                newNodeList.add(createPeerEurekaNode(peerUrl));
            }
        }

        this.peerEurekaNodes = newNodeList;
        this.peerEurekaNodeUrls = new HashSet<>(newPeerUrls);
    }
protected void updatePeerEurekaNodes ( List < String > newPeerUrls ) { if ( newPeerUrls . isEmpty ( ) ) { logger . warn ( "The replica size seems to be empty. Check the route 53 DNS Registry" ) ; return ; } Set < String > toShutdown = new HashSet < > ( peerEurekaNodeUrls ) ; toShutdown . removeAll ( newPeerUrls ) ; Set < String > toAdd = new HashSet < > ( newPeerUrls ) ; toAdd . removeAll ( peerEurekaNodeUrls ) ; if ( toShutdown . isEmpty ( ) && toAdd . isEmpty ( ) ) { return ; } List < PeerEurekaNode > newNodeList = new ArrayList < > ( peerEurekaNodes ) ; if ( ! toShutdown . isEmpty ( ) ) { logger . info ( "Removing no longer available peer nodes {}" , toShutdown ) ; int i = 0 ; while ( i < newNodeList . size ( ) ) { PeerEurekaNode eurekaNode = newNodeList . get ( i ) ; if ( toShutdown . contains ( eurekaNode . getServiceUrl ( ) ) ) { newNodeList . remove ( i ) ; eurekaNode . shutDown ( ) ; } else { i ++ ; } } } if ( ! toAdd . isEmpty ( ) ) { logger . info ( "Adding new peer nodes {}" , toAdd ) ; for ( String peerUrl : toAdd ) { newNodeList . add ( createPeerEurekaNode ( peerUrl ) ) ; } } this . peerEurekaNodes = newNodeList ; this . peerEurekaNodeUrls = new HashSet < > ( newPeerUrls ) ; }
Given new set of replica URLs, destroy {@link PeerEurekaNode}s no longer available, and
create new ones.

@param newPeerUrls peer node URLs; this collection should have local node's URL filtered out