voidrestOfInit(IClientConfig clientConfig){
boolean primeConnection = this.isEnablePrimingConnections();// turn this off to avoid duplicated asynchronous priming done in BaseLoadBalancer.setServerList()
this.setEnablePrimingConnections(false);enableAndInitLearnNewServersFeature();// serverListUpdater.start(updateAction);updateListOfServers();if(primeConnection && this.getPrimeConnections()!= null){
this.getPrimeConnections().primeConnections(getReachableServers());}
this.setEnablePrimingConnections(primeConnection);
LOGGER.info("DynamicServerListLoadBalancer for client {} initialized: {}", clientConfig.getClientName(), this.toString());}/**
* Feature that lets us add new instances (from AMIs) to the list of
* existing servers that the LB will use Call this method if you want this
* feature enabled
*/
public voidenableAndInitLearnNewServersFeature(){
LOGGER.info("Using serverListUpdater {}", serverListUpdater.getClass().getSimpleName());
serverListUpdater.start(updateAction);// 开始调用updateAction}
UpdateAction
protected final ServerListUpdater.UpdateAction updateAction = new ServerListUpdater.UpdateAction(){
@Override
public voiddoUpdate(){updateListOfServers();}};
updateListOfServers
public voidupdateListOfServers(){
List<T> servers = new ArrayList<T>();if(serverListImpl != null){// NacosServerList
servers = serverListImpl.getUpdatedListOfServers();
LOGGER.debug("List of Servers for {} obtained from Discovery client: {}",getIdentifier(), servers);if(filter != null){
servers = filter.getFilteredListOfServers(servers);
LOGGER.debug("Filtered List of Servers for {} obtained from Discovery client: {}",getIdentifier(), servers);}}updateAllServerList(servers);}