Move registerCustomNameResolvers to Node class and rename it

This commit is contained in:
David Pilato 2016-07-27 11:19:08 +02:00
parent 1c03d0bb2a
commit b62bb47663
3 changed files with 18 additions and 21 deletions

View File

@ -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<Setting<?>> additionalSettings = new ArrayList<>();

View File

@ -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<CustomNameResolver> registerCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
List<CustomNameResolver> customNameResolvers = new ArrayList<>();
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
customNameResolvers.add(customNameResolver);
}
}
return customNameResolvers;
}
}

View File

@ -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 (<tt>cluster.name</tt>). 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<NetworkService.CustomNameResolver> generateCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
List<NetworkService.CustomNameResolver> customNameResolvers = new ArrayList<>();
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
customNameResolvers.add(customNameResolver);
}
}
return customNameResolvers;
}
}