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

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

Introduction

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

Prototype

public void setMaxIdle(int maxIdle) 

Source Link

Document

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

Usage

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
 *//* ww w. j ava2 s  . c  o  m*/
@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.axibase.tsd.example.AbstractAtsdClientExample.java

protected void pureJavaConfigure() {
    ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory("http",
            "writeyourownservername.com", 8088, // serverPort
            "/api/v1", "/api/v1", "username", "pwd", 3000, // connectTimeout
            3000, // readTimeout
            600000, // pingTimeout
            false, // ignoreSSLErrors
            false // skipStreamingControl
    );/*from w w  w .java  2s. c  o  m*/
    ClientConfiguration clientConfiguration = configurationFactory.createClientConfiguration();
    System.out.println("Connecting to ATSD: " + clientConfiguration.getMetadataUrl());
    HttpClientManager httpClientManager = new HttpClientManager(clientConfiguration);

    GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
    objectPoolConfig.setMaxTotal(5);
    objectPoolConfig.setMaxIdle(5);

    httpClientManager.setObjectPoolConfig(objectPoolConfig);
    httpClientManager.setBorrowMaxWaitMillis(1000);

    dataService = new DataService(httpClientManager);
    metaDataService = new MetaDataService(httpClientManager);
}

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();//w w  w. j  a  v  a  2  s .  c  o 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.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 w  w  .j  a  v a2  s .  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:com.streamsets.pipeline.lib.parser.log.TestCEFParser.java

private GenericObjectPool<StringBuilder> getStringBuilderPool() {
    GenericObjectPoolConfig stringBuilderPoolConfig = new GenericObjectPoolConfig();
    stringBuilderPoolConfig.setMaxTotal(1);
    stringBuilderPoolConfig.setMinIdle(1);
    stringBuilderPoolConfig.setMaxIdle(1);
    stringBuilderPoolConfig.setBlockWhenExhausted(false);
    return new GenericObjectPool<>(new StringBuilderPoolFactory(1024), stringBuilderPoolConfig);
}

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

@Deprecated // rz - Kept for backwards compat with old connection configs
@Bean/*from   w  w  w.  j a va  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.skynetcomputing.database.Database.java

/**
 * Creates a new database connection pool so that statements and queries can be executed.
 */// ww  w.j  av a  2  s  . com
@SuppressWarnings("unchecked")
private Database() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(5);
    config.setMaxTotal(10);

    // Configurable connectionstring.
    String connString = MiscUtils.getPropertyOrDefault("dbConnection", URL);
    String connUser = MiscUtils.getPropertyOrDefault("dbUser", USERNAME);
    String connPassword = MiscUtils.getPropertyOrDefault("dbPassword", PASSWORD);

    pool = new GenericObjectPool<>(new BasePooledObjectFactory() {
        @Override
        public Object create() throws Exception {
            return DriverManager.getConnection(connString, connUser, connPassword);
        }

        @Override
        public PooledObject wrap(Object o) {
            return new PooledSoftReference<>(new SoftReference<>(o));
        }
    }, config);
}

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

@Provides
@Singleton/*w  w w  .j  av  a2s.  c om*/
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.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);//from  ww w.j ava 2  s. co m
}

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);/*  ww w.  jav  a  2  s. com*/
    poolConfig.setMaxIdle(maxIdle);
    LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", maxConcurrency, minIdle,
            maxIdle);
    return new GenericObjectPool<>(new SdcKafkaProducerPooledObjectFactory(kafkaConfigs, DataFormat.SDC_JSON),
            poolConfig);
}