Nacos-NacosNaingService初期化
Nacos-起動 NacosWatch#startはNacosServiceManagerを管理してNacosServiceManagerを取得すると述べています.
NacosServiceManager#getNamingService
空の場合はNamingServiceを作成します
NacosServiceManager#buildNamingService
ロック保証はnamingServiceが1つしかありません
最終的にNamingFactory#createNamingServiceを呼び出してNamingServiceオブジェクトを作成します.
NamingFactory#createNamingService
反射的にcomを作成する.alibaba.nacos.client.naming.NacosNamingServiceオブジェクト.
NacosNamingService#init
主に初期化namespace、シーケンス化、レジストリ・センター・サービス・アドレス、WebRootContextコンテキスト、キャッシュ・パス、ログ名、EventDispatcher、NamingProxy、BeatReactor、HostReactorです.EventDispatcherは、サービス傍受に関する処理を担当します.NamingProxyはNacosサービスとの通信を担当しています.例えば、サービス登録、サービスキャンセル登録、ドキドキなどです.BeatReactorは心拍数の検出を担当します.HostReactorは、サービス情報の取得、更新、保存を担当します.
NacosServiceManager#getNamingService
空の場合はNamingServiceを作成します
public NamingService getNamingService(Properties properties) {
// , NamingService
if (Objects.isNull(this.namingService)) {
buildNamingService(properties);
}
// namingService
return namingService;
}
NacosServiceManager#buildNamingService
ロック保証はnamingServiceが1つしかありません
private NamingService buildNamingService(Properties properties) {
if (Objects.isNull(namingService)) {
// namingService
synchronized (NacosServiceManager.class) {
if (Objects.isNull(namingService)) {
namingService = createNewNamingService(properties);
}
}
}
return namingService;
}
最終的にNamingFactory#createNamingServiceを呼び出してNamingServiceオブジェクトを作成します.
private NamingService createNewNamingService(Properties properties) {
try {
return createNamingService(properties);
}
catch (NacosException e) {
throw new RuntimeException(e);
}
}
// NacosFactory
public static NamingService createNamingService(Properties properties) throws NacosException {
return NamingFactory.createNamingService(properties);
}
NamingFactory#createNamingService
反射的にcomを作成する.alibaba.nacos.client.naming.NacosNamingServiceオブジェクト.
public static NamingService createNamingService(String serverList) throws NacosException {
try {
Class> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService");
Constructor constructor = driverImplClass.getConstructor(String.class);
NamingService vendorImpl = (NamingService) constructor.newInstance(serverList);
return vendorImpl;
} catch (Throwable e) {
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
}
}
NacosNamingService#init
主に初期化namespace、シーケンス化、レジストリ・センター・サービス・アドレス、WebRootContextコンテキスト、キャッシュ・パス、ログ名、EventDispatcher、NamingProxy、BeatReactor、HostReactorです.EventDispatcherは、サービス傍受に関する処理を担当します.NamingProxyはNacosサービスとの通信を担当しています.例えば、サービス登録、サービスキャンセル登録、ドキドキなどです.BeatReactorは心拍数の検出を担当します.HostReactorは、サービス情報の取得、更新、保存を担当します.
private void init(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);
// namespace public
this.namespace = InitUtils.initNamespaceForNaming(properties);
//
InitUtils.initSerialization();
// ,
initServerAddr(properties);
// WebRootContext
InitUtils.initWebRootContext();
// System.getProperty("user.home") + "/nacos/naming/" + namespace
initCacheDir();
// naming.log
initLogName(properties);
// EventDispatcher
this.eventDispatcher = new EventDispatcher();
// NamingProxy
this.serverProxy = new NamingProxy(this.namespace, this.endpoint, this.serverList, properties);
// BeatReactor
this.beatReactor = new BeatReactor(this.serverProxy, initClientBeatThreadCount(properties));
// HostReactor
this.hostReactor = new HostReactor(this.eventDispatcher, this.serverProxy, beatReactor, this.cacheDir,
isLoadCacheAtStart(properties), initPollingThreadCount(properties));
}