Example usage for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW

List of usage examples for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW.

Prototype

byte WHEN_EXHAUSTED_GROW

To view the source code for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_GROW.

Click Source Link

Document

A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should simply create a new object anyway.

Usage

From source file:com.officedrop.jesque.utils.PoolUtils.java

/**
 * @return a GenericObjectPool.Config configured with:
 * maxActive=-1, maxIdle=10, minIdle=1, testOnBorrow=true, whenExhaustedAction=GROW
 *//*from   ww w  .ja  v  a  2  s .  co m*/
public static GenericObjectPool.Config getDefaultPoolConfig() {
    final GenericObjectPool.Config cfg = new GenericObjectPool.Config();
    cfg.maxActive = -1; // Infinite
    cfg.maxIdle = 10;
    cfg.minIdle = 1;
    cfg.testOnBorrow = true;
    cfg.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    return cfg;
}

From source file:com.jaspersoft.hadoop.hbase.connection.HBaseConnectionManager.java

public HBaseConnectionManager() {
    connectionFactory = new HBaseConnectionFactory();
    poolConfiguration = new Config();
    poolConfiguration.testOnBorrow = true;
    poolConfiguration.testWhileIdle = true;
    poolConfiguration.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    poolConfiguration.maxActive = 4;//w  w  w. j ava2s  . c o  m
    poolConfiguration.maxIdle = 2;
    poolConfiguration.minIdle = 1;
}

From source file:com.panet.imeta.core.database.ConnectionPoolUtil.java

private static void createPool(DatabaseMeta databaseMeta, String partitionId, int initialSize, int maximumSize)
        throws KettleDatabaseException {
    LogWriter.getInstance().logBasic(databaseMeta.toString(),
            Messages.getString("Database.CreatingConnectionPool", databaseMeta.getName()));
    GenericObjectPool gpool = new GenericObjectPool();

    gpool.setMaxIdle(-1);//from ww  w.j  a  v a  2 s  .  c  o m
    gpool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    gpool.setMaxActive(maximumSize);

    String clazz = databaseMeta.getDriverClass();
    try {
        Class.forName(clazz).newInstance();
    } catch (Exception e) {
        throw new KettleDatabaseException(Messages.getString(
                "Database.UnableToLoadConnectionPoolDriver.Exception", databaseMeta.getName(), clazz), e);
    }

    String url;
    String userName;
    String password;

    try {
        url = databaseMeta.environmentSubstitute(databaseMeta.getURL(partitionId));
        userName = databaseMeta.environmentSubstitute(databaseMeta.getUsername());
        password = databaseMeta.environmentSubstitute(databaseMeta.getPassword());
    } catch (RuntimeException e) {
        url = databaseMeta.getURL(partitionId);
        userName = databaseMeta.getUsername();
        password = databaseMeta.getPassword();
    }

    // Get the list of pool properties
    Properties originalProperties = databaseMeta.getConnectionPoolingProperties();
    //Add user/pass
    originalProperties.setProperty("user", Const.NVL(userName, ""));
    originalProperties.setProperty("password", Const.NVL(password, ""));

    // Now, replace the environment variables in there...
    Properties properties = new Properties();
    Iterator<Object> iterator = originalProperties.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String value = originalProperties.getProperty(key);
        properties.put(key, databaseMeta.environmentSubstitute(value));
    }

    // Create factory using these properties.
    //
    ConnectionFactory cf = new DriverManagerConnectionFactory(url, properties);

    new PoolableConnectionFactory(cf, gpool, null, null, false, false);

    for (int i = 0; i < initialSize; i++) {
        try {
            gpool.addObject();
        } catch (Exception e) {
            throw new KettleDatabaseException(
                    Messages.getString("Database.UnableToPreLoadConnectionToConnectionPool.Exception"), e);
        }
    }

    pd.registerPool(databaseMeta.getName(), gpool);

    LogWriter.getInstance().logBasic(databaseMeta.toString(),
            Messages.getString("Database.CreatedConnectionPool", databaseMeta.getName()));
}

From source file:com.jaspersoft.mongodb.connection.MongoDbConnectionManager.java

