use of com.datastax.driver.core.policies.RetryPolicy in project spring-boot by spring-projects.
the class CassandraAutoConfiguration method cluster.
@Bean
@ConditionalOnMissingBean
public Cluster cluster() {
CassandraProperties properties = this.properties;
Cluster.Builder builder = Cluster.builder().withClusterName(properties.getClusterName()).withPort(properties.getPort());
if (properties.getUsername() != null) {
builder.withCredentials(properties.getUsername(), properties.getPassword());
}
if (properties.getCompression() != null) {
builder.withCompression(properties.getCompression());
}
if (properties.getLoadBalancingPolicy() != null) {
LoadBalancingPolicy policy = instantiate(properties.getLoadBalancingPolicy());
builder.withLoadBalancingPolicy(policy);
}
builder.withQueryOptions(getQueryOptions());
if (properties.getReconnectionPolicy() != null) {
ReconnectionPolicy policy = instantiate(properties.getReconnectionPolicy());
builder.withReconnectionPolicy(policy);
}
if (properties.getRetryPolicy() != null) {
RetryPolicy policy = instantiate(properties.getRetryPolicy());
builder.withRetryPolicy(policy);
}
builder.withSocketOptions(getSocketOptions());
if (properties.isSsl()) {
builder.withSSL();
}
String points = properties.getContactPoints();
builder.addContactPoints(StringUtils.commaDelimitedListToStringArray(points));
customize(builder);
return builder.build();
}
use of com.datastax.driver.core.policies.RetryPolicy in project tutorials by eugenp.
the class CassandraConfiguration method cluster.
@Bean
public Cluster cluster(CassandraProperties properties) {
Cluster.Builder builder = Cluster.builder().withClusterName(properties.getClusterName()).withProtocolVersion(protocolVersion).withPort(getPort(properties));
if (properties.getUsername() != null) {
builder.withCredentials(properties.getUsername(), properties.getPassword());
}
if (properties.getCompression() != null) {
builder.withCompression(properties.getCompression());
}
if (properties.getLoadBalancingPolicy() != null) {
LoadBalancingPolicy policy = instantiate(properties.getLoadBalancingPolicy());
builder.withLoadBalancingPolicy(policy);
}
builder.withQueryOptions(getQueryOptions(properties));
if (properties.getReconnectionPolicy() != null) {
ReconnectionPolicy policy = instantiate(properties.getReconnectionPolicy());
builder.withReconnectionPolicy(policy);
}
if (properties.getRetryPolicy() != null) {
RetryPolicy policy = instantiate(properties.getRetryPolicy());
builder.withRetryPolicy(policy);
}
builder.withSocketOptions(getSocketOptions(properties));
if (properties.isSsl()) {
builder.withSSL();
}
String points = properties.getContactPoints();
builder.addContactPoints(StringUtils.commaDelimitedListToStringArray(points));
Cluster cluster = builder.build();
cluster.getConfiguration().getCodecRegistry().register(LocalDateCodec.instance).register(CustomZonedDateTimeCodec.instance);
if (metricRegistry != null) {
cluster.init();
metricRegistry.registerAll(cluster.getMetrics().getRegistry());
}
return cluster;
}
use of com.datastax.driver.core.policies.RetryPolicy in project eventapis by kloiasoft.
the class CassandraSession method cluster.
/* private Cluster cluster() {
Cluster.Builder builder = Cluster.builder();
Arrays.stream(eventStoreConfig.getContactPoints().split(";")).forEach(s -> {
String[] hostPort = s.split(":");
builder.addContactPointsWithPorts(new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1])));
});
builder.withPoolingOptions(eventStoreConfig.getPoolingOptions());
Cluster cluster = builder.build();
cluster.register(QueryLogger.builder().build());
return cluster.init();
}*/
private Cluster cluster() {
EventStoreConfig properties = eventStoreConfig;
Cluster.Builder builder = Cluster.builder().withClusterName(properties.getClusterName()).withPort(properties.getPort());
if (properties.getUsername() != null) {
builder.withCredentials(properties.getUsername(), properties.getPassword());
}
if (properties.getCompression() != null) {
builder.withCompression(properties.getCompression());
}
if (properties.getLoadBalancingPolicy() != null) {
LoadBalancingPolicy policy = instantiate(properties.getLoadBalancingPolicy());
builder.withLoadBalancingPolicy(policy);
}
builder.withQueryOptions(getQueryOptions());
if (properties.getReconnectionPolicy() != null) {
ReconnectionPolicy policy = instantiate(properties.getReconnectionPolicy());
builder.withReconnectionPolicy(policy);
}
if (properties.getRetryPolicy() != null) {
RetryPolicy policy = instantiate(properties.getRetryPolicy());
builder.withRetryPolicy(policy);
}
builder.withSocketOptions(getSocketOptions());
if (properties.isSsl()) {
builder.withSSL();
}
String points = properties.getContactPoints();
builder.addContactPointsWithPorts(Arrays.stream(StringUtils.split(points, ",")).map(s -> {
String[] split = s.split(":");
String host = split[0];
int port = properties.getPort();
try {
port = Integer.parseInt(split[1]);
} catch (Exception e) {
log.trace(e.getMessage());
}
return new InetSocketAddress(host, port);
}).collect(Collectors.toList()));
return builder.build();
}
use of com.datastax.driver.core.policies.RetryPolicy 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.policies.RetryPolicy in project jhipster-sample-app-cassandra by jhipster.
the class CassandraConfiguration method cluster.
@Bean
public Cluster cluster(CassandraProperties properties) {
Cluster.Builder builder = Cluster.builder().withClusterName(properties.getClusterName()).withProtocolVersion(protocolVersion).withPort(getPort(properties));
if (properties.getUsername() != null) {
builder.withCredentials(properties.getUsername(), properties.getPassword());
}
if (properties.getCompression() != null) {
builder.withCompression(properties.getCompression());
}
if (properties.getLoadBalancingPolicy() != null) {
LoadBalancingPolicy policy = instantiate(properties.getLoadBalancingPolicy());
builder.withLoadBalancingPolicy(policy);
}
builder.withQueryOptions(getQueryOptions(properties));
if (properties.getReconnectionPolicy() != null) {
ReconnectionPolicy policy = instantiate(properties.getReconnectionPolicy());
builder.withReconnectionPolicy(policy);
}
if (properties.getRetryPolicy() != null) {
RetryPolicy policy = instantiate(properties.getRetryPolicy());
builder.withRetryPolicy(policy);
}
builder.withSocketOptions(getSocketOptions(properties));
if (properties.isSsl()) {
builder.withSSL();
}
builder.addContactPoints(StringUtils.toStringArray(properties.getContactPoints()));
Cluster cluster = builder.build();
TupleType tupleType = cluster.getMetadata().newTupleType(DataType.timestamp(), DataType.varchar());
cluster.getConfiguration().getCodecRegistry().register(LocalDateCodec.instance).register(InstantCodec.instance).register(new ZonedDateTimeCodec(tupleType));
if (metricRegistry != null) {
cluster.init();
metricRegistry.registerAll(cluster.getMetrics().getRegistry());
}
return cluster;
}
Aggregations