checkArgument(!contactPoints.isEmpty(), "empty contactPoints"); clusterBuilder.withPort(config.getNativeProtocolPort()); clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000)); clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());
.setMaxRequestsPerConnection(HostDistance.REMOTE, m_clusterConfiguration.getRequestsPerConnectionRemote()) .setMaxQueueSize(m_clusterConfiguration.getMaxQueueSize())) .withReconnectionPolicy(new ExponentialReconnectionPolicy(100, 5 * 1000)) .withLoadBalancingPolicy(new SelectiveLoadBalancingPolicy(readLoadBalancePolicy, m_writeLoadBalancingPolicy)) .withCompression(ProtocolOptions.Compression.LZ4)
.withPort(cassandraConf.getPort()) .withRetryPolicy(cassandraConf.getRetryPolicy()) .withReconnectionPolicy(new ExponentialReconnectionPolicy( cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs()))
reconnectionPolicy = new ExponentialReconnectionPolicy(baseDelayMs, maxDelayMs);
private Cluster.Builder exponential() { return Cluster.builder() .withReconnectionPolicy(new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000)); }
new ExponentialReconnectionPolicy(-1, 1); fail(); } catch (IllegalArgumentException e) { new ExponentialReconnectionPolicy(1, -1); fail(); } catch (IllegalArgumentException e) { new ExponentialReconnectionPolicy(-1, -1); fail(); } catch (IllegalArgumentException e) { new ExponentialReconnectionPolicy(2, 1); fail(); } catch (IllegalArgumentException e) { new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000).newSchedule(); assertTrue(schedule.nextDelayMs() == 2000); assertTrue(schedule.nextDelayMs() == 4000);
@Provides ReconnectionPolicy provideReconnectPolicy() { long baseAttempt = TimeUnit.SECONDS.toMillis(5); long maxTimeWaiting = TimeUnit.MINUTES.toMillis(1); ExponentialReconnectionPolicy policy = new ExponentialReconnectionPolicy(baseAttempt, maxTimeWaiting); return policy; }
@Provides ReconnectionPolicy provideReconnectPolicy() { long baseAttempt = TimeUnit.SECONDS.toMillis(5); long maxTimeWaiting = TimeUnit.MINUTES.toMillis(1); ExponentialReconnectionPolicy policy = new ExponentialReconnectionPolicy(baseAttempt, maxTimeWaiting); return policy; }
@Override public ReconnectionPolicy build() { return new ExponentialReconnectionPolicy(baseDelay.toMilliseconds(), maxDelay.toMilliseconds()); } }
@Override public ReconnectionPolicy build() { return new ExponentialReconnectionPolicy(baseDelay.toMilliseconds(), maxDelay.toMilliseconds()); } }
private Cluster.Builder populateReconnectPolicy(Properties properties, Cluster.Builder builder) { String reconnectionPolicy = properties.getProperty(CassandraStoreParameters.RECONNECTION_POLICY); if (reconnectionPolicy != null) { switch (reconnectionPolicy) { case "ConstantReconnectionPolicy": { String constantReconnectionPolicyDelay = properties.getProperty(CassandraStoreParameters.CONSTANT_RECONNECTION_POLICY_DELAY); ConstantReconnectionPolicy policy = new ConstantReconnectionPolicy(Long.parseLong(constantReconnectionPolicyDelay)); builder = builder.withReconnectionPolicy(policy); break; } case "ExponentialReconnectionPolicy": { String exponentialReconnectionPolicyBaseDelay = properties.getProperty(CassandraStoreParameters.EXPONENTIAL_RECONNECTION_POLICY_BASE_DELAY); String exponentialReconnectionPolicyMaxDelay = properties.getProperty(CassandraStoreParameters.EXPONENTIAL_RECONNECTION_POLICY_MAX_DELAY); ExponentialReconnectionPolicy policy = new ExponentialReconnectionPolicy(Long.parseLong(exponentialReconnectionPolicyBaseDelay), Long.parseLong(exponentialReconnectionPolicyMaxDelay)); builder = builder.withReconnectionPolicy(policy); break; } default: LOG.error("Unsupported reconnection policy : {} ", reconnectionPolicy); } } return builder; }
private Cluster.Builder populateReconnectPolicy(Properties properties, Cluster.Builder builder) { String reconnectionPolicy = properties.getProperty(CassandraStoreParameters.RECONNECTION_POLICY); if (reconnectionPolicy != null) { switch (reconnectionPolicy) { case "ConstantReconnectionPolicy": { String constantReconnectionPolicyDelay = properties.getProperty(CassandraStoreParameters.CONSTANT_RECONNECTION_POLICY_DELAY); ConstantReconnectionPolicy policy = new ConstantReconnectionPolicy(Long.parseLong(constantReconnectionPolicyDelay)); builder = builder.withReconnectionPolicy(policy); break; } case "ExponentialReconnectionPolicy": { String exponentialReconnectionPolicyBaseDelay = properties.getProperty(CassandraStoreParameters.EXPONENTIAL_RECONNECTION_POLICY_BASE_DELAY); String exponentialReconnectionPolicyMaxDelay = properties.getProperty(CassandraStoreParameters.EXPONENTIAL_RECONNECTION_POLICY_MAX_DELAY); ExponentialReconnectionPolicy policy = new ExponentialReconnectionPolicy(Long.parseLong(exponentialReconnectionPolicyBaseDelay), Long.parseLong(exponentialReconnectionPolicyMaxDelay)); builder = builder.withReconnectionPolicy(policy); break; } default: LOG.error("Unsupported reconnection policy : {} ", reconnectionPolicy); } } return builder; }
reconnectionPolicy = new ExponentialReconnectionPolicy(baseDelay.longValue(), maxDelay.longValue());
@Inject public CassandraSessionImpl(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.hostname") String hostname, @Named("cassandra.port") int port, @Named("cassandra.compression") String compression, @Named("cassandra.username") String username, @Named("cassandra.password") String password, @Named("cassandra.ssl") boolean ssl) { checkNotNull(keyspace, "keyspace argument"); checkNotNull(hostname, "hostname argument"); checkArgument(port > 0 && port < 65535, "not a valid port number: %d", port); checkNotNull(compression, "compression argument"); LOG.info("Setting up session with {}:{} using compression {}", hostname, port, compression.toUpperCase()); Builder builder = Cluster .builder() .withPort(port) .addContactPoints(hostname.split(",")) .withReconnectionPolicy(new ExponentialReconnectionPolicy(1000, 2 * 60 * 1000)) .withCompression(Compression.valueOf(compression.toUpperCase())); if (username != null && password != null) { LOG.info("Using username: {} and password: XXXXXXXX", username); builder.withCredentials(username, password); } if (ssl) { LOG.info("Enabling SSL."); builder.withSSL(); } m_session = builder.build().connect(keyspace); }
@Inject public CassandraSessionImpl(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.hostname") String hostname, @Named("cassandra.port") int port, @Named("cassandra.compression") String compression, @Named("cassandra.username") String username, @Named("cassandra.password") String password, @Named("cassandra.ssl") boolean ssl) { checkNotNull(keyspace, "keyspace argument"); checkNotNull(hostname, "hostname argument"); checkArgument(port > 0 && port < 65535, "not a valid port number: %d", port); checkNotNull(compression, "compression argument"); LOG.info("Setting up session with {}:{} using compression {}", hostname, port, compression.toUpperCase()); Builder builder = Cluster .builder() .withPort(port) .addContactPoints(hostname.split(",")) .withReconnectionPolicy(new ExponentialReconnectionPolicy(1000, 2 * 60 * 1000)) .withCompression(Compression.valueOf(compression.toUpperCase())); if (username != null && password != null) { LOG.info("Using username: {} and password: XXXXXXXX", username); builder.withCredentials(username, password); } if (ssl) { LOG.info("Enabling SSL."); builder.withSSL(); } m_session = builder.build().connect(keyspace); }
private Builder populateReconnectPolicy(Map<String, String> properties, Builder builder) throws DataServiceFault { String reconnectPolicyProp = properties.get(DBConstants.Cassandra.RECONNECTION_POLICY); if (reconnectPolicyProp != null) { if ("ConstantReconnectionPolicy".equals(reconnectPolicyProp)) { String constantReconnectionPolicyDelay = properties.get(DBConstants.Cassandra.CONSTANT_RECONNECTION_POLICY_DELAY); if (constantReconnectionPolicyDelay == null) { throw new DataServiceFault("constantReconnectionPolicyDelay property must be set for ConstantReconnectionPolicy"); } ConstantReconnectionPolicy policy = new ConstantReconnectionPolicy(Long.parseLong(constantReconnectionPolicyDelay)); builder = builder.withReconnectionPolicy(policy); } else if ("ExponentialReconnectionPolicy".equals(reconnectPolicyProp)) { String exponentialReconnectionPolicyBaseDelay = properties.get(DBConstants.Cassandra.EXPONENTIAL_RECONNECTION_POLICY_BASE_DELAY); if (exponentialReconnectionPolicyBaseDelay == null) { throw new DataServiceFault("exponentialReconnectionPolicyBaseDelay property must be set for ExponentialReconnectionPolicy"); } String exponentialReconnectionPolicyMaxDelay = properties.get(DBConstants.Cassandra.EXPONENTIAL_RECONNECTION_POLICY_MAX_DELAY); if (exponentialReconnectionPolicyMaxDelay == null) { throw new DataServiceFault("exponentialReconnectionPolicyMaxDelay property must be set for ExponentialReconnectionPolicy"); } ExponentialReconnectionPolicy policy = new ExponentialReconnectionPolicy(Long.parseLong(exponentialReconnectionPolicyBaseDelay), Long.parseLong(exponentialReconnectionPolicyMaxDelay)); builder = builder.withReconnectionPolicy(policy); } else { throw new DataServiceFault("Unsupported Cassandra reconnection policy: " + reconnectPolicyProp); } } return builder; }
private Cluster.Builder exponential() { return Cluster.builder() .withReconnectionPolicy(new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000)); }
public static Cluster setupCassandraClient(String []nodes) { return Cluster.builder() .withoutJMXReporting() .withoutMetrics() .addContactPoints(nodes) .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE) .withReconnectionPolicy(new ExponentialReconnectionPolicy(100L, TimeUnit.MINUTES.toMillis(5))) .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) .build(); }
/** * Currently we connect just once and then reuse the connection. * We do not bother with closing the connection. * * It is normal to use one Session per DB. The Session is thread safe. */ private void connect() { if (cluster == null) { log.info("Connecting to Cassandra server on " + this.dbHost + " at port " + this.dbPort); // allow fetching as much data as present in the DB QueryOptions queryOptions = new QueryOptions(); queryOptions.setFetchSize(Integer.MAX_VALUE); queryOptions.setConsistencyLevel(ConsistencyLevel.ONE); cluster = Cluster.builder() .addContactPoint(this.dbHost) .withPort(this.dbPort) .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) .withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 30000)) .withQueryOptions(queryOptions) .withCredentials(this.dbUser, this.dbPassword) .build(); } if (session == null) { log.info("Connecting to Cassandra DB with name " + this.dbName); session = cluster.connect(dbName); } }
.withPort(cassandraConf.getPort()) .withRetryPolicy(cassandraConf.getRetryPolicy()) .withReconnectionPolicy(new ExponentialReconnectionPolicy( cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs()))