use of com.datastax.driver.core.PoolingOptions 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.PoolingOptions in project storm by apache.
the class CassandraBackingMap method prepare.
public void prepare() {
LOG.info("Preparing state for {}", options.toString());
Preconditions.checkNotNull(options.getMapper, "CassandraBackingMap.Options should have getMapper");
Preconditions.checkNotNull(options.putMapper, "CassandraBackingMap.Options should have putMapper");
client = options.clientProvider.getClient(conf);
session = client.connect();
if (options.maxParallelism == null || options.maxParallelism <= 0) {
PoolingOptions po = session.getCluster().getConfiguration().getPoolingOptions();
Integer maxRequestsPerHost = Math.min(po.getMaxConnectionsPerHost(HostDistance.LOCAL) * po.getMaxRequestsPerConnection(HostDistance.LOCAL), po.getMaxConnectionsPerHost(HostDistance.REMOTE) * po.getMaxRequestsPerConnection(HostDistance.REMOTE));
options.maxParallelism = maxRequestsPerHost / 2;
LOG.info("Parallelism default set to {}", options.maxParallelism);
}
throttle = new Semaphore(options.maxParallelism, false);
this.getResultMapper = new TridentAyncCQLResultSetValuesMapper(options.stateMapper.getStateFields(), throttle);
this.putResultMapper = new TridentAyncCQLResultSetValuesMapper(null, throttle);
}
use of com.datastax.driver.core.PoolingOptions 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.PoolingOptions in project zipkin by openzipkin.
the class SessionFactoryTest method maxConnections_setsMaxConnectionsPerDatacenterLocalHost.
@Test
public void maxConnections_setsMaxConnectionsPerDatacenterLocalHost() {
PoolingOptions poolingOptions = buildCluster(CassandraStorage.builder().maxConnections(16).build()).getConfiguration().getPoolingOptions();
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(16);
}
use of com.datastax.driver.core.PoolingOptions 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;
}
Aggregations