本文整理汇总了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());
}
}
示例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);
}
示例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);
}
示例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();
}
示例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("====================");
}
示例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;
}
示例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()));
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}