use of com.datastax.driver.core.SocketOptions in project cassandra by apache.
the class CqlConfigHelper method getCluster.
public static Cluster getCluster(String[] hosts, Configuration conf, int port) {
Optional<AuthProvider> authProvider = getAuthProvider(conf);
Optional<SSLOptions> sslOptions = getSSLOptions(conf);
Optional<Integer> protocolVersion = getProtocolVersion(conf);
LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts);
SocketOptions socketOptions = getReadSocketOptions(conf);
QueryOptions queryOptions = getReadQueryOptions(conf);
PoolingOptions poolingOptions = getReadPoolingOptions(conf);
Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port).withCompression(ProtocolOptions.Compression.NONE);
if (authProvider.isPresent())
builder.withAuthProvider(authProvider.get());
if (sslOptions.isPresent())
builder.withSSL(sslOptions.get());
if (protocolVersion.isPresent()) {
builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get()));
}
builder.withLoadBalancingPolicy(loadBalancingPolicy).withSocketOptions(socketOptions).withQueryOptions(queryOptions).withPoolingOptions(poolingOptions);
return builder.build();
}
use of com.datastax.driver.core.SocketOptions in project beam by apache.
the class CassandraIO method getCluster.
/**
* Get a Cassandra cluster using hosts and port.
*/
static Cluster getCluster(ValueProvider<List<String>> hosts, ValueProvider<Integer> port, ValueProvider<String> username, ValueProvider<String> password, ValueProvider<String> localDc, ValueProvider<String> consistencyLevel, ValueProvider<Integer> connectTimeout, ValueProvider<Integer> readTimeout) {
Cluster.Builder builder = Cluster.builder().addContactPoints(hosts.get().toArray(new String[0])).withPort(port.get());
if (username != null) {
builder.withAuthProvider(new PlainTextAuthProvider(username.get(), password.get()));
}
DCAwareRoundRobinPolicy.Builder dcAwarePolicyBuilder = new DCAwareRoundRobinPolicy.Builder();
if (localDc != null) {
dcAwarePolicyBuilder.withLocalDc(localDc.get());
}
builder.withLoadBalancingPolicy(new TokenAwarePolicy(dcAwarePolicyBuilder.build()));
if (consistencyLevel != null) {
builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel.get())));
}
SocketOptions socketOptions = new SocketOptions();
builder.withSocketOptions(socketOptions);
if (connectTimeout != null) {
socketOptions.setConnectTimeoutMillis(connectTimeout.get());
}
if (readTimeout != null) {
socketOptions.setReadTimeoutMillis(readTimeout.get());
}
return builder.build();
}
use of com.datastax.driver.core.SocketOptions in project indy by Commonjava.
the class CassandraClient method init.
@PostConstruct
private void init() {
if (!config.isEnabled()) {
logger.info("Cassandra client not enabled");
return;
}
host = config.getCassandraHost();
port = config.getCassandraPort();
SocketOptions socketOptions = new SocketOptions();
socketOptions.setConnectTimeoutMillis(config.getConnectTimeoutMillis());
socketOptions.setReadTimeoutMillis(config.getReadTimeoutMillis());
Cluster.Builder builder = Cluster.builder().withoutJMXReporting().withRetryPolicy(new ConfigurableRetryPolicy(config.getReadRetries(), config.getWriteRetries())).addContactPoint(host).withPort(port).withSocketOptions(socketOptions);
username = config.getCassandraUser();
String password = config.getCassandraPass();
if (isNotBlank(username) && isNotBlank(password)) {
logger.info("Build with credentials, user: {}, pass: ****", username);
builder.withCredentials(username, password);
}
cluster = builder.build();
}
use of com.datastax.driver.core.SocketOptions in project spring-cloud-connectors by spring-cloud.
the class CassandraClusterCreatorTest method shouldCreateClusterWithConfig.
@Test
public void shouldCreateClusterWithConfig() throws Exception {
CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142);
CassandraClusterConfig config = new CassandraClusterConfig();
config.setCompression(ProtocolOptions.Compression.NONE);
config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234));
config.setQueryOptions(new QueryOptions());
config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
config.setLoadBalancingPolicy(new RoundRobinPolicy());
config.setReconnectionPolicy(new ConstantReconnectionPolicy(1));
config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
config.setSocketOptions(new SocketOptions());
Cluster cluster = creator.create(info, config);
Configuration configuration = cluster.getConfiguration();
assertThat(configuration.getProtocolOptions().getCompression(), is(config.getCompression()));
assertThat(configuration.getQueryOptions(), is(config.getQueryOptions()));
assertThat(configuration.getSocketOptions(), is(config.getSocketOptions()));
Policies policies = configuration.getPolicies();
assertThat(policies.getLoadBalancingPolicy(), is(config.getLoadBalancingPolicy()));
assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy()));
assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy()));
}
use of com.datastax.driver.core.SocketOptions in project spring-cloud-connectors by spring-cloud.
the class CassandraClusterConfigWithServiceConfig method testClusterFactoryWithConfig.
@Bean(name = "my-service")
public Cluster testClusterFactoryWithConfig() {
CassandraClusterConfig config = new CassandraClusterConfig();
SocketOptions socketOptions = new SocketOptions();
socketOptions.setSendBufferSize(12345);
config.setSocketOptions(socketOptions);
return connectionFactory().cluster("my-service", config);
}
Aggregations