Search in sources :

Example 6 with RoundRobinPolicy

use of com.datastax.driver.core.policies.RoundRobinPolicy in project cassandra-driver-mapping by valchkou.

the class SchemaSyncTest method init.

@BeforeClass
public static void init() {
    String node = "127.0.0.1";
    Builder builder = Cluster.builder();
    builder.addContactPoint(node);
    builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
    builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
    cluster = builder.build();
    session = cluster.connect();
    Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
    MappingSession.setStatementCache(cache);
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PreparedStatement(com.datastax.driver.core.PreparedStatement) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) BeforeClass(org.junit.BeforeClass)

Example 7 with RoundRobinPolicy

use of com.datastax.driver.core.policies.RoundRobinPolicy in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method init.

@BeforeClass
public static void init() {
    String node = "127.0.0.1";
    Builder builder = Cluster.builder();
    builder.addContactPoint(node);
    builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
    builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
    cluster = builder.build();
    session = cluster.connect();
    Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
    MappingSession.setStatementCache(cache);
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PreparedStatement(com.datastax.driver.core.PreparedStatement) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) BeforeClass(org.junit.BeforeClass)

Example 8 with RoundRobinPolicy

use of com.datastax.driver.core.policies.RoundRobinPolicy in project cassandra-driver-mapping by valchkou.

the class MappingSessionTest method init.

@BeforeClass
public static void init() {
    String node = "127.0.0.1";
    Builder builder = Cluster.builder();
    builder.addContactPoint(node);
    builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
    builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
    cluster = builder.build();
    session = cluster.connect();
    Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
    MappingSession.setStatementCache(cache);
}
Also used : QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) Builder(com.datastax.driver.core.Cluster.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 9 with RoundRobinPolicy

use of com.datastax.driver.core.policies.RoundRobinPolicy in project ats-framework by Axway.

the class CassandraDbProvider method connect.

/**
     * 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);
    }
}
Also used : ExponentialReconnectionPolicy(com.datastax.driver.core.policies.ExponentialReconnectionPolicy) QueryOptions(com.datastax.driver.core.QueryOptions) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy)

Aggregations

RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)9 Cluster (com.datastax.driver.core.Cluster)5 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)4 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)4 Builder (com.datastax.driver.core.Cluster.Builder)3 QueryOptions (com.datastax.driver.core.QueryOptions)3 ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)3 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)3 CacheBuilder (com.google.common.cache.CacheBuilder)3 Host (com.datastax.driver.core.Host)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 InetSocketAddress (java.net.InetSocketAddress)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 SocketOptions (com.datastax.driver.core.SocketOptions)1 ConstantSpeculativeExecutionPolicy (com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy)1 LatencyAwarePolicy (com.datastax.driver.core.policies.LatencyAwarePolicy)1 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)1