Elasticsearch整个大致流程:从Elastcisearch类的main方法入口,然后调用了BootStrap类的中的init方法,该方法会对环境和配置进行一系列的检测和初始化,其中最为主要的两个方法就是setup方法和start方法,setup的方法通过ModulesBuilder采用gucie进行不同模块的注入,start方法进行启动(keepAliveThread和node中的模块),如下图所示:
elasticsearch启动流程图
1. org.elasticsearch.bootstrap.Elasticsearch类:
一个私有的构造函数:private Elasticsearch() {}
一个main方法:
public static void main(String[] args) throws StartupError {
try {
Bootstrap.init(args);
} catch (Throwable t) {
//format exceptions to the console in a special way
// to avoid 2MB stacktraces from guice, etc.
throw new StartupError(t);
}
}
close的方法:
static void close(String[] args) {
Bootstrap.stop();
}
2. org.elasticsearch.bootstrap.Bootstrap类:
从Elasticsearch类中的main函数看到调用了Bootstrap的init方法,es的启动初始化主要在这个类中完成(代码比较多,不一一贴出):
该类中主要有三个实例:
private volatile Node node;
private final CountDownLatch keepAliveLatch = new CountDownLatch(1);
private final Thread keepAliveThread;
构造函数:
Bootstrap() {
keepAliveThread = new Thread(new Runnable() {
@Override
public void run() {
try {
keepAliveLatch.await();
} catch (InterruptedException e) {
// bail out
}
}
}, "elasticsearch[keepAlive/" +