use of com.datastax.driver.core.SocketOptions in project gora by apache.
the class CassandraClient method populateSocketOptions.
private Cluster.Builder populateSocketOptions(Properties properties, Cluster.Builder builder) {
String connectionTimeoutMillisProp = properties.getProperty(CassandraStoreParameters.CONNECTION_TIMEOUT_MILLIS);
String keepAliveProp = properties.getProperty(CassandraStoreParameters.KEEP_ALIVE);
String readTimeoutMillisProp = properties.getProperty(CassandraStoreParameters.READ_TIMEOUT_MILLIS);
String receiveBufferSizeProp = properties.getProperty(CassandraStoreParameters.RECEIVER_BUFFER_SIZE);
String reuseAddress = properties.getProperty(CassandraStoreParameters.REUSE_ADDRESS);
String sendBufferSize = properties.getProperty(CassandraStoreParameters.SEND_BUFFER_SIZE);
String soLinger = properties.getProperty(CassandraStoreParameters.SO_LINGER);
String tcpNoDelay = properties.getProperty(CassandraStoreParameters.TCP_NODELAY);
SocketOptions options = new SocketOptions();
if (connectionTimeoutMillisProp != null) {
options.setConnectTimeoutMillis(Integer.parseInt(connectionTimeoutMillisProp));
}
if (keepAliveProp != null) {
options.setKeepAlive(Boolean.parseBoolean(keepAliveProp));
}
if (readTimeoutMillisProp != null) {
options.setReadTimeoutMillis(Integer.parseInt(readTimeoutMillisProp));
}
if (receiveBufferSizeProp != null) {
options.setReceiveBufferSize(Integer.parseInt(receiveBufferSizeProp));
}
if (reuseAddress != null) {
options.setReuseAddress(Boolean.parseBoolean(reuseAddress));
}
if (sendBufferSize != null) {
options.setSendBufferSize(Integer.parseInt(sendBufferSize));
}
if (soLinger != null) {
options.setSoLinger(Integer.parseInt(soLinger));
}
if (tcpNoDelay != null) {
options.setTcpNoDelay(Boolean.parseBoolean(tcpNoDelay));
}
return builder.withSocketOptions(options);
}
use of com.datastax.driver.core.SocketOptions in project beam by apache.
the class HIFIOWithEmbeddedCassandraTest method startCassandra.
@BeforeClass
public static void startCassandra() throws Exception {
//Start the Embedded Cassandra Service
cassandra.start();
final SocketOptions socketOptions = new SocketOptions();
// Setting this to 0 disables read timeouts.
socketOptions.setReadTimeoutMillis(0);
// This defaults to 5 s. Increase to a minute.
socketOptions.setConnectTimeoutMillis(60 * 1000);
cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST).withClusterName("beam").withSocketOptions(socketOptions).build();
session = cluster.connect();
createCassandraData();
}
use of com.datastax.driver.core.SocketOptions in project cas by apereo.
the class DefaultCassandraSessionFactory method initializeCassandraCluster.
private static Cluster initializeCassandraCluster(final BaseCassandraProperties cassandra) {
final Cluster cluster;
final PoolingOptions poolingOptions = new PoolingOptions().setMaxRequestsPerConnection(HostDistance.LOCAL, cassandra.getMaxRequestsPerConnection()).setConnectionsPerHost(HostDistance.LOCAL, cassandra.getCoreConnections(), cassandra.getMaxConnections());
final DCAwareRoundRobinPolicy.Builder dcPolicyBuilder = DCAwareRoundRobinPolicy.builder();
if (StringUtils.isNotBlank(cassandra.getLocalDc())) {
dcPolicyBuilder.withLocalDc(cassandra.getLocalDc());
}
final TokenAwarePolicy loadBalancingPolicy = new TokenAwarePolicy(dcPolicyBuilder.build(), cassandra.isShuffleReplicas());
final SocketOptions socketOptions = new SocketOptions().setConnectTimeoutMillis(cassandra.getConnectTimeoutMillis()).setReadTimeoutMillis(cassandra.getReadTimeoutMillis());
final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getConsistencyLevel())).setSerialConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getSerialConsistencyLevel()));
final RetryPolicy retryPolicy = RetryPolicyType.valueOf(cassandra.getRetryPolicy()).getRetryPolicy();
final Cluster.Builder builder = Cluster.builder().withCredentials(cassandra.getUsername(), cassandra.getPassword()).withPoolingOptions(poolingOptions).withProtocolVersion(ProtocolVersion.valueOf(cassandra.getProtocolVersion())).withLoadBalancingPolicy(loadBalancingPolicy).withSocketOptions(socketOptions).withRetryPolicy(new LoggingRetryPolicy(retryPolicy)).withCompression(ProtocolOptions.Compression.valueOf(cassandra.getCompression())).withPort(cassandra.getPort()).withQueryOptions(queryOptions);
Arrays.stream(StringUtils.split(cassandra.getContactPoints(), ',')).forEach(contactPoint -> builder.addContactPoint(StringUtils.trim(contactPoint)));
cluster = builder.build();
if (LOGGER.isDebugEnabled()) {
cluster.getMetadata().getAllHosts().forEach(clusterHost -> LOGGER.debug("Host [{}]:\n\n\tDC: [{}]\n\tRack: [{}]\n\tVersion: [{}]\n\tDistance: [{}]\n\tUp?: [{}]\n", clusterHost.getAddress(), clusterHost.getDatacenter(), clusterHost.getRack(), clusterHost.getCassandraVersion(), loadBalancingPolicy.distance(clusterHost), clusterHost.isUp()));
}
return cluster;
}
use of com.datastax.driver.core.SocketOptions in project thingsboard by thingsboard.
the class CassandraSocketOptions method initOpts.
@PostConstruct
public void initOpts() {
opts = new SocketOptions();
opts.setConnectTimeoutMillis(connectTimeoutMillis);
opts.setReadTimeoutMillis(readTimeoutMillis);
if (keepAlive != null) {
opts.setKeepAlive(keepAlive);
}
if (reuseAddress != null) {
opts.setReuseAddress(reuseAddress);
}
if (soLinger != null) {
opts.setSoLinger(soLinger);
}
if (tcpNoDelay != null) {
opts.setTcpNoDelay(tcpNoDelay);
}
if (receiveBufferSize != null) {
opts.setReceiveBufferSize(receiveBufferSize);
}
if (sendBufferSize != null) {
opts.setSendBufferSize(sendBufferSize);
}
}
use of com.datastax.driver.core.SocketOptions in project beam by apache.
the class HadoopFormatIOCassandraTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
cassandraPort = NetworkTestHelper.getAvailableLocalPort();
cassandraNativePort = NetworkTestHelper.getAvailableLocalPort();
replacePortsInConfFile();
// Start the Embedded Cassandra Service
cassandra.start();
final SocketOptions socketOptions = new SocketOptions();
// Setting this to 0 disables read timeouts.
socketOptions.setReadTimeoutMillis(0);
// This defaults to 5 s. Increase to a minute.
socketOptions.setConnectTimeoutMillis(60 * 1000);
cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST).withClusterName("beam").withSocketOptions(socketOptions).withPort(cassandraNativePort).build();
session = cluster.connect();
createCassandraData();
}
Aggregations