当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionPoolType类代码示例

本文整理汇总了Java中com.netflix.astyanax.connectionpool.impl.ConnectionPoolType的典型用法代码示例。如果您正苦于以下问题:Java ConnectionPoolType类的具体用法?Java ConnectionPoolType怎么用?Java ConnectionPoolType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionPoolType类属于com.netflix.astyanax.connectionpool.impl包,在下文中一共展示了ConnectionPoolType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupAstyanaxContext

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
private Keyspace setupAstyanaxContext(String clusterName)
{
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace("CrawlerKS")
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                            .setDiscoveryType(NodeDiscoveryType.NONE)
                            .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
            )
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("CassandraPool")
                            .setPort(9160)
                            .setMaxConnsPerHost(3)
                            .setSeeds("127.0.0.1:9160")
            )
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());


    context.start();
    return context.getClient();
}
 
开发者ID:Esquive,项目名称:iticrawler,代码行数:22,代码来源:StorageCluster.java

示例2: initWithThriftDriverWithExternalHostsSupplier

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
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());

}
 
开发者ID:Netflix,项目名称:Raigad,代码行数:23,代码来源:InstanceDataDAOCassandra.java

示例3: beforeClass

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {

    astyanaxContext =
            new AstyanaxContext.Builder()
                    .forKeyspace("timeSeriesKeyspace")
                    .withConnectionPoolConfiguration(
                            new ConnectionPoolConfigurationImpl("myCPConfig")
                                    .setSeeds("localhost")
                                    .setPort(9171))
                    .withAstyanaxConfiguration(
                            new AstyanaxConfigurationImpl()
                                    .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
                                    .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
                    .buildKeyspace(ThriftFamilyFactory.getInstance());

    keyspace = astyanaxContext.getClient();
    astyanaxContext.start();
}
 
开发者ID:iZettle,项目名称:izettle-toolbox,代码行数:20,代码来源:TimeSeriesIT.java

示例4: testCassandraContext

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
public static AstyanaxContext<Keyspace> testCassandraContext() {
    return new AstyanaxContext.Builder()
            .forCluster(CLUSTER_NAME)
            .forKeyspace(KEYSPACE_NAME)
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                    .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
                    .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN)
                    .setAsyncExecutor(Executors.newFixedThreadPool(
                            CLIENT_THREADS,
                            new ThreadFactoryBuilder().setDaemon(true)
                                    .setNameFormat("astyanax-%d")
                                    .build()
                    ))
            )
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("Atlas")
                    .setPort(PORT)
                    .setMaxBlockedThreadsPerHost(CLIENT_THREADS)
                    .setMaxConnsPerHost(CLIENT_THREADS)
                    .setMaxConns(CLIENT_THREADS * 5)
                    .setConnectTimeout(CONNECTION_TIMEOUT)
                    .setSeeds(SEEDS)
            )
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());
}
 
开发者ID:atlasapi,项目名称:atlas-deer,代码行数:26,代码来源:CassandraHelper.java

示例5: astyanaxConfiguration

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(AstyanaxConfiguration.class)
@ConfigurationProperties("cassandra")
public AstyanaxConfiguration astyanaxConfiguration(@Qualifier("cassandraAsyncExecutor") ExecutorService cassandraAsyncExecutor) {
    return new AstyanaxConfigurationImpl()
            .setDefaultReadConsistencyLevel(ConsistencyLevel.CL_LOCAL_QUORUM)
            .setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_LOCAL_QUORUM)
            .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
            .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
            .setCqlVersion("3.0.0")
            .setTargetCassandraVersion("2.0")
            .setAsyncExecutor(cassandraAsyncExecutor);
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:14,代码来源:AstyanaxComponents.java

示例6: provideKeyspace

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
@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;
    }
 
开发者ID:Netflix,项目名称:staash,代码行数:31,代码来源:TestStaashModule.java

示例7: provideKeyspace

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
@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;
}
 
开发者ID:Netflix,项目名称:staash,代码行数:37,代码来源:PaasPropertiesModule.java

