当前位置: 首页>>代码示例>>Java>>正文


Java DefaultRetryPolicy类代码示例

本文整理汇总了Java中com.datastax.driver.core.policies.DefaultRetryPolicy的典型用法代码示例。如果您正苦于以下问题:Java DefaultRetryPolicy类的具体用法?Java DefaultRetryPolicy怎么用?Java DefaultRetryPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultRetryPolicy类属于com.datastax.driver.core.policies包,在下文中一共展示了DefaultRetryPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startComponent

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@Override
public void startComponent() {
  if (cluster == null) {
    // Configure and build up the Cassandra cluster.
    cluster = Cluster.builder()
            .withClusterName(clusterName)
            .withPort(port)
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            // TokenAware requires query has routing info (e.g. BoundStatement with all PK value bound).
            .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .build();

    // Register any codecs.
    cluster.getConfiguration().getCodecRegistry()
            .register(new CassandraEnumCodec<>(AccessMode.class, AccessMode.getValueMap()))
            .register(new CassandraEnumCodec<>(Direction.class, Direction.getValueMap()))
            .register(new CassandraEnumCodec<>(SourceEntity.Type.class, SourceEntity.Type.getValueMap()));

    // Create a session.
    manager = new MappingManager(cluster.connect());
  }
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:24,代码来源:ClusterManager.java

示例2: onReadTimeout

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@Override
public RetryDecision onReadTimeout(
    Statement stmt,
    ConsistencyLevel cl,
    int required,
    int received,
    boolean retrieved,
    int retry) {

  if (retry > 1) {
    try {
      Thread.sleep(100);
    } catch (InterruptedException expected) { }
  }
  return null != stmt && stmt.isIdempotent()
      ? retry < 10 ? RetryDecision.retry(cl) : RetryDecision.rethrow()
      : DefaultRetryPolicy.INSTANCE.onReadTimeout(stmt, cl, required, received, retrieved, retry);
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:19,代码来源:CassandraStorage.java

示例3: DatastaxMetricModule

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@JsonCreator
public DatastaxMetricModule(
    @JsonProperty("id") Optional<String> id, @JsonProperty("groups") Optional<Groups> groups,
    @JsonProperty("seeds") Optional<Set<String>> seeds,
    @JsonProperty("schema") Optional<SchemaModule> schema,
    @JsonProperty("configure") Optional<Boolean> configure,
    @JsonProperty("fetchSize") Optional<Integer> fetchSize,
    @JsonProperty("readTimeout") Optional<Duration> readTimeout,
    @JsonProperty("consistencyLevel") Optional<ConsistencyLevel> consistencyLevel,
    @JsonProperty("retryPolicy") Optional<RetryPolicy> retryPolicy,
    @JsonProperty("authentication") Optional<DatastaxAuthentication> authentication
) {
    this.id = id;
    this.groups = groups.orElseGet(Groups::empty).or("heroic");
    this.seeds = convert(seeds.orElse(DEFAULT_SEEDS));
    this.schema = schema.orElseGet(NextGenSchemaModule.builder()::build);
    this.configure = configure.orElse(DEFAULT_CONFIGURE);
    this.fetchSize = fetchSize.orElse(DEFAULT_FETCH_SIZE);
    this.readTimeout = readTimeout.orElse(DEFAULT_READ_TIMEOUT);
    this.consistencyLevel = consistencyLevel.orElse(ConsistencyLevel.ONE);
    this.retryPolicy = retryPolicy.orElse(DefaultRetryPolicy.INSTANCE);
    this.authentication = authentication.orElseGet(DatastaxAuthentication.None::new);
}
 
开发者ID:spotify,项目名称:heroic,代码行数:24,代码来源:DatastaxMetricModule.java

示例4: createCache

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
protected void createCache(Map<String, String> mapParams) throws Exception {
    final Cluster.Builder bluePrint = Cluster.builder().withClusterName("BluePrint")
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM))
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))
            .addContactPoint(mapParams.get("cassandra.server.ip.address")).withPort(9042);

    cache1 = mache(String.class, CassandraTestEntity.class)
            .cachedBy(guava())
            .storedIn(cassandra()
                    .withCluster(bluePrint)
                    .withKeyspace(mapParams.get("keyspace.name"))
                    .withSchemaOptions(SchemaOptions.CREATE_SCHEMA_IF_NEEDED)
                    .build())
            .withMessaging(kafka()
                    .withKafkaMqConfig(KafkaMqConfigBuilder.builder()
                            .withZkHost(mapParams.get("kafka.connection"))
                            .build())
                    .withTopic(mapParams.get("kafka.topic"))
                    .build())
            .macheUp();
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:23,代码来源:MacheAbstractCassandraKafkaSamplerClient.java

