- LongPollingService
public LongPollingService() {
allSubs = new ConcurrentLinkedQueue<ClientLongPolling>();
ConfigExecutor.scheduleLongPolling(new StatTask(), 0L, 10L, TimeUnit.SECONDS);
// Register LocalDataChangeEvent to NotifyCenter.
NotifyCenter.registerToPublisher(LocalDataChangeEvent.class, NotifyCenter.ringBufferSize);
// Register A Subscriber to subscribe LocalDataChangeEvent.
NotifyCenter.registerSubscriber(new Subscriber() {
@Override
public void onEvent(Event event) {
if (isFixedPolling()) {
// Ignore.
} else {
if (event instanceof LocalDataChangeEvent) {
LocalDataChangeEvent evt = (LocalDataChangeEvent) event;
ConfigExecutor.executeLongPolling(new DataChangeTask(evt.groupKey, evt.isBeta, evt.betaIps));
}
}
}
@Override
public Class<? extends Event> subscribeType() {
return LocalDataChangeEvent.class;
}
});
}
构造中分为定时轮训和LocalDataChangeEvent两种方式.
ConfigController. publishConfig -> NotifyCenter.publishEvent()->
发布了时间后 1. 同步其他集群节点 2. 出发了LocalDataChangeEvent,开启任务,提前generatel响应了长轮训的的http请求。 返回结果,相当于http主动的推送了 过来.
- ConfigController
LongPollingService ClientWorker ConfigService ConfigExecutor
详情看fox老师的笔记.
Nacos配置中心源码分析.jpg
网友评论