示例8: registerKeyspace

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:Netflix,项目名称:staash,代码行数:37,代码来源:CassandraClusterHolder.java

示例9: get

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
@Override
public AstyanaxConfiguration get(String name) {
    return new AstyanaxConfigurationImpl()
        .setDiscoveryType(NodeDiscoveryType.NONE)
        .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN)
        .setDiscoveryDelayInSeconds(60000)
        .setCqlVersion("3.0.0");
}
 
开发者ID:Netflix,项目名称:staash,代码行数:9,代码来源:DefaultAstyanaxConfigurationProvider.java

示例10: createPreferredAstyanaxConfiguration

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
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;
}
 
开发者ID:rackerlabs,项目名称:blueflood,代码行数:13,代码来源:AstyanaxIO.java

示例11: CassandraService

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
public CassandraService()
{
    System.out.println("Firing up connection to Cassandra...");
    context = (new com.netflix.astyanax.AstyanaxContext.Builder()).forCluster("Test Cluster").forKeyspace("OwenTest").withAstyanaxConfiguration((new AstyanaxConfigurationImpl()).setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE).setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)).withConnectionPoolConfiguration((new ConnectionPoolConfigurationImpl("MyConnectionPool")).setPort(9160).setMaxConnsPerHost(3).setSeeds("10.10.1.2:9160")).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
    keyspace = (Keyspace)context.getEntity();
}
 
开发者ID:owenobyrne,项目名称:aib-internet-banking-api,代码行数:8,代码来源:CassandraService.java

示例12: newAstyanaxBuilder

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
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);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:50,代码来源:CassandraConfiguration.java

示例13: getContextBuilder

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
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;
    }
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:82,代码来源:AstyanaxStoreManager.java

示例14: getContextBuilder

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
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.getLength(TimeUnit.MILLISECONDS);

        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");

        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;
    }
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:81,代码来源:AstyanaxStoreManager.java

示例15: initializeContext

import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; //导入依赖的package包/类
private AstyanaxContext<Keyspace> initializeContext(final ExecutionContext context, final String keyspaceName) {

        /* Will resort hosts per token partition every 10 seconds */
        final int updateInterval = 10000;

        /* Will clear the latency every 10 seconds */
        final int resetInterval = 10000;

        /* Uses last 100 latency samples */
        final int windowSize = 100;

        /*
         * Will sort hosts if a host is more than 100% slower than the best and always assign connections to the fastest
         * host, otherwise will use round robin
         */
        final double badnessThreshold = 0.50;

        final SmaLatencyScoreStrategyImpl scoreStrategy = new SmaLatencyScoreStrategyImpl(
                updateInterval,
                resetInterval,
                windowSize,
                badnessThreshold
        );

        final ConnectionPoolConfigurationImpl poolConfig =
                new ConnectionPoolConfigurationImpl("CassPool"+ UUID.randomUUID().toString().subSequence(0, 6))
                        .setPort(context.getPort())
                        .setSocketTimeout(ConnectionPoolConfigurationImpl.DEFAULT_SOCKET_TIMEOUT)
                        .setInitConnsPerHost(initConnectionsPerHost) //--> might be the reason for the too many open files
                        .setConnectTimeout(connectTimeout)
                        .setMaxConnsPerHost(maxConnectionsPerHost)
                        .setSeeds(context.getSeedNode());

        poolConfig.setLatencyScoreStrategy(scoreStrategy); // Enabled SMA. Omit this to use round robin with a token

        return new AstyanaxContext.Builder()
                .forCluster(context.getClusterName())
                .forKeyspace(keyspaceName)
                .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                                .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
                                .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
                                .setTargetCassandraVersion(cassandraVersion)
                )
                .withConnectionPoolConfiguration(poolConfig)
                .buildKeyspace(ThriftFamilyFactory.getInstance());
    }
 
开发者ID:cosh,项目名称:CassandraBenchmark,代码行数:47,代码来源:AstyanaxBenchmark.java


注:本文中的com.netflix.astyanax.connectionpool.impl.ConnectionPoolType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。