use of com.netflix.astyanax.connectionpool.NodeDiscoveryType in project titan by thinkaurelius.
the class AstyanaxStoreManager method getContextBuilder.
private AstyanaxContext.Builder getContextBuilder(Configuration config, int maxConnsPerHost, String usedFor) {
final ConnectionPoolType poolType = ConnectionPoolType.valueOf(config.getString(CONNECTION_POOL_TYPE_KEY, CONNECTION_POOL_TYPE_DEFAULT));
final NodeDiscoveryType discType = NodeDiscoveryType.valueOf(config.getString(NODE_DISCOVERY_TYPE_KEY, NODE_DISCOVERY_TYPE_DEFAULT));
final int maxConnections = config.getInt(MAX_CONNECTIONS_KEY, MAX_CONNECTIONS_DEFAULT);
final int maxOperationsPerConnection = config.getInt(MAX_OPERATIONS_PER_CONNECTION_KEY, MAX_OPERATIONS_PER_CONNECTION_DEFAULT);
ConnectionPoolConfigurationImpl cpool = new ConnectionPoolConfigurationImpl(usedFor + "TitanConnectionPool").setPort(port).setMaxOperationsPerConnection(maxOperationsPerConnection).setMaxConnsPerHost(maxConnsPerHost).setRetryDelaySlice(retryDelaySlice).setRetryMaxDelaySlice(retryMaxDelaySlice).setRetrySuspendWindow(retrySuspendWindow).setSocketTimeout(connectionTimeout).setConnectTimeout(connectionTimeout).setSeeds(StringUtils.join(hostnames, ","));
if (null != retryBackoffStrategy) {
cpool.setRetryBackoffStrategy(retryBackoffStrategy);
log.debug("Custom RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
} else {
log.debug("Default RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
}
AstyanaxConfigurationImpl aconf = new AstyanaxConfigurationImpl().setConnectionPoolType(poolType).setDiscoveryType(discType).setTargetCassandraVersion("1.2");
if (0 < maxConnections) {
cpool.setMaxConns(maxConnections);
}
if (hasAuthentication()) {
cpool.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password));
}
String hostSupplier = config.getString(ASTYANAX_HOST_SUPPLIER_KEY);
Supplier<List<Host>> supplier = null;
if (hostSupplier != null) {
try {
supplier = (Supplier<List<Host>>) Class.forName(hostSupplier).newInstance();
} catch (Exception e) {
log.warn("Problem with host supplier class " + hostSupplier + ", going to use default.", e);
}
}
return new AstyanaxContext.Builder().forCluster(clusterName).forKeyspace(keySpaceName).withAstyanaxConfiguration(aconf).withConnectionPoolConfiguration(cpool).withHostSupplier(supplier).withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
}
use of com.netflix.astyanax.connectionpool.NodeDiscoveryType in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method getContextBuilder.
private AstyanaxContext.Builder getContextBuilder(Configuration config, int maxConnsPerHost, String usedFor) {
final ConnectionPoolType poolType = ConnectionPoolType.valueOf(config.get(CONNECTION_POOL_TYPE));
final NodeDiscoveryType discType = NodeDiscoveryType.valueOf(config.get(NODE_DISCOVERY_TYPE));
final int maxConnections = config.get(MAX_CONNECTIONS);
final int maxOperationsPerConnection = config.get(MAX_OPERATIONS_PER_CONNECTION);
final int connectionTimeout = (int) connectionTimeoutMS.toMillis();
ConnectionPoolConfigurationImpl cpool = new ConnectionPoolConfigurationImpl(usedFor + "JanusGraphConnectionPool").setPort(port).setMaxOperationsPerConnection(maxOperationsPerConnection).setMaxConnsPerHost(maxConnsPerHost).setRetryDelaySlice(retryDelaySlice).setRetryMaxDelaySlice(retryMaxDelaySlice).setRetrySuspendWindow(retrySuspendWindow).setSocketTimeout(connectionTimeout).setConnectTimeout(connectionTimeout).setSeeds(StringUtils.join(hostnames, ","));
if (null != retryBackoffStrategy) {
cpool.setRetryBackoffStrategy(retryBackoffStrategy);
log.debug("Custom RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
} else {
log.debug("Default RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
}
if (StringUtils.isNotBlank(localDatacenter)) {
cpool.setLocalDatacenter(localDatacenter);
log.debug("Set local datacenter: {}", cpool.getLocalDatacenter());
}
AstyanaxConfigurationImpl astyanaxConfiguration = new AstyanaxConfigurationImpl().setConnectionPoolType(poolType).setDiscoveryType(discType).setTargetCassandraVersion("1.2").setMaxThriftSize(thriftFrameSizeBytes);
if (0 < maxConnections) {
cpool.setMaxConns(maxConnections);
}
if (hasAuthentication()) {
cpool.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password));
}
if (config.get(SSL_ENABLED)) {
cpool.setSSLConnectionContext(new SSLConnectionContext(config.get(SSL_TRUSTSTORE_LOCATION), config.get(SSL_TRUSTSTORE_PASSWORD)));
}
AstyanaxContext.Builder ctxBuilder = new AstyanaxContext.Builder();
// Standard context builder options
ctxBuilder.forCluster(clusterName).forKeyspace(keySpaceName).withAstyanaxConfiguration(astyanaxConfiguration).withConnectionPoolConfiguration(cpool).withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
// Conditional context builder option: host supplier
if (config.has(HOST_SUPPLIER)) {
String hostSupplier = config.get(HOST_SUPPLIER);
final Supplier<List<Host>> supplier;
if (hostSupplier != null) {
try {
supplier = (Supplier<List<Host>>) Class.forName(hostSupplier).newInstance();
ctxBuilder.withHostSupplier(supplier);
} catch (Exception e) {
log.warn("Problem with host supplier class " + hostSupplier + ", going to use default.", e);
}
}
}
return ctxBuilder;
}
Aggregations