示例5: testRetryPolicyParsing

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@Test
public void testRetryPolicyParsing() throws Exception
{
	String retryPolicyStr = "DefaultRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DefaultRetryPolicy);
	System.out.println("====================");
	retryPolicyStr = "DowngradingConsistencyRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DowngradingConsistencyRetryPolicy);
	System.out.println("====================");
	retryPolicyStr = "FallthroughRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof FallthroughRetryPolicy);
	System.out.println("====================");
	    	

}
 
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:19,代码来源:UtilsUnitTest.java

示例6: populateRetrytPolicy

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
private Builder populateRetrytPolicy(Map<String, String> properties, Builder builder) throws DataServiceFault {
    String retryPolicy = properties.get(DBConstants.Cassandra.RETRY_POLICY);
    if (retryPolicy != null) {
        if ("DefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
        } else if ("DowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
        } else if ("FallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE);
        } else if ("LoggingDefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE));
        } else if ("LoggingDowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE));                
        } else if ("LoggingFallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE));                
        } else {
            throw new DataServiceFault("Invalid Cassandra retry policy: " + retryPolicy);
        }
    }
    return builder;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:22,代码来源:CassandraConfig.java

示例7: cassandraSessionWithConfiguration

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@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()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:18,代码来源:CassandraClusterXmlConfigTest.java

示例8: createCluster

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
/**
 * @param ip String
 * @param port String
 * @param poolingOptions PoolingOptions
 * @return Cluster Cluster
 */
private static Cluster createCluster(String ip, String port, PoolingOptions poolingOptions) {
  return Cluster.builder().addContactPoint(ip).withPort(Integer.parseInt(port))
      .withProtocolVersion(ProtocolVersion.V3).withRetryPolicy(DefaultRetryPolicy.INSTANCE)
      .withTimestampGenerator(new AtomicMonotonicTimestampGenerator())
      .withPoolingOptions(poolingOptions).build();
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:13,代码来源:CassandraConnectionManagerImpl.java

示例9: main

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
public static void main(String[] args){
    Cluster cluster;
    Session session;
    cluster = Cluster
            .builder()
            .addContactPoint("127.0.0.1")
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE) //Other option: DowngradingConsistencyRetryPolicy
            .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
            .build();
    session = cluster.connect("demo");


    PreparedStatement statement = session.prepare("INSERT INTO user (id, name) VALUES (?, ?)");
    Statement boundStatement = statement
            .bind(1, "user 1")
            .enableTracing();

    long startTime = System.currentTimeMillis();
    ResultSet resultSet = session.execute(boundStatement);
    long duration = System.currentTimeMillis() - startTime;
    System.out.format("Time taken: %d", duration);

    ExecutionInfo executionInfo = resultSet.getExecutionInfo();
    printQueryTrace(executionInfo.getQueryTrace());
    cluster.close();

}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:28,代码来源:TracingExample.java

示例10: init

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
public void init() {
    LOG.info("Starting Cassandra connector initialization.");
    Cluster.Builder builder = Cluster.builder()
            .addContactPoints(hosts)
            .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMs))
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            .withCompression(ProtocolOptions.Compression.LZ4)
            .withSocketOptions(new SocketOptions()
                    .setReceiveBufferSize(receiverBufferSize)
                    .setSendBufferSize(senderBufferSize))
            .withPort(port);
    if (poolingOptions != null) {
        int procs = Runtime.getRuntime().availableProcessors();
        poolingOptions
                .setConnectionsPerHost(HostDistance.LOCAL, procs, procs * 2)
                .setConnectionsPerHost(HostDistance.REMOTE, (procs / 2), procs * 2)
                .setPoolTimeoutMillis(poolTimeoutMillis)
                .setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequestsPerConnection)
                .setMaxRequestsPerConnection(HostDistance.REMOTE, maxRequestsPerConnection);
        builder.withPoolingOptions(poolingOptions);
    }
    if (!Strings.isNullOrEmpty(username)) {
        builder.withCredentials(username, password);
    }
    cluster = builder.build();
    session = cluster.connect(keyspace);
}
 
