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)
.withQueryOptions(queryOptions) .withSocketOptions(socketOptions) .withReconnectionPolicy(Policies.defaultReconnectionPolicy())
.setConnectTimeoutMillis(readTimeout) .setReadTimeoutMillis(reconnectInterval)) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build(); try {
builder.withReconnectionPolicy(reconnectionPolicy);
.withReconnectionPolicy(new ConstantReconnectionPolicy(10000)) .build();
.addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) .withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions)
.setConnectTimeoutMillis(readTimeout) .setReadTimeoutMillis(reconnectInterval)) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build(); try {
.withPort(ccm().getBinaryPort()) .withLoadBalancingPolicy(loadBalancingPolicy) .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) .build()); cluster.connect();
Cluster.builder() .addContactPoints(hosts.get(0).address, hosts.get(1).address) .withReconnectionPolicy(reconnectionPolicy) .build(); try {
.withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build();
.addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .withReconnectionPolicy(reconnectionPolicy) .withLoadBalancingPolicy(loadBalancingPolicy) .build());
@CCMConfig(dirtiesContext = true, numberOfNodes = 2, createCluster = false) @Test(groups = "long") public void should_cancel_reconnection_attempts() throws InterruptedException { // Stop a node and cancel the reconnection attempts to it CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .withReconnectionPolicy(reconnectionPolicy) .build()); cluster.connect(); // Stop a node and cancel the reconnection attempts to it ccm().stop(2); Host host2 = TestUtils.findHost(cluster, 2); host2.getReconnectionAttemptFuture().cancel(false); // The reconnection count should not vary over time anymore int initialCount = reconnectionPolicy.count.get(); TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2); assertThat(reconnectionPolicy.count.get()).isEqualTo(initialCount); // Restart the node, which will trigger an UP notification ccm().start(2); ccm().waitForUp(2); // The driver should now see the node as UP again assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); }
@CCMConfig(dirtiesContext = true, numberOfNodes = 2, createCluster = false) @Test(groups = "long") public void should_reconnect_after_full_connectivity_loss() throws InterruptedException { Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) .build()); cluster.connect(); assertThat(cluster).usesControlHost(1); // Stop all nodes. We won't get notifications anymore, so the only mechanism to // reconnect is the background reconnection attempts. ccm().stop(2); ccm().stop(1); ccm().waitForDown(2); ccm().start(2); ccm().waitForUp(2); assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); // Give the control connection a few moments to reconnect TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2); assertThat(cluster).usesControlHost(2); }
private Cluster.Builder constant() { return Cluster.builder().withReconnectionPolicy(new ConstantReconnectionPolicy(10 * 1000)); }
private void createCluster(int core, int max) { PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max); SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000); cluster = Cluster.builder() .addContactPoints(scassandra.address(1).getAddress()) .withPort(scassandra.getBinaryPort()) .withQueryOptions(nonDebouncingQueryOptions()) .withPoolingOptions(poolingOptions) .withSocketOptions(socketOptions) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build(); cluster.connect(); }
private Cluster.Builder exponential() { return Cluster.builder() .withReconnectionPolicy(new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000)); }
@Override public Cluster.Builder createClusterBuilder() { channelMonitor = register(new SocketChannelMonitor()); PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 8, 8); return Cluster.builder() .withPoolingOptions(poolingOptions) .withNettyOptions(channelMonitor.nettyOptions()) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)); }
builder = builder.withReconnectionPolicy(reconnectionPlc);
.withPort(cassandraConf.getPort()) .withRetryPolicy(cassandraConf.getRetryPolicy()) .withReconnectionPolicy(new ExponentialReconnectionPolicy( cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs()))