如何获取服务列表:用于获取服务位置,
1、(RibbonClientConfiguration)return new ZoneAwareLoadBalancer<>(config, rule, ping, serverList,
serverListFilter, serverListUpdater);
2、(ZoneAwareLoadBalancer)public ZoneAwareLoadBalancer(IClientConfig clientConfig, IRule rule,
IPing ping, ServerList
ServerListUpdater serverListUpdater) {
super(clientConfig, rule, ping, serverList, filter, serverListUpdater);
}
3、(DynamicServerListLoadBalancer)public DynamicServerListLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping,
restOfInit(clientConfig);
}
4、(DynamicServerListLoadBalancer)void restOfInit(IClientConfig clientConfig) {
enableAndInitLearnNewServersFeature();
}
5、(DynamicServerListLoadBalancer)public void enableAndInitLearnNewServersFeature() {
serverListUpdater(初始化的时候加入).start(updateAction(直接new的));
-->updateAction:
protected final ServerListUpdater.UpdateAction updateAction = new ServerListUpdater.UpdateAction() {
@Override
public void doUpdate() {
updateListOfServers();
}
};
}
6、(DynamicServerListLoadBalancer)public void updateListOfServers() {
List
if (serverListImpl != null) {
//获取服务列表
servers = (ConfigurationBasedServerList)serverListImpl.getUpdatedListOfServers();
-->
if (filter != null) {
servers = filter.getFilteredListOfServers(servers);
}
}
//更新服务列表
updateAllServerList(servers);
}
7、(DynamicServerListLoadBalancer)protected void updateAllServerList(List
// other threads might be doing this - in which case, we pass
if (serverListUpdateInProgress.compareAndSet(false, true)) {
try {
for (T s : ls) {
s.setAlive(true); // set so that clients can start using these
// servers right away instead
// of having to wait out the ping cycle.
}
setServersList(ls);
super.forceQuickPing();
} finally {
serverListUpdateInProgress.set(false);
}
}
}
9、(PollingServerListUpdater)public synchronized void start(final UpdateAction updateAction) {
public void run() {
try {
updateAction.doUpdate();
lastUpdated = System.currentTimeMillis();
} catch (Exception e) {
//定时获取
scheduledFuture = getRefreshExecutor().scheduleWithFixedDelay(
wrapperRunnable,
initialDelayMs,
refreshIntervalMs,
TimeUnit.MILLISECONDS
);
} else {
logger.info("Already active, no-op");
}
}