com.datastax.driver.core.policies.Policies.getLoadBalancingPolicy()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(199)

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

Policies.getLoadBalancingPolicy介绍

[英]The load balancing policy in use.

The load balancing policy defines how Cassandra hosts are picked for queries.
[中]正在使用的负载平衡策略。
负载平衡策略定义了如何选择Cassandra主机进行查询。

代码示例

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

LoadBalancingPolicy loadBalancingPolicy() {
 return configuration.getPolicies().getLoadBalancingPolicy();
}

代码示例来源:origin: intuit/wasabi

private void poolingMonitoring(PoolingOptions poolingOptions) {
    final LoadBalancingPolicy loadBalancingPolicy =
        cluster.getConfiguration().getPolicies().getLoadBalancingPolicy();
    ScheduledExecutorService scheduled =
        Executors.newScheduledThreadPool(1);
    scheduled.scheduleAtFixedRate((Runnable) () -> {
      Session.State state = session.getState();
      for (Host host : state.getConnectedHosts()) {
        HostDistance distance = loadBalancingPolicy.distance(host);
        int connections = state.getOpenConnections(host);
        int inFlightQueries = state.getInFlightQueries(host);
        LOGGER.info("{} connections={}, current load={}, max load={}",
            host, connections, inFlightQueries,
            connections * poolingOptions.getMaxRequestsPerConnection(distance));
      }
    }, 5, 5, TimeUnit.SECONDS);
  }
}

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

Assert.assertEquals(configuration.getPoolingOptions()
    .getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(), TAP);
Assert.assertEquals(configuration.getPolicies().getReconnectionPolicy().getClass().getName(), CRP);
Assert.assertEquals(configuration.getPolicies().getRetryPolicy().getClass().getName(), LRTP);

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

Assert.assertEquals(configuration.getPoolingOptions()
    .getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(),
    LatencyAwarePolicy.class.getName());
Assert.assertEquals(configuration.getPolicies().getReconnectionPolicy().getClass().getName(), CRP);

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

.getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(), DRRP);
Assert.assertEquals(configuration.getPolicies().getReconnectionPolicy().getClass().getName(), CRP);
Assert.assertEquals(configuration.getPolicies().getRetryPolicy().getClass().getName(), DCRP);

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

.getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(), RRP);
Assert.assertEquals(configuration.getPolicies().getReconnectionPolicy().getClass().getName(), ERP);
Assert.assertEquals(configuration.getPolicies().getRetryPolicy().getClass().getName(), DCRP);

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

.getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(), RRP);
Assert.assertEquals(configuration.getPolicies().getReconnectionPolicy().getClass().getName(), ERP);
Assert.assertEquals(configuration.getPolicies().getRetryPolicy().getClass().getName(), DCRP);

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

LoadBalancingPolicy loadBalancingPolicy() {
  return configuration.getPolicies().getLoadBalancingPolicy();
}

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

LoadBalancingPolicy loadBalancingPolicy() {
  return configuration.getPolicies().getLoadBalancingPolicy();
}

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

LoadBalancingPolicy loadBalancingPolicy() {
  return configuration.getPolicies().getLoadBalancingPolicy();
}

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

LoadBalancingPolicy loadBalancingPolicy() {
  return configuration.getPolicies().getLoadBalancingPolicy();
}

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

private Manager(String clusterName, List<InetSocketAddress> contactPoints, Configuration configuration, Collection<Host.StateListener> listeners) {
  this.clusterName = clusterName == null ? generateClusterName() : clusterName;
  this.configuration = configuration;
  this.contactPoints = contactPoints;
  this.listeners = new CopyOnWriteArraySet<Host.StateListener>(listeners);
  this.requiresPartitionMap = requiresPartitionMap(configuration.getPolicies().getLoadBalancingPolicy());
}

代码示例来源:origin: EinsamHauer/disthene

