use of org.elasticsearch.common.component.LifecycleListener in project crate by crate.
the class InternalTestCluster method buildNode.
/**
* builds a new node
*
* @param nodeId node ordinal
* @param settings the settings to use
* @param reuseExisting if a node with the same name is already part of {@link #nodes}, no new node will be built and
* the method will return the existing one
* @param onTransportServiceStarted callback to run when transport service is started
*/
private synchronized NodeAndClient buildNode(int nodeId, Settings settings, boolean reuseExisting, Runnable onTransportServiceStarted) {
assert Thread.holdsLock(this);
ensureOpen();
Collection<Class<? extends Plugin>> plugins = getPlugins();
String name = settings.get("node.name");
final NodeAndClient nodeAndClient = nodes.get(name);
if (reuseExisting && nodeAndClient != null) {
// reusing an existing node implies its transport service already started
onTransportServiceStarted.run();
return nodeAndClient;
}
assert reuseExisting == true || nodeAndClient == null : "node name [" + name + "] already exists but not allowed to use it";
MockNode node = new MockNode(settings, plugins, nodeConfigurationSource.nodeConfigPath(nodeId), forbidPrivateIndexSettings);
node.injector().getInstance(TransportService.class).addLifecycleListener(new LifecycleListener() {
@Override
public void afterStart() {
onTransportServiceStarted.run();
}
});
return new NodeAndClient(name, node, settings, nodeId);
}
Aggregations