上一篇中已经给出h2o.ai的整体介绍以及其核心项目h2o.ai/h2o-3的源码目录,本篇给出h2o启动流程的源码分析。启动过程的时序图如下:
下面挑选时序图中的关键接口进行详细功能介绍:
1. 【步骤3】 registerCoreExtensions()加载扩展类
利用Java ServiceLoader的原理加载当前项目目录中所有/resources/META-INF/目录下water.AbstractH2OExtension文件中定义的服务类:(这些服务类都继承了AbstractH2OExtension)。汇总了下加载了扩展类如下:
Project | File | Content |
---|---|---|
h2o-core | water.AbstractH2OExtension | water.FailedNodeWatchdogExtension |
h2o-ext-krbstandalone | water.AbstractH2OExtension | hex.security.KerberosExtension |
h2o-ext-xgboost | water.AbstractH2OExtension | hex.tree.xgboost.XGBoostExtension |
h2o-grpc | water.AbstractH2OExtension | ai.h2o.api.GrpcExtension |
*2.【步骤5,6】 startLocalNode()启动当前节点和当前cloud并将当前节点作为当前cloud的唯一成员*
/** Initializes the local node and the local cloud with itself as the only member. */
private static void startLocalNode() {
// Figure self out; this is surprisingly hard
NetworkInit.initializeNetworkSockets();
// Do not forget to put SELF into the static configuration (to simulate
// proper multicast behavior)
if( !ARGS.client && STATIC_H2OS != null && !STATIC_H2OS.contains(SELF)) {
Log.warn("Flatfile configuration does not include self: " + SELF+ " but contains " + STATIC_H2OS);
STATIC_H2OS.add(SELF);
}
......
}
其中调用【步骤6】的 initializeNetworkSockets() 初始化启动一个jettyServer加载Web API(默认为ip:host为localhost:54321)