private List<List<Statement>> splitByToken() {
  Map<Set<Host>,List<Statement>> batches = new HashMap<>();
  for (Statement statement : statements) {
    Set<Host> hosts = new HashSet<>();
    Iterator<Host> it = session.getCluster().getConfiguration().getPolicies().
        getLoadBalancingPolicy().newQueryPlan(statement.getKeyspace(), statement);
    // We are using TokenAwarePolicy without shuffling. Let's group by primary replica only then
    if (it.hasNext()) {
      hosts.add(it.next());
    }
    List<Statement> tokenBatch = batches.get(hosts);
    if (tokenBatch == null) {
      tokenBatch = new ArrayList<>();
      batches.put(hosts, tokenBatch);
    }
    tokenBatch.add(statement);
  }
  return new ArrayList<>(batches.values());
}

代码示例来源:origin: com.moz.fiji.mapreduce/fiji-mapreduce-cassandra

/**
 * Constructor for SubsplitCreator.
 * @param session open Cassandra Session.
 */
public CassandraSubSplitCreator(Session session) {
 mSession = session;
 // Check that this session uses the load-balancing policy that we need.
 Preconditions.checkArgument(
   session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy()
     instanceof ConsistentHostOrderPolicy
 );
}

代码示例来源:origin: hawkular/hawkular-metrics

public RxSessionImpl(Session session) {
  this.session = session;
  this.loadBalancingPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
  PoolingOptions poolingOptions = session.getCluster().getConfiguration().getPoolingOptions();
  maxInFlightLocal = poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL) *
      poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL);
  maxInFlightRemote = poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE) *
      poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE);
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-rx-java-driver

public RxSessionImpl(Session session) {
  this.session = session;
  this.loadBalancingPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
  PoolingOptions poolingOptions = session.getCluster().getConfiguration().getPoolingOptions();
  maxInFlightLocal = poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL) *
      poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL);
  maxInFlightRemote = poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE) *
      poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE);
}

代码示例来源:origin: hawkular/hawkular-metrics

public DataAccessImpl(Session session) {
  this.session = session;
  rxSession = new RxSessionImpl(session);
  loadBalancingPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
  codecRegistry = session.getCluster().getConfiguration().getCodecRegistry();
  metadata = session.getCluster().getMetadata();
  initPreparedStatements();
  initializeTemporaryTableStatements();
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service

public DataAccessImpl(Session session) {
  this.session = session;
  rxSession = new RxSessionImpl(session);
  loadBalancingPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
  codecRegistry = session.getCluster().getConfiguration().getCodecRegistry();
  metadata = session.getCluster().getMetadata();
  initPreparedStatements();
  initializeTemporaryTableStatements();
}

代码示例来源:origin: spring-cloud/spring-cloud-connectors

@Test
public void cassandraSessionWithConfiguration() throws Exception {
  ApplicationContext testContext = getTestApplicationContext(
      "cloud-cassandra-with-config.xml", createService("my-service"));
  Cluster cluster = testContext.getBean("cassandra-full-config",
      getConnectorType());
  assertNotNull(cluster.getConfiguration().getSocketOptions());
  assertEquals(15000,
      cluster.getConfiguration().getSocketOptions().getConnectTimeoutMillis());
  assertTrue(DefaultRetryPolicy.class.isAssignableFrom(
      cluster.getConfiguration().getPolicies().getRetryPolicy().getClass()));
  assertTrue(RoundRobinPolicy.class.isAssignableFrom(cluster.getConfiguration()
      .getPolicies().getLoadBalancingPolicy().getClass()));
  assertTrue(ConstantReconnectionPolicy.class.isAssignableFrom(cluster
      .getConfiguration().getPolicies().getReconnectionPolicy().getClass()));
}

代码示例来源:origin: ef-labs/vertx-cassandra

private void createKeyspace(Metadata metadata) {
  Statement createKeyspaceStatement = null;
  // Find out which node is closest and use that for the networktopologystrategy
  LoadBalancingPolicy lbPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
  for (Host host : metadata.getAllHosts()) {
    if (lbPolicy.distance(host) == HostDistance.LOCAL) {
      createKeyspaceStatement = KeyspaceBuilder.create(keyspace)
          .ifNotExists()
          .networkTopologyStrategy()
          .dc(host.getDatacenter(), 1);
      break;
    }
  }
  if (createKeyspaceStatement == null) {
    fail("Could not find a local host for the test");
    return;
  }
  session.execute(createKeyspaceStatement);
}

相关文章