搜索引擎|ZenNodeDiscovery

上篇博客就写了nodeDiscovery服务的引用,这里就详细分解一下ZenNodeDiscovery。
搜索引擎|ZenNodeDiscovery
文章图片

AbstractLifecycleComponent

@SuppressWarnings({"unchecked"}) @Override public T start() { if (!lifecycle.canMoveToStarted()) { return (T) this; } for (LifecycleListener listener : listeners) { listener.beforeStart(); } doStart(); lifecycle.moveToStarted(); for (LifecycleListener listener : listeners) { listener.afterStart(); } return (T) this; }protected abstract void doStart();

【搜索引擎|ZenNodeDiscovery】ZenDiscovery
@Override protected void doStart() { nodesFD.setLocalNode(clusterService.localNode()); joinThreadControl.start(); pingService.start(); this.nodeJoinController = new NodeJoinController(clusterService, routingService, discoverySettings, settings); // start the join thread from a cluster state update. See {@link JoinThreadControl} for details. clusterService.submitStateUpdateTask("initial_join", new ClusterStateUpdateTask() {@Override public boolean runOnlyOnMaster() { return false; }@Override public ClusterState execute(ClusterState currentState) throws Exception { // do the join on a different thread, the DiscoveryService waits for 30s anyhow till it is discovered joinThreadControl.startNewThreadIfNotRunning(); return currentState; }@Override public void onFailure(String source, @org.elasticsearch.common.Nullable Throwable t) { logger.warn("failed to start initial join process", t); } }); }

    推荐阅读