Example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setMinIdle

List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMinIdle

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setMinIdle.

Prototype

public void setMinIdle(int minIdle) 

Source Link

Document

Set the value for the minIdle configuration attribute for pools created with this configuration instance.

Usage

From source file:dictinsight.redis.JedisInstance.java

public JedisInstance() {
    boolean online = FileUtils.getBooleanConfig(RedisConst.filename, "online", false);
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    if (online) {
        List<String> seedList = HttpUtils.getSvnConfServer(RedisConst.seedList);
        for (String seed : seedList) {
            String[] s = seed.split(":");
            try {
                jedisClusterNodes.add(new HostAndPort(s[0], Integer.valueOf(s[1])));
                System.out.println("connect to rediscluster:" + s[0]);
            } catch (Exception e) {
                e.printStackTrace();//from   ww  w.j av  a2s.  co  m
            }
        }
    } else {
        String host = FileUtils.getStringConfig(RedisConst.filename, "redis-hosts", "nc042x");
        String ports = FileUtils.getStringConfig(RedisConst.filename, "redis-port",
                "7000:7001:7002:7003:7004:7005");
        String[] portArray = ports.split(":");
        for (String port : portArray) {
            jedisClusterNodes.add(new HostAndPort(host, Integer.valueOf(port)));
            System.out.println("connect to " + host);
        }
    }

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(200);
    poolConfig.setMaxIdle(20);
    poolConfig.setMinIdle(10);
    poolConfig.setMaxWaitMillis(5 * 1000);
    poolConfig.setTimeBetweenEvictionRunsMillis(5 * 60 * 1000);
    poolConfig.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy");
    poolConfig.setSoftMinEvictableIdleTimeMillis(2 * 60 * 1000);
    jedis = new JedisCluster(jedisClusterNodes, DEFAULT_TIMEOUT, 3, poolConfig);
}

From source file:com.thinkbiganalytics.nifi.provenance.config.NifiProvenanceConfig.java

/**
 * The KyloProvenanceEventReportingTask will override these defaults based upon its batch property ("Processing batch size")
 *
 * @return an object pool for processing ProvenanceEventRecordDTO objects
 *//*from w w  w .j  a  va  2s. c om*/
@Bean
public ProvenanceEventObjectPool provenanceEventObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(1000);
    config.setMaxTotal(1000);
    config.setMinIdle(1);
    config.setBlockWhenExhausted(false);
    config.setTestOnBorrow(false);
    config.setTestOnReturn(false);
    return new ProvenanceEventObjectPool(new ProvenanceEventObjectFactory(), config);
}

From source file:com.streamsets.pipeline.lib.parser.DataParserFactory.java

protected GenericObjectPool<StringBuilder> getStringBuilderPool(Settings settings) {
    int maxRecordLen = getSettings().getMaxRecordLen();
    int poolSize = getSettings().getStringBuilderPoolSize();
    GenericObjectPoolConfig stringBuilderPoolConfig = new GenericObjectPoolConfig();
    stringBuilderPoolConfig.setMaxTotal(poolSize);
    stringBuilderPoolConfig.setMinIdle(poolSize);
    stringBuilderPoolConfig.setMaxIdle(poolSize);
    stringBuilderPoolConfig.setBlockWhenExhausted(false);
    return new GenericObjectPool<>(
            new StringBuilderPoolFactory(maxRecordLen > 0 ? maxRecordLen : DEFAULT_MAX_RECORD_LENGTH),
            stringBuilderPoolConfig);/*  w  w w . j  a  v a2s .c  o m*/
}

From source file:com.pytsoft.cachelock.LockSmithTest_RedisCluster_Jedis.java

@Before
public void init() {
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    HostAndPort hostAndPort = new HostAndPort(this.cacheServerHost, this.redisServerPort);
    jedisClusterNodes.add(hostAndPort);//w ww  .  j a  va  2s  .c o  m

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setBlockWhenExhausted(true);
    config.setMaxTotal(20);
    config.setMaxIdle(10);
    config.setMinIdle(5);
    config.setMaxWaitMillis(5000);

    this.cluster = new JedisCluster(jedisClusterNodes, config);
}

From source file:me.carbou.mathieu.tictactoe.di.ServiceBindings.java

@Provides
@Singleton/* www  .j ava2  s  .  c o m*/
JedisPool jedisPool() {
    URI connectionURI = URI.create(Env.REDISCLOUD_URL);
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMinIdle(0);
    config.setMaxIdle(5);
    config.setMaxTotal(30);
    String password = connectionURI.getUserInfo().split(":", 2)[1];
    return new JedisPool(config, connectionURI.getHost(), connectionURI.getPort(), Protocol.DEFAULT_TIMEOUT,
            password);
}

From source file:com.streamsets.pipeline.stage.origin.tokafka.KafkaFragmentWriter.java

