com.netflix.astyanax.connectionpool.impl.ConnectionPoolType Java Examples
The following examples show how to use
com.netflix.astyanax.connectionpool.impl.ConnectionPoolType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstanceDataDAOCassandra.java From Raigad with Apache License 2.0 | 6 votes |
private AstyanaxContext<Keyspace> initWithThriftDriverWithExternalHostsSupplier() { logger.info("Boot cluster (BOOT_CLUSTER) is {}, keyspace name (KS_NAME) is {}", BOOT_CLUSTER, KS_NAME); return new AstyanaxContext.Builder() .forCluster(BOOT_CLUSTER) .forKeyspace(KS_NAME) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.DISCOVERY_SERVICE) .setConnectionPoolType( ConnectionPoolType.ROUND_ROBIN)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl( "MyConnectionPool") .setMaxConnsPerHost(3) .setPort(thriftPortForAstyanax)) .withHostSupplier(getSupplier()) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); }
Example #2
Source File: TestStaashModule.java From staash with Apache License 2.0 | 5 votes |
@Provides @Named("astmetaks") @Singleton Keyspace provideKeyspace() { AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder() .forCluster("test cluster") .forKeyspace(MetaConstants.META_KEY_SPACE) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.NONE) .setConnectionPoolType( ConnectionPoolType.ROUND_ROBIN) .setTargetCassandraVersion("1.2") .setCqlVersion("3.0.0")) // .withHostSupplier(hs.getSupplier(clustername)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("localpool" + "_" + MetaConstants.META_KEY_SPACE) .setSocketTimeout(30000) .setMaxTimeoutWhenExhausted(20000) .setMaxConnsPerHost(3).setInitConnsPerHost(1) .setSeeds("localhost"+":"+"9160")) //uncomment for localhost // .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); keyspaceContext.start(); Keyspace keyspace; keyspace = keyspaceContext.getClient(); return keyspace; }
Example #3
Source File: PaasPropertiesModule.java From staash with Apache License 2.0 | 5 votes |
@Provides @Named("astmetaks") Keyspace provideKeyspace(@Named("staash.metacluster") String clustername,EurekaAstyanaxHostSupplier hs) { String clusterNameOnly = ""; String[] clusterinfo = clustername.split(":"); if (clusterinfo != null && clusterinfo.length == 2) { clusterNameOnly = clusterinfo[0]; } else { clusterNameOnly = clustername; } AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder() .forCluster(clusterNameOnly) .forKeyspace(MetaConstants.META_KEY_SPACE) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE) .setConnectionPoolType( ConnectionPoolType.TOKEN_AWARE) .setDiscoveryDelayInSeconds(60) .setTargetCassandraVersion("1.2") .setCqlVersion("3.0.0")) .withHostSupplier(hs.getSupplier(clustername)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(clusterNameOnly + "_" + MetaConstants.META_KEY_SPACE) .setSocketTimeout(11000) .setConnectTimeout(2000) .setMaxConnsPerHost(10).setInitConnsPerHost(3)) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); keyspaceContext.start(); Keyspace keyspace; keyspace = keyspaceContext.getClient(); return keyspace; }
Example #4
Source File: CassandraClusterHolder.java From staash with Apache License 2.0 | 5 votes |
/** * Register a keyspace such that a client is created for it and it is now accessible to * this instance * * @param keyspaceName * @throws AlreadyExistsException */ public synchronized void registerKeyspace(String keyspaceName) throws AlreadyExistsException { Preconditions.checkNotNull(keyspaceName); if (keyspaces.containsKey(keyspaceName)) { throw new AlreadyExistsException("keyspace", keyspaceName); } CassandraKeyspaceHolder keyspace = new CassandraKeyspaceHolder(new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(keyspaceName) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN) .setDiscoveryDelayInSeconds(60000)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl( clusterName + "_" + keyspaceName) .setSeeds("localhost:9160")) .withConnectionPoolMonitor(new Slf4jConnectionPoolMonitorImpl()) .buildKeyspace(ThriftFamilyFactory.getInstance())); try { keyspace.initialize(); } finally { keyspaces.put(keyspaceName, keyspace); } }
Example #5
Source File: DefaultAstyanaxConfigurationProvider.java From staash with Apache License 2.0 | 5 votes |
@Override public AstyanaxConfiguration get(String name) { return new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.NONE) .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN) .setDiscoveryDelayInSeconds(60000) .setCqlVersion("3.0.0"); }
Example #6
Source File: AstyanaxIO.java From blueflood with Apache License 2.0 | 5 votes |
private static AstyanaxConfigurationImpl createPreferredAstyanaxConfiguration() { AstyanaxConfigurationImpl astyconfig = new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.NONE) .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN); int numRetries = config.getIntegerProperty(CoreConfig.CASSANDRA_MAX_RETRIES); if (numRetries > 0) { astyconfig.setRetryPolicy(new RetryNTimes(numRetries)); } return astyconfig; }
Example #7
Source File: CassandraConfiguration.java From emodb with Apache License 2.0 | 4 votes |
private AstyanaxContext.Builder newAstyanaxBuilder(String name, ConnectionPoolConfiguration poolConfig, MetricRegistry metricRegistry) { performHostDiscovery(metricRegistry); LatencyScoreStrategy latencyScoreStrategy = _latencyAware ? new EmaLatencyScoreStrategyImpl(_latencyAwareWindowSize) : new EmptyLatencyScoreStrategyImpl(); ConnectionPoolConfigurationImpl poolConfiguration = new ConnectionPoolConfigurationImpl(name) .setLocalDatacenter(_dataCenter) .setSeeds(_seeds) .setPartitioner(_partitioner.newAstyanaxPartitioner()) .setInitConnsPerHost(poolConfig.getInitialConnectionsPerHost().or(getInitialConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_INIT_PER_PARTITION)) .setMaxConnsPerHost(poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_ACTIVE_PER_PARTITION)) .setPort(_thriftPort) .setSocketTimeout(poolConfig.getSocketTimeout().or(getSocketTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_SOCKET_TIMEOUT)) .setConnectTimeout(poolConfig.getConnectTimeout().or(getConnectTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECT_TIMEOUT)) .setMaxFailoverCount(poolConfig.getMaxFailoverCount().or(getMaxFailoverCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_FAILOVER_COUNT)) .setConnectionLimiterWindowSize(poolConfig.getConnectionLimiterWindowSize().or(getConnectionLimiterWindowSize()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_WINDOW_SIZE)) .setConnectionLimiterMaxPendingCount(poolConfig.getConnectionLimiterMaxPendingCount().or(getConnectionLimiterMaxPendingCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_MAX_PENDING_COUNT)) .setMaxPendingConnectionsPerHost(poolConfig.getMaxPendingConnectionsPerHost().or(getMaxPendingConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_PENDING_CONNECTIONS_PER_HOST)) .setMaxBlockedThreadsPerHost(poolConfig.getMaxBlockedThreadsPerHost().or(getMaxBlockedThreadsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_BLOCKED_THREADS_PER_HOST)) .setMaxTimeoutCount(poolConfig.getMaxTimeoutCount().or(getMaxTimeoutCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIMEOUT_COUNT)) .setTimeoutWindow(poolConfig.getTimeoutWindow().or(getTimeoutWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_TIMEOUT_WINDOW)) .setRetrySuspendWindow(poolConfig.getRetrySuspendWindow().or(getRetrySuspendWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_SUSPEND_WINDOW)) .setRetryDelaySlice(poolConfig.getRetryDelaySlice().or(getRetryDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_DELAY_SLICE)) .setRetryMaxDelaySlice(poolConfig.getRetryMaxDelaySlice().or(getRetryMaxDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_MAX_DELAY_SLICE)) .setMaxTimeoutWhenExhausted(poolConfig.getMaxTimeoutWhenExhausted().or(getMaxTimeoutWhenExhausted()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIME_WHEN_EXHAUSTED)) .setAuthenticationCredentials(_authenticationCredentials) .setLatencyScoreStrategy(latencyScoreStrategy); CountingConnectionPoolMonitor poolMonitor = _verboseHostLogging ? new Slf4jConnectionPoolMonitorImpl() : new CountingConnectionPoolMonitor(); AstyanaxConfigurationImpl asConfig = new AstyanaxConfigurationImpl() .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE) .setDiscoveryType(NodeDiscoveryType.TOKEN_AWARE) .setTargetCassandraVersion("1.2"); if (_maxThriftFrameSize.isPresent()) { asConfig.setMaxThriftSize((int) _maxThriftFrameSize.get().toBytes()); } return new AstyanaxContext.Builder() .withAstyanaxConfiguration(asConfig) .withConnectionPoolConfiguration(poolConfiguration) .withConnectionPoolMonitor(poolMonitor); }
Example #8
Source File: AstyanaxStoreManager.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
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 + "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()); } if (StringUtils.isNotBlank(localDatacenter)) { cpool.setLocalDatacenter(localDatacenter); log.debug("Set local datacenter: {}", cpool.getLocalDatacenter()); } AstyanaxConfigurationImpl aconf = 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(aconf) .withConnectionPoolConfiguration(cpool) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()); // Conditional context builder option: host supplier if (config.has(HOST_SUPPLIER)) { String hostSupplier = config.get(HOST_SUPPLIER); Supplier<List<Host>> supplier = null; 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; }
Example #9
Source File: AstyanaxCassandraConnection.java From staash with Apache License 2.0 | 4 votes |
private Keyspace createAstyanaxKeyspace(String clustername, String db, EurekaAstyanaxHostSupplier supplier) { String clusterNameOnly = "localhost"; String clusterPortOnly = "9160"; String[] clusterinfo = clustername.split(":"); if (clusterinfo != null && clusterinfo.length == 2) { clusterNameOnly = clusterinfo[0]; } else { clusterNameOnly = clustername; } AstyanaxContext<Keyspace> keyspaceContext; if (supplier!=null) { keyspaceContext = new AstyanaxContext.Builder() .forCluster("Casss_Paas") .forKeyspace(db) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.DISCOVERY_SERVICE) .setConnectionPoolType( ConnectionPoolType.TOKEN_AWARE) .setDiscoveryDelayInSeconds(60) .setTargetCassandraVersion("1.2") .setCqlVersion("3.0.0")) .withHostSupplier(supplier.getSupplier(clustername)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(clusterNameOnly + "_" + db) .setSocketTimeout(10000) .setPort(7102) .setMaxConnsPerHost(10).setInitConnsPerHost(3) .setSeeds(null)) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); } else { keyspaceContext = new AstyanaxContext.Builder() .forCluster(clusterNameOnly) .forKeyspace(db) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE) .setConnectionPoolType( ConnectionPoolType.TOKEN_AWARE) .setDiscoveryDelayInSeconds(60) .setTargetCassandraVersion("1.2") .setCqlVersion("3.0.0")) //.withHostSupplier(hs.getSupplier(clustername)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(clusterNameOnly + "_" + db) .setSocketTimeout(11000) .setConnectTimeout(2000) .setMaxConnsPerHost(10).setInitConnsPerHost(3) .setSeeds(clusterNameOnly+":"+clusterPortOnly)) .buildKeyspace(ThriftFamilyFactory.getInstance()); } keyspaceContext.start(); Keyspace keyspace; keyspace = keyspaceContext.getClient(); return keyspace; }
Example #10
Source File: TestPaasPropertiesModule.java From staash with Apache License 2.0 | 4 votes |
@Provides @Named("astmetaks") @Singleton Keyspace provideKeyspace(@Named("paas.metacluster") String clustername) { String clusterNameOnly = ""; String clusterPortOnly = ""; String[] clusterinfo = clustername.split(":"); if (clusterinfo != null && clusterinfo.length == 2) { clusterNameOnly = clusterinfo[0]; clusterPortOnly = clusterinfo[1]; } else { clusterNameOnly = clustername; clusterPortOnly = "9160"; } // hs = new EurekaAstyanaxHostSupplier(); AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder() .forCluster(clusterNameOnly) .forKeyspace(MetaConstants.META_KEY_SPACE) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE) .setConnectionPoolType( ConnectionPoolType.TOKEN_AWARE) .setDiscoveryDelayInSeconds(60000) .setTargetCassandraVersion("1.1") .setCqlVersion("3.0.0")) // .withHostSupplier(hs.getSupplier(clustername)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(clusterNameOnly + "_" + MetaConstants.META_KEY_SPACE) .setSocketTimeout(3000) .setMaxTimeoutWhenExhausted(2000) .setMaxConnsPerHost(3).setInitConnsPerHost(1) .setSeeds(clusterNameOnly+":"+clusterPortOnly)) //uncomment for localhost .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); keyspaceContext.start(); Keyspace keyspace; keyspace = keyspaceContext.getClient(); return keyspace; }
Example #11
Source File: AnnotatedAstyanaxConfiguration.java From staash with Apache License 2.0 | 4 votes |
@Override public ConnectionPoolType getConnectionPoolType() { // TODO Auto-generated method stub return null; }