com.datastax.driver.core.policies.WhiteListPolicy类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.datastax.driver.core.policies.WhiteListPolicy类的一些代码示例,展示了WhiteListPolicy类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WhiteListPolicy类的具体详情如下:
包路径:com.datastax.driver.core.policies.WhiteListPolicy
类名称:WhiteListPolicy

WhiteListPolicy介绍

[英]A load balancing policy wrapper that ensure that only hosts from a provided white list will ever be returned.

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 IGNOREDand 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.
[中]一个负载平衡策略包装器,确保只返回所提供白名单中的主机。
此策略包装了另一个负载平衡策略,并将主机的选择委托给包装的策略,但只有在构建此策略时提供的白名单中包含的主机才会被返回。任何不在while列表中的主机都将被视为被忽略,因此不会连接到。
此策略可用于确保驱动程序仅连接到预定义的主机集。但是请记住,此策略在一定程度上会破坏主机对驱动程序的自动检测。因此,该策略仅在少数特殊情况下或用于测试时有用,但总体上不是最优的。如果您只想限制与本地数据中心主机的连接,那么您应该使用dcawarerRoundRobinPolicy,尤其是此策略。

代码示例

代码示例来源:origin: prestodb/presto

whiteList.add(new InetSocketAddress(point, config.getNativeProtocolPort()));
loadPolicy = new WhiteListPolicy(loadPolicy, whiteList);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Creates a new policy that wraps the provided child policy but only "allows" hosts from the
 * provided white list.
 *
 * @param childPolicy the wrapped policy.
 * @param 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 WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) {
 super(childPolicy, buildPredicate(whiteList));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Creates a new policy with the given host names.
 *
 * <p>See {@link #ofHosts(LoadBalancingPolicy, Iterable)} for more details.
 */
public static WhiteListPolicy ofHosts(LoadBalancingPolicy childPolicy, String... hostnames) {
 return ofHosts(childPolicy, Arrays.asList(hostnames));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

return new WhiteListPolicy(
  childPolicy,
  new Predicate<Host>() {

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

/**
 * Creates a new policy that wraps the provided child policy but only "allows" hosts
 * from the provided while list.
 *
 * @param childPolicy the wrapped policy.
 * @param 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 WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) {
  super(childPolicy, buildPredicate(whiteList));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws an {@link
 * IllegalArgumentException} if a name could not be resolved.
 *
 * @test_category load_balancing:white_list
 */
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
public void should_throw_IAE_if_name_could_not_be_resolved() {
 WhiteListPolicy.ofHosts(new RoundRobinPolicy(), "a.b.c.d.e.f.UNRESOLVEABLE");
}

代码示例来源:origin: Impetus/Kundera

loadBalancingPolicy = new WhiteListPolicy(loadBalancingPolicy, whiteListCollection);

代码示例来源:origin: com.yugabyte/cassandra-driver-core

/**
 * Creates a new policy that wraps the provided child policy but only "allows" hosts
 * from the provided while list.
 *
 * @param childPolicy the wrapped policy.
 * @param 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 WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) {
  super(childPolicy, buildPredicate(whiteList));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws a {@link
 * NullPointerException} if a name provided is null.
 *
 * @test_category load_balancing:white_list
 */
@Test(groups = "unit", expectedExceptions = NullPointerException.class)
public void should_throw_NPE_if_null_provided() {
 WhiteListPolicy.ofHosts(new RoundRobinPolicy(), null, null);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public Cluster.Builder createClusterBuilder() {
 // Only connect to node 1, which makes it easier to query system tables in
 // should_expose_tokens_per_host()
 LoadBalancingPolicy lbp =
   new WhiteListPolicy(new RoundRobinPolicy(), Collections.singleton(ccm().addressOfNode(1)));
 return Cluster.builder()
   .addContactPoints(getContactPoints().get(0))
   .withPort(ccm().getBinaryPort())
   .withLoadBalancingPolicy(lbp);
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver

/**
 * Creates a new policy that wraps the provided child policy but only "allows" hosts
 * from the provided while list.
 *
 * @param childPolicy the wrapped policy.
 * @param 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 WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) {
  super(childPolicy, buildPredicate(whiteList));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

WhiteListPolicy.ofHosts(
  new RoundRobinPolicy(),
  sCluster.address(1).getHostName(),

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * @return a {@link Cluster} instance that connects only to the control host of the given cluster.
 */
public static Cluster buildControlCluster(Cluster cluster, CCMAccess ccm) {
 Host controlHost = cluster.manager.controlConnection.connectedHost();
 List<InetSocketAddress> singleAddress =
   Collections.singletonList(controlHost.getSocketAddress());
 return Cluster.builder()
   .addContactPoints(controlHost.getSocketAddress().getAddress())
   .withPort(ccm.getBinaryPort())
   .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress))
   .build();
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws an {@link
 * IllegalArgumentException} if a name could not be resolved.
 *
 * @test_category load_balancing:white_list
 */
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
public void should_throw_IAE_if_name_could_not_be_resolved() {
 WhiteListPolicy.ofHosts(new RoundRobinPolicy(), "a.b.c.d.e.f.UNRESOLVEABLE");
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

private void deleteNode2RpcAddressFromNode1() throws Exception {
  InetSocketAddress firstHost = ccm().addressOfNode(1);
  Cluster cluster =
    register(
      Cluster.builder()
        .addContactPoints(firstHost.getAddress())
        .withPort(ccm().getBinaryPort())
        // ensure we will only connect to node1
        .withLoadBalancingPolicy(
          new WhiteListPolicy(
            Policies.defaultLoadBalancingPolicy(), Lists.newArrayList(firstHost)))
        .build());
  Session session = cluster.connect();
  String deleteStmt =
    String.format(
      "DELETE rpc_address FROM system.peers WHERE peer = '%s'",
      ccm().addressOfNode(2).getHostName());
  session.execute(deleteStmt);
  session.close();
  cluster.close();
 }
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws a {@link
 * NullPointerException} if a name provided is null.
 *
 * @test_category load_balancing:white_list
 */
@Test(groups = "unit", expectedExceptions = NullPointerException.class)
public void should_throw_NPE_if_null_provided() {
 WhiteListPolicy.ofHosts(new RoundRobinPolicy(), null, null);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_rethrow_unavailable_in_no_host_available_exception() {
 LoadBalancingPolicy firstHostOnlyPolicy =
   new WhiteListPolicy(
     Policies.defaultLoadBalancingPolicy(),
     Collections.singletonList(host1.getSocketAddress()));

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

WhiteListPolicy.ofHosts(
  new RoundRobinPolicy(),
  sCluster.address(1).getHostName(),

代码示例来源:origin: composable-systems/dropwizard-cassandra

@Override
  public LoadBalancingPolicy build() {
    return new WhiteListPolicy(subPolicy.build(), whiteList);
  }
}

代码示例来源:origin: systems.composable/dropwizard-cassandra

@Override
  public LoadBalancingPolicy build() {
    return new WhiteListPolicy(subPolicy.build(), whiteList);
  }
}

相关文章