Add comment clarifying property setting in client

This commit adds a comment clarifying why we do not catch a security
exception in the pre-built transport client.
This commit is contained in:
Jason Tedor 2016-12-23 18:14:36 -05:00
parent d5c18bf5c9
commit 5185a9734d
1 changed files with 24 additions and 18 deletions

View File

@ -37,13 +37,12 @@ import java.util.Collections;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* A builder to create an instance of {@link TransportClient} * A builder to create an instance of {@link TransportClient}. This class pre-installs the
* This class pre-installs the
* {@link Netty4Plugin}, * {@link Netty4Plugin},
* {@link ReindexPlugin}, * {@link ReindexPlugin},
* {@link PercolatorPlugin}, * {@link PercolatorPlugin},
* and {@link MustachePlugin} * and {@link MustachePlugin}
* for the client. These plugins are all elasticsearch core modules required. * plugins for the client. These plugins are all the required modules for Elasticsearch.
*/ */
@SuppressWarnings({"unchecked","varargs"}) @SuppressWarnings({"unchecked","varargs"})
public class PreBuiltTransportClient extends TransportClient { public class PreBuiltTransportClient extends TransportClient {
@ -63,6 +62,8 @@ public class PreBuiltTransportClient extends TransportClient {
final String noUnsafe = System.getProperty(noUnsafeKey); final String noUnsafe = System.getProperty(noUnsafeKey);
if (noUnsafe == null) { if (noUnsafe == null) {
// disable Netty from using unsafe // disable Netty from using unsafe
// while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or
// the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here
System.setProperty(noUnsafeKey, Boolean.toString(true)); System.setProperty(noUnsafeKey, Boolean.toString(true));
} }
@ -70,34 +71,36 @@ public class PreBuiltTransportClient extends TransportClient {
final String noKeySetOptimization = System.getProperty(noKeySetOptimizationKey); final String noKeySetOptimization = System.getProperty(noKeySetOptimizationKey);
if (noKeySetOptimization == null) { if (noKeySetOptimization == null) {
// disable Netty from replacing the selector key set // disable Netty from replacing the selector key set
// while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or
// the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here
System.setProperty(noKeySetOptimizationKey, Boolean.toString(true)); System.setProperty(noKeySetOptimizationKey, Boolean.toString(true));
} }
} }
private static final Collection<Class<? extends Plugin>> PRE_INSTALLED_PLUGINS = private static final Collection<Class<? extends Plugin>> PRE_INSTALLED_PLUGINS =
Collections.unmodifiableList( Collections.unmodifiableList(
Arrays.asList( Arrays.asList(
Netty4Plugin.class, Netty4Plugin.class,
ReindexPlugin.class, ReindexPlugin.class,
PercolatorPlugin.class, PercolatorPlugin.class,
MustachePlugin.class)); MustachePlugin.class));
/** /**
* Creates a new transport client with pre-installed plugins. * Creates a new transport client with pre-installed plugins.
*
* @param settings the settings passed to this transport client * @param settings the settings passed to this transport client
* @param plugins an optional array of additional plugins to run with this client * @param plugins an optional array of additional plugins to run with this client
*/ */
@SafeVarargs @SafeVarargs
public PreBuiltTransportClient(Settings settings, Class<? extends Plugin>... plugins) { public PreBuiltTransportClient(Settings settings, Class<? extends Plugin>... plugins) {
this(settings, Arrays.asList(plugins)); this(settings, Arrays.asList(plugins));
} }
/** /**
* Creates a new transport client with pre-installed plugins. * Creates a new transport client with pre-installed plugins.
*
* @param settings the settings passed to this transport client * @param settings the settings passed to this transport client
* @param plugins a collection of additional plugins to run with this client * @param plugins a collection of additional plugins to run with this client
*/ */
public PreBuiltTransportClient(Settings settings, Collection<Class<? extends Plugin>> plugins) { public PreBuiltTransportClient(Settings settings, Collection<Class<? extends Plugin>> plugins) {
this(settings, plugins, null); this(settings, plugins, null);
@ -105,12 +108,15 @@ public class PreBuiltTransportClient extends TransportClient {
/** /**
* Creates a new transport client with pre-installed plugins. * Creates a new transport client with pre-installed plugins.
* @param settings the settings passed to this transport client *
* @param plugins a collection of additional plugins to run with this client * @param settings the settings passed to this transport client
* @param hostFailureListener a failure listener that is invoked if a node is disconnected. This can be <code>null</code> * @param plugins a collection of additional plugins to run with this client
* @param hostFailureListener a failure listener that is invoked if a node is disconnected; this can be <code>null</code>
*/ */
public PreBuiltTransportClient(Settings settings, Collection<Class<? extends Plugin>> plugins, public PreBuiltTransportClient(
HostFailureListener hostFailureListener) { Settings settings,
Collection<Class<? extends Plugin>> plugins,
HostFailureListener hostFailureListener) {
super(settings, Settings.EMPTY, addPlugins(plugins, PRE_INSTALLED_PLUGINS), hostFailureListener); super(settings, Settings.EMPTY, addPlugins(plugins, PRE_INSTALLED_PLUGINS), hostFailureListener);
} }