public MongoDbConnectionManager() {
    connectionFactory = new MongoDbConnectionFactory();
    poolConfiguration = new Config();
    poolConfiguration.testOnBorrow = true;
    poolConfiguration.testWhileIdle = true;
    poolConfiguration.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    poolConfiguration.maxActive = 4;/*w w w .java 2 s .  co  m*/
    poolConfiguration.maxIdle = 2;
    poolConfiguration.minIdle = 1;
}

From source file:com.jaspersoft.bigquery.connection.BigQueryConnectionManager.java

public BigQueryConnectionManager() {
    connectionFactory = new BigQueryConnectionFactory();
    poolConfiguration = new Config();
    poolConfiguration.testOnBorrow = true;
    poolConfiguration.testWhileIdle = true;
    poolConfiguration.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    poolConfiguration.maxActive = 4;/*  www.  j av  a2  s  .  c o m*/
    poolConfiguration.maxIdle = 2;
    poolConfiguration.minIdle = 1;
}

From source file:com.lithium.flow.util.ConfigObjectPool.java

private static Config buildConfig(@Nonnull com.lithium.flow.config.Config config) {
    Config poolConfig = new Config();
    poolConfig.lifo = config.getBoolean("pool.lifo", true);
    poolConfig.maxActive = config.getInt("pool.maxActive", Runtime.getRuntime().availableProcessors());
    poolConfig.maxIdle = config.getInt("pool.maxIdle", -1);
    poolConfig.minIdle = config.getInt("pool.minIdle", 0);
    poolConfig.testOnBorrow = config.getBoolean("pool.testOnBorrow", false);
    poolConfig.testOnReturn = config.getBoolean("pool.testOnReturn", false);
    poolConfig.timeBetweenEvictionRunsMillis = config.getTime("pool.timeBetweenEvictionRunsMillis", "-1");
    poolConfig.minEvictableIdleTimeMillis = config.getTime("pool.minEvictableIdleTimeMillis", "30m");
    poolConfig.testWhileIdle = config.getBoolean("pool.testWhileIdle", false);
    poolConfig.softMinEvictableIdleTimeMillis = config.getTime("pool.softMinEvictableIdleTimeMillis", "-1");
    poolConfig.numTestsPerEvictionRun = config.getInt("pool.numTestsPerEvictionRun", 3);

    String action = config.getString("pool.whenExhaustedAction", "block");
    switch (action) {
    case "fail":
        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
        break;/* w w  w.  j a v a2  s. c  o m*/
    case "block":
        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        break;
    case "grow":
        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        break;
    default:
        throw new IllegalConfigException("pool.whenExhaustedAction", action, "string", null);
    }

    return poolConfig;
}

From source file:com.thoughtworks.studios.shine.cruise.stage.details.LazyStageGraphLoader.java

LazyStageGraphLoader(StageResourceImporter importer, StageStorage stageStorage,
        int transformerRegistryPoolSize) {
    this.importer = importer;
    this.stageStorage = stageStorage;
    transformerRegistryPool = new GenericObjectPool(new BasePoolableObjectFactory() {
        @Override/*from   ww w.j av a 2s . co m*/
        public Object makeObject() throws Exception {
            return new XSLTTransformerRegistry();
        }

        @Override
        public void activateObject(Object obj) throws Exception {
            XSLTTransformerRegistry registry = (XSLTTransformerRegistry) obj;
            registry.reset();
        }
    }, transformerRegistryPoolSize, GenericObjectPool.WHEN_EXHAUSTED_GROW, GenericObjectPool.DEFAULT_MAX_WAIT);
}

From source file:lineage2.commons.dbcp.BasicDataSource.java

/**
 * Constructor for BasicDataSource./*w  w w  .  j a v a2 s  .  co  m*/
 * @param driver String
 * @param connectURI String
 * @param uname String
 * @param passwd String
 * @param maxActive int
 * @param maxIdle int
 * @param idleTimeOut int
 * @param idleTestPeriod int
 * @param poolPreparedStatements boolean
 */
