负载均衡数据记录LoadBalancerStats
public class LoadBalancerStats {
String name;
//zone相关信息,默认用不到
volatile Map<String, ZoneStats> zoneStatsMap = new ConcurrentHashMap<String, ZoneStats>();
volatile Map<String, List<? extends Server>> upServerListZoneMap = new ConcurrentHashMap<String, List<? extends Server>>();
//动态配置,连接失败上限
private volatile DynamicIntProperty connectionFailureThreshold;
//动态配置,熔断时间因子
private volatile DynamicIntProperty circuitTrippedTimeoutFactor;
//动态配置,最大熔断时间
private volatile DynamicIntProperty maxCircuitTrippedTimeout;
//动态配置,每个Server负载均衡统计数据过期时间配置
private static final DynamicIntProperty SERVERSTATS_EXPIRE_MINUTES =
DynamicPropertyFactory.getInstance().getIntProperty("niws.loadbalancer.serverStats.expire.minutes", 30);
//每个Server的负载均衡统计数据
private final LoadingCache<Server, ServerStats> serverStatsCache =
CacheBuilder.newBuilder()
.expireAfterAccess(SERVERSTATS_EXPIRE_MINUTES.get(), TimeUnit.MINUTES)
.removalListener(new RemovalListener<Server, ServerStats>() {
@Override
public void onRemoval(RemovalNotification<Server, ServerStats> notification) {
notification.getValue().close();
}
})
.build(
new CacheLoader<Server, ServerStats>() {
public ServerStats load(Server server) {
return createServerStats(server);
}
});
}
服务实例列表更新机制实现的接口ServerListUpdater
public interface ServerListUpdater {
//定义了更新服务实例列表的操作doUpdate
public interface UpdateAction {
void doUpdate();
}
//开始调度更新服务实例列表,可以看到这里以UpdateAction为传参
void start(UpdateAction updateAction);
//停止更新服务实例列表
void stop();
//上次服务实例列表更新时间
String getLastUpdate();
//上次服务实例列表更新时间间隔
long getDurationSinceLastUpdateMs();
//已经错过几轮更新
int getNumberMissedCycles();
//使用线程池大小
int getCoreThreads();
}