Search in sources :

Example 11 with SocketOptions

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);
}
Also used : SocketOptions(com.datastax.driver.core.SocketOptions)

Example 12 with SocketOptions

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();
}
Also used : SocketOptions(com.datastax.driver.core.SocketOptions) BeforeClass(org.junit.BeforeClass)

Example 13 with SocketOptions

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;
}
Also used : DCAwareRoundRobinPolicy(com.datastax.driver.core.policies.DCAwareRoundRobinPolicy) SocketOptions(com.datastax.driver.core.SocketOptions) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) QueryOptions(com.datastax.driver.core.QueryOptions) LoggingRetryPolicy(com.datastax.driver.core.policies.LoggingRetryPolicy) RetryPolicy(com.datastax.driver.core.policies.RetryPolicy) LoggingRetryPolicy(com.datastax.driver.core.policies.LoggingRetryPolicy)

Example 14 with SocketOptions

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);
    }
}
Also used : SocketOptions(com.datastax.driver.core.SocketOptions) PostConstruct(javax.annotation.PostConstruct)

Example 15 with SocketOptions

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();
}
Also used : SocketOptions(com.datastax.driver.core.SocketOptions) BeforeClass(org.junit.BeforeClass)

Aggregations

SocketOptions (com.datastax.driver.core.SocketOptions)16 Cluster (com.datastax.driver.core.Cluster)7 QueryOptions (com.datastax.driver.core.QueryOptions)6 PoolingOptions (com.datastax.driver.core.PoolingOptions)4 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)4 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)3 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)3 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)3 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2 SSLOptions (com.datastax.driver.core.SSLOptions)2 WhiteListPolicy (com.datastax.driver.core.policies.WhiteListPolicy)2 InetSocketAddress (java.net.InetSocketAddress)2 PostConstruct (javax.annotation.PostConstruct)2 BeforeClass (org.junit.BeforeClass)2 AuthProvider (com.datastax.driver.core.AuthProvider)1 Configuration (com.datastax.driver.core.Configuration)1 Host (com.datastax.driver.core.Host)1 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)1 Metadata (com.datastax.driver.core.Metadata)1 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)1