public BasicDataSource(String driver, String connectURI, String uname, String passwd, int maxActive,
        int maxIdle, int idleTimeOut, int idleTestPeriod, boolean poolPreparedStatements) {
    GenericObjectPool<?> connectionPool = new GenericObjectPool<>(null);
    connectionPool.setMaxActive(maxActive);
    connectionPool.setMaxIdle(maxIdle);
    connectionPool.setMinIdle(1);
    connectionPool.setMaxWait(-1L);
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    connectionPool.setTestOnBorrow(false);
    connectionPool.setTestWhileIdle(true);
    connectionPool.setTimeBetweenEvictionRunsMillis(idleTestPeriod * 1000L);
    connectionPool.setNumTestsPerEvictionRun(maxActive);
    connectionPool.setMinEvictableIdleTimeMillis(idleTimeOut * 1000L);
    GenericKeyedObjectPoolFactory<?, ?> statementPoolFactory = null;
    if (poolPreparedStatements) {
        statementPoolFactory = new GenericKeyedObjectPoolFactory<>(null, -1,
                GenericObjectPool.WHEN_EXHAUSTED_FAIL, 0L, 1, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL);
    }
    Properties connectionProperties = new Properties();
    connectionProperties.put("user", uname);
    connectionProperties.put("password", passwd);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, connectionProperties);
    @SuppressWarnings("unused")
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, statementPoolFactory, "SELECT 1", false, true);
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
    _connectionPool = connectionPool;
    _source = dataSource;
}

From source file:eu.openanalytics.rsb.stats.RedisJobStatisticsHandler.java

public void initialize() {
    final GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
    poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;

    pool = new JedisPool(poolConfig, redisHost, redisPort);

    final boolean redisConfigurationOk = runWithJedis(new RedisAction() {
        public void run(final Jedis jedis) {
            final String pingResponse = jedis.ping();

            Validate.isTrue("PONG".equals(pingResponse),
                    "Unexpected response received from pinging Redis: " + pingResponse);

            LOGGER.info(String.format("%s successfully connected to Redis: %s:%d", getClass().getSimpleName(),
                    redisHost, redisPort));
        }// w  w  w .  ja va  2s. c  om
    });

    Validate.isTrue(redisConfigurationOk,
            "Redis can't be contacted: please check parameter 'rsb.jobs.stats.handler' (set it to 'none' to disable statistics altogether)");
}

From source file:com.toolsverse.etl.sql.connection.PooledAliasConnectionProvider.java

/**
 * Instantiates a new pooled alias connection provider.
 *///from  www.j  a  va2 s .  co  m
public PooledAliasConnectionProvider() {
    _config = new GenericObjectPool.Config();

    _config.maxActive = Utils.str2Int(SystemConfig.instance().getSystemProperty(MAX_ACTIVE),
            GenericObjectPool.DEFAULT_MAX_ACTIVE);

    _config.whenExhaustedAction = Utils.str2Byte(
            SystemConfig.instance().getSystemProperty(WHEN_EXHAUSTED_ACTION),
            GenericObjectPool.WHEN_EXHAUSTED_GROW);

    _config.maxWait = Utils.str2Long(SystemConfig.instance().getSystemProperty(MAX_WAIT), 1000 * 30);

    _config.maxIdle = Utils.str2Int(SystemConfig.instance().getSystemProperty(MAX_IDLE),
            GenericObjectPool.DEFAULT_MAX_IDLE);

    _config.minIdle = Utils.str2Int(SystemConfig.instance().getSystemProperty(MIN_IDLE),
            GenericObjectPool.DEFAULT_MIN_IDLE);

    _config.testOnBorrow = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_ON_BORROW),
            GenericObjectPool.DEFAULT_TEST_ON_BORROW);

    _config.testOnReturn = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_ON_RETURN),
            GenericObjectPool.DEFAULT_TEST_ON_RETURN);

    _config.timeBetweenEvictionRunsMillis = Utils.str2Long(
            SystemConfig.instance().getSystemProperty(TIME_BETWEEN_EVICTION_RUNS_MILLIS),
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);

    _config.numTestsPerEvictionRun = Utils.str2Int(
            SystemConfig.instance().getSystemProperty(NUM_TESTS_PER_EVICTION_RUN),
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);

    _config.minEvictableIdleTimeMillis = Utils.str2Long(
            SystemConfig.instance().getSystemProperty(MIN_EVICTABLE_IDLE_TIME_MILLIS),
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

    _config.testWhileIdle = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_WHILE_IDLE),
            GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}