开发者ID:dmart28,项目名称:gcplot,代码行数:28,代码来源:CassandraConnector.java

示例11: onWriteTimeout

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@Override
public RetryDecision onWriteTimeout(
    Statement stmt,
    ConsistencyLevel cl,
    WriteType type,
    int required,
    int received,
    int retry) {

  return null != stmt && stmt.isIdempotent()
      ? RetryDecision.retry(cl)
      : DefaultRetryPolicy.INSTANCE.onWriteTimeout(stmt, cl, type, required, received, retry);
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:14,代码来源:CassandraStorage.java

示例12: returnsDefaultRetryPolicyInstance

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
@Test
public void returnsDefaultRetryPolicyInstance() throws Exception {
    final DefaultRetryPolicyFactory factory = new DefaultRetryPolicyFactory();

    final DefaultRetryPolicy policy = (DefaultRetryPolicy) factory.build();

    assertThat(policy).isSameAs(DefaultRetryPolicy.INSTANCE);
}
 
开发者ID:composable-systems,项目名称:dropwizard-cassandra,代码行数:9,代码来源:DefaultRetryPolicyFactoryTest.java

示例13: populateRetrytPolicy

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
private Cluster.Builder populateRetrytPolicy(Properties properties, Cluster.Builder builder) {
  String retryPolicy = properties.getProperty(CassandraStoreParameters.RETRY_POLICY);
  if (retryPolicy != null) {
    switch (retryPolicy) {
      case "DefaultRetryPolicy":
        builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
        break;
      case "DowngradingConsistencyRetryPolicy":
        builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
        break;
      case "FallthroughRetryPolicy":
        builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE);
        break;
      case "LoggingDefaultRetryPolicy":
        builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE));
        break;
      case "LoggingDowngradingConsistencyRetryPolicy":
        builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE));
        break;
      case "LoggingFallthroughRetryPolicy":
        builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE));
        break;
      default:
        LOG.error("Unsupported retry policy : {} ", retryPolicy);
        break;
    }
  }
  return builder;
}
 
开发者ID:apache,项目名称:gora,代码行数:30,代码来源:CassandraClient.java

示例14: createSessionManager

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
/**
 * Creates a {@link SessionManager} instance. Sub-class my override this
 * method to customized its own {@link SessionManager}.
 * 
 * @return
 */
protected SessionManager createSessionManager() {
    SessionManager sm = new SessionManager();

    // sm.setRetryPolicy(new
    // LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE));
    sm.setRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE));
    sm.setSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 3));

    sm.init();
    return sm;
}
 
开发者ID:DDTH,项目名称:ddth-id,代码行数:18,代码来源:CassandraIdGenerator.java

示例15: build

import com.datastax.driver.core.policies.DefaultRetryPolicy; //导入依赖的package包/类
public CassandraSessionManaged build(Environment environment, String localDc) {
    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions.setConnectionsPerHost(HostDistance.LOCAL,  3, 5)
        .setConnectionsPerHost(HostDistance.REMOTE, 1, 2);
    final DCAwareRoundRobinPolicy.Builder builder = DCAwareRoundRobinPolicy.builder();
    if (localDc != null) {
        builder.withLocalDc(localDc);
    }
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE).setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL);
    final Cluster cluster = Cluster
        .builder()
        .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
        .withReconnectionPolicy(new ExponentialReconnectionPolicy(10L, 1000L))
        .withQueryOptions(queryOptions)
        .withLoadBalancingPolicy(new TokenAwarePolicy(builder.build()))
        .addContactPoints(getContactPoints().stream().toArray(String[]::new))
        .withPort(getPort())
        .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(1000, 2))
        .withPoolingOptions(poolingOptions)
        .build();

    cluster.getConfiguration().getCodecRegistry()
        .register(InstantCodec.instance);

    Session session = cluster.connect(getKeySpace());

    CassandraSessionManaged cassandraSessionManaged = new CassandraSessionManaged(cluster, session);
    environment.lifecycle().manage(cassandraSessionManaged);

    return cassandraSessionManaged;
}
 
开发者ID:iZettle,项目名称:izettle-toolbox,代码行数:33,代码来源:CassandraSessionFactory.java


注:本文中的com.datastax.driver.core.policies.DefaultRetryPolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。