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

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

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

Policies介绍

[英]Policies configured for a com.datastax.driver.core.Cluster instance.
[中]为com配置的策略。税收。驾驶员果心集群实例。

代码示例

代码示例来源: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: com.datastax.cassandra/cassandra-driver-core

/**
  * Builds the final object from this builder.
  *
  * <p>Any field that hasn't been set explicitly will get its default value.
  *
  * @return the object.
  */
 public Policies build() {
  return new Policies(
    loadBalancingPolicy == null ? defaultLoadBalancingPolicy() : loadBalancingPolicy,
    reconnectionPolicy == null ? defaultReconnectionPolicy() : reconnectionPolicy,
    retryPolicy == null ? defaultRetryPolicy() : retryPolicy,
    addressTranslator == null ? defaultAddressTranslator() : addressTranslator,
    timestampGenerator == null ? defaultTimestampGenerator() : timestampGenerator,
    speculativeExecutionPolicy == null
      ? defaultSpeculativeExecutionPolicy()
      : speculativeExecutionPolicy);
 }
}

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

configuration.getPolicies().getRetryPolicy().close();
reconnectionPolicy().close();
configuration.getPolicies().getAddressTranslator().close();
for (LatencyTracker tracker : latencyTrackers) tracker.onUnregister(Cluster.this);
for (Host.StateListener listener : listeners) listener.onUnregister(Cluster.this);

代码示例来源:origin: com.github.ddth/ddth-cql-utils

