From b62bb4766357b8c70039765854db2471fc6fe96d Mon Sep 17 00:00:00 2001 From: David Pilato Date: Wed, 27 Jul 2016 11:19:08 +0200 Subject: [PATCH] Move registerCustomNameResolvers to Node class and rename it --- .../client/transport/TransportClient.java | 4 ++-- .../common/network/NetworkService.java | 16 ---------------- .../java/org/elasticsearch/node/Node.java | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index ae75babd1d2..dd385062432 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -64,7 +64,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers; +import static org.elasticsearch.node.Node.generateCustomNameResolvers; /** * The transport client allows to create a client that is not part of the cluster, but simply connects to one @@ -112,7 +112,7 @@ public abstract class TransportClient extends AbstractClient { final ThreadPool threadPool = new ThreadPool(settings); resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); final NetworkService networkService = new NetworkService(settings, - registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); + generateCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); try { final List> additionalSettings = new ArrayList<>(); diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java index 32d2a09a46b..2652f9ff646 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.plugins.DiscoveryPlugin; import java.io.IOException; import java.net.InetAddress; @@ -270,19 +269,4 @@ public class NetworkService extends AbstractComponent { } return InetAddress.getAllByName(host); } - - /** - * Register custom name resolver a DiscoveryPlugin might provide - * @param discoveryPlugins Discovery plugins - */ - public static List registerCustomNameResolvers(Settings settings, List discoveryPlugins) { - List customNameResolvers = new ArrayList<>(); - for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) { - NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings); - if (customNameResolver != null) { - customNameResolvers.add(customNameResolver); - } - } - return customNameResolvers; - } } diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index fd7b51f06ba..af45147a146 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -135,8 +135,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers; - /** * A node represent a node within a cluster (cluster.name). The {@link #client()} can be used * in order to use a {@link Client} to perform actions/operations against the cluster. @@ -298,7 +296,7 @@ public class Node implements Closeable { final SettingsModule settingsModule = new SettingsModule(this.settings, additionalSettings, additionalSettingsFilter); resourcesToClose.add(resourceWatcherService); final NetworkService networkService = new NetworkService(settings, - registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); + generateCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); clusterService.add(scriptModule.getScriptService()); resourcesToClose.add(clusterService); @@ -725,4 +723,19 @@ public class Node implements Closeable { BigArrays createBigArrays(Settings settings, CircuitBreakerService circuitBreakerService) { return new BigArrays(settings, circuitBreakerService); } + + /** + * Generate Custom Name Resolvers list based on a Discovery Plugins list + * @param discoveryPlugins Discovery plugins list + */ + public static List generateCustomNameResolvers(Settings settings, List discoveryPlugins) { + List customNameResolvers = new ArrayList<>(); + for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) { + NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings); + if (customNameResolver != null) { + customNameResolvers.add(customNameResolver); + } + } + return customNameResolvers; + } }