@VisibleForTesting
GenericObjectPool<SdcKafkaProducer> createKafkaProducerPool() {
    int minIdle = Math.max(1, maxConcurrency / 4);
    int maxIdle = maxConcurrency / 2;
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(maxConcurrency);
    poolConfig.setMinIdle(minIdle);
    poolConfig.setMaxIdle(maxIdle);/*  www. j  a  va  2s. co m*/
    LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", maxConcurrency, minIdle,
            maxIdle);
    return new GenericObjectPool<>(new SdcKafkaProducerPooledObjectFactory(kafkaConfigs, DataFormat.SDC_JSON),
            poolConfig);
}

From source file:com.yahoo.athenz.common.server.db.DataSourceFactory.java

public static GenericObjectPoolConfig setupPoolConfig() {

    // setup config vars for the object pool
    // ie. min and max idle instances, and max total instances of arbitrary objects

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();

    // The maximum number of active connections that can be allocated from
    // this pool at the same time, or negative for no limit. Default: 8
    config.setMaxTotal(/* w w w .j a  v a  2  s  . c  om*/
            retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL));
    if (config.getMaxTotal() == 0) {
        config.setMaxTotal(-1); // -1 means no limit
    }

    //  The maximum number of connections that can remain idle in the pool,
    // without extra ones being released, or negative for no limit. Default 8
    config.setMaxIdle(
            retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE));
    if (config.getMaxIdle() == 0) {
        config.setMaxIdle(-1); // -1 means no limit
    }

    // The minimum number of connections that can remain idle in the pool,
    // without extra ones being created, or zero to create none. Default 0
    config.setMinIdle(
            retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE));

    // The maximum number of milliseconds that the pool will wait (when
    // there are no available connections) for a connection to be returned
    // before throwing an exception, or -1 to wait indefinitely. Default -1
    config.setMaxWaitMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_WAIT,
            GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS));

    // setup the configuration to cleanup idle connections
    //
    // Minimum time an object can be idle in the pool before being eligible
    // for eviction by the idle object evictor.
    // The default value is 30 minutes (1000 * 60 * 30).
    config.setMinEvictableIdleTimeMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT,
            BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS));

    // Number of milliseconds to sleep between runs of idle object evictor thread.
    // Not using DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS since it is -1
    // meaning it will not run the evictor thread and instead we're using
    // the default min value for evictable idle connections (Default 30 minutes)
    config.setTimeBetweenEvictionRunsMillis(retrieveConfigSetting(ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL,
            BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS));

    if (LOG.isDebugEnabled()) {
        LOG.debug("Config settings for idle object eviction: " + "time interval between eviction thread runs ("
                + config.getTimeBetweenEvictionRunsMillis() + " millis): minimum timeout for idle objects ("
                + config.getMinEvictableIdleTimeMillis() + " millis)");
    }

    // Validate objects by the idle object evictor. If invalid, gets dropped
    // from the pool.
    config.setTestWhileIdle(true);

    // Validate object before borrowing from pool. If invalid, gets dropped
    // from the pool and an attempt to borrow another one will occur.
    config.setTestOnBorrow(true);
    return config;
}

From source file:com.netflix.spinnaker.orca.config.RedisConfiguration.java

@Deprecated // rz - Kept for backwards compat with old connection configs
@Bean/*w w w .  java  2 s. c  om*/
@ConfigurationProperties("redis")
public GenericObjectPoolConfig redisPoolConfig() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(100);
    config.setMaxIdle(100);
    config.setMinIdle(25);
    return config;
}

From source file:com.streamsets.pipeline.stage.origin.sdcipctokafka.IpcToKafkaServlet.java

@Override
public void init() throws ServletException {
    super.init();
    int max = configs.maxConcurrentRequests;
    int minIdle = Math.max(1, configs.maxConcurrentRequests / 4);
    int maxIdle = configs.maxConcurrentRequests / 2;
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(max);//from  ww w  .  ja v a2 s  . c o m
    poolConfig.setMinIdle(minIdle);
    poolConfig.setMaxIdle(maxIdle);
    LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", max, minIdle, maxIdle);
    kafkaProducerPool = new GenericObjectPool<>(new SdcKafkaProducerPooledObjectFactory(configs), poolConfig);
}

From source file:com.streamsets.pipeline.stage.origin.ipctokafka.IpcToKafkaServlet.java

@Override
public void init() throws ServletException {
    super.init();
    int max = configs.maxConcurrentRequests;
    int minIdle = Math.max(1, configs.maxConcurrentRequests / 4);
    int maxIdle = configs.maxConcurrentRequests / 2;
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(max);//from   www  .ja va2  s.  c o  m
    poolConfig.setMinIdle(minIdle);
    poolConfig.setMaxIdle(maxIdle);
    LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", max, minIdle, maxIdle);
    kafkaProducerPool = new GenericObjectPool<>(
            new SdcKafkaProducerPooledObjectFactory(kafkaConfigBean.kafkaConfig, DataFormat.SDC_JSON),
            poolConfig);
}