static Session connect() { String contactPoint = "localhost"; String keySpace = "ks1"; if(session == null) { RetryPolicy retryPolicy = new CustomRetryPolicy(3, 3, 2); cluster = Cluster.builder().addContactPoint(contactPoint) .withRetryPolicy(retryPolicy).build(); cluster.init(); for (Host host : cluster.getMetadata().getAllHosts()) { System.out.printf("Address: %s, Rack: %s, Datacenter: %s, Tokens: %s\n", host.getAddress(), host.getDatacenter(), host.getRack(), host.getTokens()); } } return session; }
@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); }
public StatementSettings(ConsistencyLevel consistency, ConsistencyLevel serialConsistency, boolean traceQuery, RetryPolicy retryPolicy, int fetchSize) { this.consistency = consistency; this.serialConsistency = serialConsistency; this.traceQuery = traceQuery; this.retryPolicy = retryPolicy; this.fetchSize = fetchSize; }
/** * Parse the RetryPolicy policy. */ public static RetryPolicy parseRetryPolicy(String retryPolicyString) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException { if (!retryPolicyString.contains(".")) { retryPolicyString = "com.datastax.driver.core.policies." + retryPolicyString; Class<?> clazz = Class.forName(retryPolicyString); Field field = clazz.getDeclaredField("INSTANCE"); RetryPolicy policy = (RetryPolicy) field.get(null); return policy; } return null; }
private RetryPolicy convertRetryPolicy(final String policyName, final ExtraParameters params) { if ("aggressive".equals(policyName)) { final int numRetries = params.getInteger("numRetries").orElse(DEFAULT_NUM_RETRIES); final int rotateHost = params.getInteger("rotateHost").orElse(DEFAULT_ROTATE_HOST); return new AggressiveRetryPolicy(numRetries, rotateHost); } throw new IllegalArgumentException("Not a valid retry policy: " + policyName); }
/** * Sets retry policy. * * @param plc Retry policy. */ @SuppressWarnings("UnusedDeclaration") public void setRetryPolicy(RetryPolicy plc) { retryPlc = plc; invalidate(); }
Context withRetryPolicy(RetryPolicy policy) { return new Context(dbSession, catalog, executionSpec.withRetryPolicy(policy), interceptorRegistry, beanMapper, udtValueMapper, executor); }
public ExecutionSpecImpl(ConsistencyLevel consistencyLevel, ConsistencyLevel serialConsistencyLevel, Integer ttlSec, Long writetimeMicrosSinceEpoch, Boolean enableTracking, RetryPolicy retryPolicy) { this.consistencyLevel = consistencyLevel; this.serialConsistencyLevel = serialConsistencyLevel; this.ttlSec = ttlSec; this.writetimeMicrosSinceEpoch = writetimeMicrosSinceEpoch; this.enableTracing = enableTracking; this.retryPolicy = retryPolicy; }
public ExecutionSpec withRetryPolicy(RetryPolicy policy) { return new ExecutionSpecImpl(this.consistencyLevel, this.serialConsistencyLevel, this.ttlSec, this.writetimeMicrosSinceEpoch, this.enableTracing, policy); }
public CqlSession(final String nodes, final int port, final String keyspace, final SocketOptions socketOptions, final RetryPolicy retryPolicy, final QueryOptions queryOptions, final LoadBalancingPolicy loadBalancingPolicy, final int maxConnectionsPerHost, final MetricFactory metricFactory) { // this is temp. to reuse current hosts properties: final Iterable<String> nodesIter = Splitter.on(",").split(nodes); final String[] nodesArr = Iterables.toArray( StreamSupport.stream(nodesIter.spliterator(), false).map(input -> { if (input == null) return null; final int idx = input.lastIndexOf(":"); return input.substring(0, idx); }).collect(Collectors.toList()), String.class); /*PoolingOptions poolingOptions = new PoolingOptions(); poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionsPerHost); poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionsPerHost);*/ final Cluster cluster = Cluster.builder(). withPort(port). withSocketOptions(socketOptions). withQueryOptions(queryOptions). withLoadBalancingPolicy(loadBalancingPolicy). // withPoolingOptions(poolingOptions). addContactPoints(nodesArr).build(); //cluster.init(); this.session = cluster.connect(keyspace); this.retryPolicy = Preconditions.checkNotNull(retryPolicy); this.metricFactory = Preconditions.checkNotNull(metricFactory); }
@Test public void firstTimeRetryOnReadTimeout_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onReadTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, false, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void maxTimeRetryOnReadTimeout_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onReadTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, false, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void maxTimeRetryOnWriteTimeout_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void firstTimeRetryOnUnavailable_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.ONE); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void maxTimeRetryOnUnavailable_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); }
private void prepare(String cql, RetryPolicy petryPolicy) { logger.info("Preparing cql stmt {}", cql); PreparedStatement pstmt = session.prepare(cql); pstmt.setConsistencyLevel(consistencyLevel); pstmt.setRetryPolicy(petryPolicy); pstmt.setIdempotent(true); preparedStatements.put(cql, pstmt); }
/** * Sets retry policy. * * @param plc Retry policy. */ @SuppressWarnings("UnusedDeclaration") public void setRetryPolicy(RetryPolicy plc) { this.retryPlc = plc; invalidate(); }
@Override public RetryPolicy getRetryPolicy() { return preparedStatement.getRetryPolicy(); }
@Override public PreparedStatement setRetryPolicy( RetryPolicy arg0 ) { return preparedStatement.setRetryPolicy( arg0 ); }
public Class<? extends RetryPolicy> getRetryPolicy() { return this.retryPolicy; }
public void setRetryPolicy(Class<? extends RetryPolicy> retryPolicy) { this.retryPolicy = retryPolicy; }
public RetryPolicy getRetryPolicy() { return retryPolicy; }
public StatementSettings setRetryPolicy(RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; return this; }
public RetryPolicy.RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry) { return RetryDecision.tryNextHost(cl); }
public void setRetryPolicy(RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; }
@Override public RetryPolicy build() { return DowngradingConsistencyRetryPolicy.INSTANCE; }
@Override public RetryPolicy build() { return new LoggingRetryPolicy(subPolicy.build()); }
@Override public RetryPolicy build() { return FallthroughRetryPolicy.INSTANCE; }
@Override public RetryPolicy build() { return DefaultRetryPolicy.INSTANCE; }
@Override public Object withRetryPolicy(RetryPolicy policy) { return mutation.withRetryPolicy(policy); }
@Override public net.oneandone.troilus.java7.CounterMutation withRetryPolicy(RetryPolicy policy) { return (net.oneandone.troilus.java7.CounterMutation) mutation.withRetryPolicy(policy); }
@Override public CounterMutation withRetryPolicy(RetryPolicy policy) { return (CounterMutation) mutation.withRetryPolicy(policy); }
@Override public Dao withRetryPolicy(RetryPolicy policy) { return new DaoImpl(ctx.withRetryPolicy(policy), this.tablename); }
@Override public Dao withRetryPolicy(RetryPolicy policy) { return new Java7DaoImpl(ctx.withRetryPolicy(policy), this.tablename); }