AddressTranslator at = policies != null ? policies.getAddressTranslator() : null;
if (at != null) {
  builder.withAddressTranslator(at);
LoadBalancingPolicy lbp = policies != null ? policies.getLoadBalancingPolicy() : null;
if (lbp != null) {
  builder.withLoadBalancingPolicy(lbp);
ReconnectionPolicy rnp = policies != null ? policies.getReconnectionPolicy() : null;
if (rnp != null) {
  builder.withReconnectionPolicy(rnp);
RetryPolicy rp = policies != null ? policies.getRetryPolicy() : null;
if (rp != null) {
  builder.withRetryPolicy(rp);
SpeculativeExecutionPolicy sep = policies != null ? policies.getSpeculativeExecutionPolicy()
    : null;
if (sep != null) {
  builder.withSpeculativeExecutionPolicy(sep);
TimestampGenerator tg = policies != null ? policies.getTimestampGenerator() : null;
if (tg != null) {
  builder.withTimestampGenerator(tg);

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

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

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

private <T> T executeWithSession(SessionCallable<T> sessionCallable)
{
  ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy();
  ReconnectionSchedule schedule = reconnectionPolicy.newSchedule();
  long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis();
  while (true) {
    try {
      return sessionCallable.executeWithSession(session.get());
    }
    catch (NoHostAvailableException e) {
      long timeLeft = deadline - System.currentTimeMillis();
      if (timeLeft <= 0) {
        throw e;
      }
      else {
        long delay = Math.min(schedule.nextDelayMs(), timeLeft);
        log.warn(e.getCustomMessage(10, true, true));
        log.warn("Reconnecting in %dms", delay);
        try {
          Thread.sleep(delay);
        }
        catch (InterruptedException interrupted) {
          Thread.currentThread().interrupt();
          throw new RuntimeException("interrupted", interrupted);
        }
      }
    }
  }
}

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

public Policies() {
  this(defaultLoadBalancingPolicy(), defaultReconnectionPolicy(), defaultRetryPolicy(), defaultAddressTranslater());
}

代码示例来源:origin: com.github.ddth/ddth-cql-utils

asyncSemaphore = new Semaphore(maxSyncJobs, true);
Policies.Builder polBuilder = Policies.builder();
if (this.addressTranslator == null) {
  addressTranslator = Policies.defaultAddressTranslator();
  loadBalancingPolicy = Policies.defaultLoadBalancingPolicy();
  retryPolicy = Policies.defaultRetryPolicy();
  speculativeExecutionPolicy = Policies.defaultSpeculativeExecutionPolicy();
  timestampGenerator = Policies.defaultTimestampGenerator();

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

@Override
public Cluster.Builder createClusterBuilder() {
 policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy());
 return Cluster.builder()
   .addContactPoints(getContactPoints().get(0))
   .withLoadBalancingPolicy(policy);
}

代码示例来源:origin: bazaarvoice/emodb

_loadBalancingPolicy = Objects.firstNonNull(_loadBalancingPolicy, Policies.defaultLoadBalancingPolicy());
_retryPolicy = Objects.firstNonNull(_retryPolicy, Policies.defaultRetryPolicy());

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

private RetryPolicy retryPolicy() {
 return statement.getRetryPolicy() == null
   ? manager.configuration().getPolicies().getRetryPolicy()
   : statement.getRetryPolicy();
}

代码示例来源:origin: cumulusrdf/cumulusrdf

/**
 * Returns the retry balancing policy according with a given configuration.
 * 
 * @param configuration the configuration.
 * @return the retry balancing policy according with a given configuration.
 */
private RetryPolicy retryPolicy(final Configuration<Map<String, Object>> configuration) {
  RetryPolicy retryPolicy = Policies.defaultRetryPolicy();
  try {
    String retryPolicyClassName = configuration.getAttribute(RETRY_POLICY, null);
    if (retryPolicyClassName != null) {
      retryPolicy = (RetryPolicy) Class.forName(retryPolicyClassName).newInstance();                        
    }
  } catch (final Exception ignore) {
    // just use the default value.
  }
  return retryPolicy;
}

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

/**
  * Builds the final object from this builder.
  *
  * <p>Any field that hasn't been set explicitly will get its default value.
  *
  * @return the object.
  */
 public Configuration build() {
  return new Configuration(
    policies != null ? policies : Policies.builder().build(),
    protocolOptions != null ? protocolOptions : new ProtocolOptions(),
    poolingOptions != null ? poolingOptions : new PoolingOptions(),
    socketOptions != null ? socketOptions : new SocketOptions(),
    metricsOptions != null ? metricsOptions : new MetricsOptions(),
    queryOptions != null ? queryOptions : new QueryOptions(),
    threadingOptions != null ? threadingOptions : new ThreadingOptions(),
    nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE,
    codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE);
 }
}

代码示例来源:origin: apache/usergrid

.withQueryOptions(queryOptions)
.withSocketOptions(socketOptions)
.withReconnectionPolicy(Policies.defaultReconnectionPolicy())

代码示例来源:origin: stackoverflow.com

public void actionPerformed(ActionEvent e) {
  new Policies ();
}

代码示例来源: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: com.datastax.cassandra/cassandra-driver-core

ReconnectionPolicy reconnectionPolicy() {
 return configuration.getPolicies().getReconnectionPolicy();
}

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

/**
 * The configuration that will be used for the new cluster.
 * <p>
 * You <b>should not</b> modify this object directly because changes made
 * to the returned object may not be used by the cluster build.
 * Instead, you should use the other methods of this {@code Builder}.
 *
 * @return the configuration to use for the new cluster.
 */
@Override
public Configuration getConfiguration() {
  Policies policies = new Policies(
    loadBalancingPolicy == null ? Policies.defaultLoadBalancingPolicy() : loadBalancingPolicy,
    reconnectionPolicy == null ? Policies.defaultReconnectionPolicy() : reconnectionPolicy,
    retryPolicy == null ? Policies.defaultRetryPolicy() : retryPolicy,
    addressTranslater == null ? Policies.defaultAddressTranslater() : addressTranslater
  );
  return new Configuration(policies,
               new ProtocolOptions(port, protocolVersion, sslOptions, authProvider).setCompression(compression),
               poolingOptions == null ? new PoolingOptions() : poolingOptions,
               socketOptions == null ? new SocketOptions() : socketOptions,
               metricsEnabled ? new MetricsOptions(jmxEnabled) : null,
               queryOptions == null ? new QueryOptions() : queryOptions);
}

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

configuration.getPolicies().getRetryPolicy().init(Cluster.this);
reconnectionPolicy().init(Cluster.this);
configuration.getPolicies().getAddressTranslator().init(Cluster.this);
for (LatencyTracker tracker : latencyTrackers) tracker.onRegister(Cluster.this);
for (Host.StateListener listener : listeners) listener.onRegister(Cluster.this);

代码示例来源: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();
 }
}

相关文章