public class WhiteListPolicy extends HostFilterPolicy
This policy wraps another load balancing policy and will delegate the choice of hosts to the
wrapped policy with the exception that only hosts contained in the white list provided when
constructing this policy will ever be returned. Any host not in the while list will be considered
IGNORED
and thus will not be connected to.
This policy can be useful to ensure that the driver only connects to a predefined set of hosts. Keep in mind however that this policy defeats somewhat the host auto-detection of the driver. As such, this policy is only useful in a few special cases or for testing, but is not optimal in general. If all you want to do is limiting connections to hosts of the local data-center then you should use DCAwareRoundRobinPolicy and *not* this policy in particular.
HostFilterPolicy
Constructor and Description |
---|
WhiteListPolicy(LoadBalancingPolicy childPolicy,
Collection<InetSocketAddress> whiteList)
Creates a new policy that wraps the provided child policy but only "allows" hosts from the
provided white list.
|
Modifier and Type | Method and Description |
---|---|
static WhiteListPolicy |
ofHosts(LoadBalancingPolicy childPolicy,
Iterable<String> hostnames)
Creates a new policy that wraps the provided child policy but only "allows" hosts having
addresses that match those from the resolved input host names.
|
static WhiteListPolicy |
ofHosts(LoadBalancingPolicy childPolicy,
String... hostnames)
Creates a new policy with the given host names.
|
close, distance, fromDCBlackList, fromDCWhiteList, getChildPolicy, init, newQueryPlan, onAdd, onDown, onRemove, onUp
public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList)
childPolicy
- the wrapped policy.whiteList
- the white listed hosts. Only hosts from this list may get connected to
(whether they will get connected to or not depends on the child policy).public static WhiteListPolicy ofHosts(LoadBalancingPolicy childPolicy, String... hostnames)
See ofHosts(LoadBalancingPolicy, Iterable)
for more details.
public static WhiteListPolicy ofHosts(LoadBalancingPolicy childPolicy, Iterable<String> hostnames)
Note that all host names must be non-null and resolvable; if any of them cannot be resolved, this method will fail.
childPolicy
- the wrapped policy.hostnames
- list of host names to resolve whitelisted addresses from.IllegalArgumentException
- if any of the given hostnames
could not be resolved.NullPointerException
- If null was provided for a hostname.SecurityException
- if a security manager is present and permission to resolve the host
name is denied.Copyright © 2012–2024. All rights reserved.