Search in sources :

Example 1 with LifecycleListener

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);
}
Also used : TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) MockNode(org.elasticsearch.node.MockNode) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) Plugin(org.elasticsearch.plugins.Plugin)

Aggregations

LifecycleListener (org.elasticsearch.common.component.LifecycleListener)1 MockNode (org.elasticsearch.node.MockNode)1 Plugin (org.elasticsearch.plugins.Plugin)1 MockTransportService (org.elasticsearch.test.transport.MockTransportService)1 TransportService (org.elasticsearch.transport.TransportService)1