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.streamsets.pipeline.stage.origin.udptokafka.KafkaUDPConsumer.java

public void init() {
    executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(udpConfigBean.concurrency);
    int max = udpConfigBean.concurrency;
    int minIdle = Math.max(1, udpConfigBean.concurrency / 4);
    int maxIdle = udpConfigBean.concurrency / 2;
    GenericObjectPoolConfig kakfaPoolConfig = new GenericObjectPoolConfig();
    kakfaPoolConfig.setMaxTotal(udpConfigBean.concurrency);
    kakfaPoolConfig.setMinIdle(minIdle);
    kakfaPoolConfig.setMaxIdle(maxIdle);
    LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", max, minIdle, maxIdle);
    kafkaProducerPool = new GenericObjectPool<>(
            new SdcKafkaProducerPooledObjectFactory(kafkaTargetConfig, DataFormat.BINARY), kakfaPoolConfig);
    GenericObjectPoolConfig serializerPoolConfig = new GenericObjectPoolConfig();
    serializerPoolConfig.setMaxTotal(udpConfigBean.concurrency);
    serializerPoolConfig.setMinIdle(udpConfigBean.concurrency);
    serializerPoolConfig.setMaxIdle(udpConfigBean.concurrency);
    udpSerializerPool = new GenericObjectPool<>(new UDPMessageSerializerPooledObjectFactory(),
            serializerPoolConfig);//  ww w .  ja v  a 2 s .  c o  m
    udpType = UDP_DATA_FORMAT_MAP.get(udpConfigBean.dataFormat);
    LOG.debug("Started, concurrency '{}'", udpConfigBean.concurrency);
}

From source file:herddb.jdbc.BasicHerdDBDataSource.java

protected synchronized void ensureClient() throws SQLException {
    if (client == null) {
        ClientConfiguration clientConfiguration = new ClientConfiguration(properties);
        Properties propsNoPassword = new Properties(properties);
        if (propsNoPassword.contains("password")) {
            propsNoPassword.setProperty("password", "-------");
        }/*from   w  w w.ja  va 2s. c o m*/
        LOGGER.log(Level.INFO, "Booting HerdDB Client, url:" + url + ", properties:" + propsNoPassword
                + " clientConfig " + clientConfiguration);
        clientConfiguration.readJdbcUrl(url);
        if (properties.containsKey("discoverTableSpaceFromQuery")) {
            this.discoverTableSpaceFromQuery = clientConfiguration.getBoolean("discoverTableSpaceFromQuery",
                    true);
        }
        client = new HDBClient(clientConfiguration);
    }
    if (pool == null) {
        if (properties.containsKey("maxActive")) {
            this.maxActive = Integer.parseInt(properties.get("maxActive").toString());
        }
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setBlockWhenExhausted(true);
        config.setMaxTotal(maxActive);
        config.setMaxIdle(maxActive);
        config.setMinIdle(maxActive / 2);
        config.setJmxNamePrefix("HerdDBClient");
        pool = new GenericObjectPool<>(new ConnectionsFactory(), config);
    }
}

From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java

@Test
public void genericPoolShouldCloseConnectionsAboveMaxIdleSize() throws Exception {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(2);

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createGenericObjectPool(() -> client.connect(), poolConfig);

    borrowAndReturn(pool);//  www . j av a 2  s. co  m
    borrowAndClose(pool);
    borrowAndCloseTryWithResources(pool);

    StatefulRedisConnection<String, String> c1 = pool.borrowObject();
    StatefulRedisConnection<String, String> c2 = pool.borrowObject();
    StatefulRedisConnection<String, String> c3 = pool.borrowObject();

    assertThat(channels).hasSize(3);

    pool.returnObject(c1);
    pool.returnObject(c2);
    pool.returnObject(c3);

    assertThat(channels).hasSize(2);

    pool.close();

    Wait.untilTrue(channels::isEmpty).waitOrTimeout();

    assertThat(channels).isEmpty();
}

From source file:gobblin.hive.metastore.HiveMetaStoreBasedRegister.java

public HiveMetaStoreBasedRegister(State state, Optional<String> metastoreURI) throws IOException {
    super(state);

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(this.props.getNumThreads());
    config.setMaxIdle(this.props.getNumThreads());
    this.clientPool = HiveMetastoreClientPool.get(this.props.getProperties(), metastoreURI);

    MetricContext metricContext = GobblinMetricsRegistry.getInstance().getMetricContext(state,
            HiveMetaStoreBasedRegister.class, GobblinMetrics.getCustomTagsFromState(state));

    this.eventSubmitter = new EventSubmitter.Builder(metricContext, "gobblin.hive.HiveMetaStoreBasedRegister")
            .build();/*from   ww  w .  j a  v a  2s  .  c om*/
}

From source file:ch.cyberduck.core.worker.ConcurrentTransferWorker.java

public ConcurrentTransferWorker(final ConnectionService connect, final Transfer transfer,
        final TransferOptions options, final TransferSpeedometer meter, final TransferPrompt prompt,
        final TransferErrorCallback error, final TransferItemCallback transferItemCallback,
        final ConnectionCallback connectionCallback, final ProgressListener progressListener,
        final StreamListener streamListener, final X509TrustManager trust, final X509KeyManager key,
        final PathCache cache, final Integer connections) {
    super(transfer, options, prompt, meter, error, transferItemCallback, progressListener, streamListener,
            connectionCallback);/*from   w w  w.  ja  v a  2s .c o m*/
    final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig() {
        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("GenericObjectPoolConfig{");
            sb.append("connections=").append(connections);
            sb.append('}');
            return sb.toString();
        }
    };
    configuration.setJmxEnabled(false);
    configuration.setMinIdle(0);
    configuration.setMaxTotal(connections);
    configuration.setMaxIdle(connections);
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    progress = progressListener;
    retry = Integer.max(PreferencesFactory.get().getInteger("connection.retry"), connections);
    pool = new GenericObjectPool<Session>(new SessionPool(connect, trust, key, cache, transfer.getHost()),
            configuration) {
        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("GenericObjectPool{");
            sb.append("configuration=").append(configuration);
            sb.append('}');
            return sb.toString();
        }
    };
    completion = new DefaultThreadPool<TransferStatus>(connections, "transfer");
}

From source file:com.threecrickets.prudence.cache.SqlCache.java

/**
 * Constructor.// w  w w. j  a  v a  2s.  c  o  m
 * 
 * @param dataSource
 *        The data source
 * @param maxSize
 *        The max entry count
 * @param poolSize
 *        The number of connections in the pool
 * @param lockSource
 *        The lock source
 */
public SqlCache(DataSource dataSource, int maxSize, int poolSize, LockSource lockSource) {
    this.maxSize = maxSize;
    this.lockSource = lockSource;

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(poolSize);
    config.setMaxIdle(poolSize);
    config.setMinIdle(poolSize);
    DataSourceConnectionFactory connectionFactory = new DataSourceConnectionFactory(dataSource);
    PoolableConnectionFactory pooledObjectFactory = new PoolableConnectionFactory(connectionFactory, null);
    GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pooledObjectFactory,
            config);
    pooledObjectFactory.setPool(pool);
    this.dataSource = new PoolingDataSource<PoolableConnection>(pool);
}

From source file:com.escframework.support.dubbo.RedisRegistry.java

public RedisRegistry(URL url) {
    super(url);/*from  ww w . ja  va 2s  .  c o  m*/
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setTestOnBorrow(url.getParameter("test.on.borrow", true));
    config.setTestOnReturn(url.getParameter("test.on.return", false));
    config.setTestWhileIdle(url.getParameter("test.while.idle", false));

    if (url.getParameter("max.idle", 0) > 0)

        config.setMaxIdle(url.getParameter("max.idle", 0));
    if (url.getParameter("min.idle", 0) > 0)
        config.setMinIdle(url.getParameter("min.idle", 0));
    if (url.getParameter("max.active", 0) > 0)
        config.setMaxTotal(url.getParameter("max.total", 0));
    if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
        config.setMaxWaitMillis(url.getParameter("max.wait", url.getParameter("timeout", 0)));
    if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
        config.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0));
    if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
        config.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0));
    if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
        config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0));

    String cluster = url.getParameter("cluster", "failover");
    if (!"failover".equals(cluster) && !"replicate".equals(cluster)) {
        throw new IllegalArgumentException("Unsupported redis cluster: " + cluster
                + ". The redis cluster only supported failover or replicate.");
    }
    replicate = "replicate".equals(cluster);

    List<String> addresses = new ArrayList<String>();
    addresses.add(url.getAddress());
    String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
    if (backups != null && backups.length > 0) {
        addresses.addAll(Arrays.asList(backups));
    }
    for (String address : addresses) {
        int i = address.indexOf(':');
        String host;
        int port;
        if (i > 0) {
            host = address.substring(0, i);
            port = Integer.parseInt(address.substring(i + 1));
        } else {
            host = address;
            port = DEFAULT_REDIS_PORT;
        }
        this.jedisPools.put(address, new JedisPool(config, host, port,
                url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
    }

    this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY,
            Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (!group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    if (!group.endsWith(Constants.PATH_SEPARATOR)) {
        group = group + Constants.PATH_SEPARATOR;
    }
    this.root = group;

    this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
    this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            try {
                deferExpired(); // 
            } catch (Throwable t) { // 
                logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
            }
        }
    }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}

From source file:net.ymate.platform.persistence.redis.impl.RedisModuleCfg.java

@SuppressWarnings("unchecked")
protected RedisDataSourceCfgMeta __doParserDataSourceCfgMeta(String dsName, Map<String, String> _moduleCfgs)
        throws Exception {
    RedisDataSourceCfgMeta _meta = null;
    ////from   w  w w.  ja v  a2 s.c o  m
    Map<String, String> _dataSourceCfgs = __doGetCfgs(_moduleCfgs, "ds." + dsName + ".");
    //
    //        if (!_dataSourceCfgs.isEmpty()) {
    String _connectionType = StringUtils.defaultIfBlank(_dataSourceCfgs.get("connection_type"), "default");
    String _masterServerName = StringUtils.defaultIfBlank(_dataSourceCfgs.get("master_server_name"), "default");
    List<ServerMeta> _servers = new ArrayList<ServerMeta>();
    String[] _serverNames = StringUtils
            .split(StringUtils.defaultIfBlank(_dataSourceCfgs.get("server_name_list"), "default"), "|");
    Map<String, String> _tmpCfgs = null;
    if (_serverNames != null) {
        for (String _serverName : _serverNames) {
            _tmpCfgs = __doGetCfgs(_dataSourceCfgs, "server." + _serverName + ".");
            if (!_tmpCfgs.isEmpty()) {
                ServerMeta _servMeta = new ServerMeta();
                _servMeta.setName(_serverName);
                _servMeta.setHost(StringUtils.defaultIfBlank(_tmpCfgs.get("host"), "localhost"));
                _servMeta.setPort(
                        BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("port"), "6379")).toIntValue());
                _servMeta.setTimeout(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("timeout"), "2000")).toIntValue());
                _servMeta.setWeight(
                        BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("weight"), "1")).toIntValue());
                _servMeta.setDatabase(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("database"), "0"))
                        .toIntValue());
                _servMeta.setClientName(StringUtils.trimToNull(_tmpCfgs.get("client_name")));
                _servMeta.setPassword(StringUtils.trimToNull(_tmpCfgs.get("password")));
                //
                boolean _pwdEncrypted = new BlurObject(_tmpCfgs.get("password_encrypted")).toBooleanValue();
                //
                if (_pwdEncrypted && StringUtils.isNotBlank(_servMeta.getPassword())
                        && StringUtils.isNotBlank(_tmpCfgs.get("password_class"))) {
                    IPasswordProcessor _proc = ClassUtils.impl(_dataSourceCfgs.get("password_class"),
                            IPasswordProcessor.class, this.getClass());
                    if (_proc != null) {
                        _servMeta.setPassword(_proc.decrypt(_servMeta.getPassword()));
                    }
                }
                //
                _servers.add(_servMeta);
            }
        }
    }
    //
    GenericObjectPoolConfig _poolConfig = new GenericObjectPoolConfig();
    _tmpCfgs = __doGetCfgs(_dataSourceCfgs, "pool.");
    if (!_tmpCfgs.isEmpty()) {
        _poolConfig.setMinIdle(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("min_idle"),
                GenericObjectPoolConfig.DEFAULT_MIN_IDLE + "")).toIntValue());
        _poolConfig.setMaxIdle(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_idle"),
                GenericObjectPoolConfig.DEFAULT_MAX_IDLE + "")).toIntValue());
        _poolConfig.setMaxTotal(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_total"),
                GenericObjectPoolConfig.DEFAULT_MAX_TOTAL + "")).toIntValue());
        _poolConfig
                .setBlockWhenExhausted(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("block_when_exhausted"),
                                        GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED + ""))
                                .toBooleanValue());
        _poolConfig.setFairness(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("fairness"),
                GenericObjectPoolConfig.DEFAULT_FAIRNESS + "")).toBooleanValue());
        _poolConfig.setJmxEnabled(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_enabled"),
                GenericObjectPoolConfig.DEFAULT_JMX_ENABLE + "")).toBooleanValue());
        _poolConfig.setJmxNameBase(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_name_base"),
                GenericObjectPoolConfig.DEFAULT_JMX_NAME_BASE));
        _poolConfig.setJmxNamePrefix(StringUtils.defaultIfBlank(_tmpCfgs.get("jmx_name_prefix"),
                GenericObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX));
        _poolConfig.setEvictionPolicyClassName(
                StringUtils.defaultIfBlank(_tmpCfgs.get("eviction_policy_class_name"),
                        GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME));
        _poolConfig.setLifo(BlurObject.bind(
                StringUtils.defaultIfBlank(_tmpCfgs.get("lifo"), GenericObjectPoolConfig.DEFAULT_LIFO + ""))
                .toBooleanValue());
        _poolConfig.setMaxWaitMillis(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("max_wait_millis"),
                GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS + "")).toLongValue());
        _poolConfig
                .setMinEvictableIdleTimeMillis(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("min_evictable_idle_time_millis"),
                                GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS + ""))
                        .toLongValue());
        _poolConfig.setSoftMinEvictableIdleTimeMillis(BlurObject
                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("soft_min_evictable_idle_time_millis"),
                        GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS + ""))
                .toLongValue());
        _poolConfig.setTestOnBorrow(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_borrow"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW + "")).toBooleanValue());
        _poolConfig.setTestOnReturn(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_return"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN + "")).toBooleanValue());
        _poolConfig.setTestOnCreate(BlurObject.bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_on_create"),
                GenericObjectPoolConfig.DEFAULT_TEST_ON_CREATE + "")).toBooleanValue());
        _poolConfig
                .setTestWhileIdle(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("test_while_idle"),
                                        GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE + ""))
                                .toBooleanValue());
        _poolConfig
                .setNumTestsPerEvictionRun(
                        BlurObject
                                .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("num_tests_per_eviction_run"),
                                        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN + ""))
                                .toIntValue());
        _poolConfig
                .setTimeBetweenEvictionRunsMillis(BlurObject
                        .bind(StringUtils.defaultIfBlank(_tmpCfgs.get("time_between_eviction_runs_millis"),
                                GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS + ""))
                        .toLongValue());
    }
    _meta = new RedisDataSourceCfgMeta(dsName, _connectionType, _masterServerName, _servers, _poolConfig);
    //        }
    return _meta;
}

From source file:org.apache.directory.ldap.client.template.LdapConnectionTemplateTest.java

@Test
public void testDIRAPI_202() throws Exception {
    // test requested by https://issues.apache.org/jira/browse/DIRAPI-202
    LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(Network.LOOPBACK_HOSTNAME);
    config.setLdapPort(createLdapConnectionPoolRule.getLdapServer().getPort());
    config.setName("uid=admin,ou=system");
    config.setCredentials("secret");

    DefaultLdapConnectionFactory factory = new DefaultLdapConnectionFactory(config);
    factory.setTimeOut(30000);/*from   w  ww  . ja va  2  s  .com*/

    // optional, values below are defaults
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setLifo(true);
    poolConfig.setMaxTotal(8);
    poolConfig.setMaxIdle(8);
    poolConfig.setMaxWaitMillis(-1L);
    poolConfig.setMinEvictableIdleTimeMillis(1000L * 60L * 30L);
    poolConfig.setMinIdle(0);
    poolConfig.setNumTestsPerEvictionRun(3);
    poolConfig.setSoftMinEvictableIdleTimeMillis(-1L);
    poolConfig.setTestOnBorrow(false);
    poolConfig.setTestOnReturn(false);
    poolConfig.setTestWhileIdle(false);
    poolConfig.setTimeBetweenEvictionRunsMillis(-1L);
    poolConfig.setBlockWhenExhausted(GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED);

    LdapConnectionTemplate ldapConnectionTemplate = new LdapConnectionTemplate(
            new LdapConnectionPool(new ValidatingPoolableLdapConnectionFactory(factory), poolConfig));
    assertNotNull(ldapConnectionTemplate);

    List<Muppet> muppets = ldapConnectionTemplate.search("ou=people,dc=example,dc=com",
            "(objectClass=inetOrgPerson)", SearchScope.ONELEVEL, Muppet.getEntryMapper());
    assertNotNull(muppets);
    assertEquals(6, muppets.size());

    muppets = ldapConnectionTemplate.search("ou=people,dc=example,dc=com",
            equal("objectClass", "inetOrgPerson"), SearchScope.ONELEVEL, Muppet.getEntryMapper());
    assertNotNull(muppets);
    assertEquals(6, muppets.size());
}

From source file:org.apache.directory.server.core.integ.CreateLdapConnectionPoolRule.java

private LdapConnectionPool createLdapConnectionPool(LdapServer ldapServer,
        Class<? extends PooledObjectFactory<LdapConnection>> factoryClass,
        Class<? extends LdapConnectionFactory> connectionFactoryClass,
        Class<? extends LdapConnectionValidator> validatorClass) {
    LdapConnectionConfig config = new LdapConnectionConfig();

    config.setLdapHost(Network.LOOPBACK_HOSTNAME);

    config.setLdapPort(ldapServer.getPort());
    config.setName("uid=admin,ou=system");
    config.setCredentials("secret");

    if ((createLdapConnectionPool.additionalBinaryAttributes() != null)
            && (createLdapConnectionPool.additionalBinaryAttributes().length > 0)) {
        DefaultConfigurableBinaryAttributeDetector binaryAttributeDetector = new DefaultConfigurableBinaryAttributeDetector();
        binaryAttributeDetector.addBinaryAttribute(createLdapConnectionPool.additionalBinaryAttributes());
        config.setBinaryAttributeDetector(binaryAttributeDetector);
    }//from  ww w.  ja va2 s .  c  o  m

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setLifo(createLdapConnectionPool.lifo());
    poolConfig.setMaxTotal(createLdapConnectionPool.maxActive());
    poolConfig.setMaxIdle(createLdapConnectionPool.maxIdle());
    poolConfig.setMaxWaitMillis(createLdapConnectionPool.maxWait());
    poolConfig.setMinEvictableIdleTimeMillis(createLdapConnectionPool.minEvictableIdleTimeMillis());
    poolConfig.setMinIdle(createLdapConnectionPool.minIdle());
    poolConfig.setNumTestsPerEvictionRun(createLdapConnectionPool.numTestsPerEvictionRun());
    poolConfig.setSoftMinEvictableIdleTimeMillis(createLdapConnectionPool.softMinEvictableIdleTimeMillis());
    poolConfig.setTestOnBorrow(createLdapConnectionPool.testOnBorrow());
    poolConfig.setTestOnReturn(createLdapConnectionPool.testOnReturn());
    poolConfig.setTestWhileIdle(createLdapConnectionPool.testWhileIdle());
    poolConfig.setTimeBetweenEvictionRunsMillis(createLdapConnectionPool.timeBetweenEvictionRunsMillis());
    poolConfig.setBlockWhenExhausted(createLdapConnectionPool.whenExhaustedAction() == 1);

    try {
        Constructor<? extends LdapConnectionFactory> constructor = connectionFactoryClass
                .getConstructor(LdapConnectionConfig.class);
        ldapConnectionFactory = constructor.newInstance(config);
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "invalid connectionFactoryClass " + connectionFactoryClass.getName() + ": " + e.getMessage(),
                e);
    }
    try {
        Method timeoutSetter = connectionFactoryClass.getMethod("setTimeOut", Long.TYPE);
        if (timeoutSetter != null) {
            timeoutSetter.invoke(ldapConnectionFactory, createLdapConnectionPool.timeout());
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("invalid connectionFactoryClass " + connectionFactoryClass.getName()
                + ", missing setTimeOut(long): " + e.getMessage(), e);
    }

    try {
        Constructor<? extends PooledObjectFactory<LdapConnection>> constructor = factoryClass
                .getConstructor(LdapConnectionFactory.class);
        poolableLdapConnectionFactory = constructor.newInstance(ldapConnectionFactory);
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "invalid factoryClass " + factoryClass.getName() + ": " + e.getMessage(), e);
    }
    try {
        Method setValidator = factoryClass.getMethod("setValidator", LdapConnectionValidator.class);
        if (setValidator != null) {
            setValidator.invoke(poolableLdapConnectionFactory, validatorClass.newInstance());
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("invalid connectionFactoryClass " + connectionFactoryClass.getName()
                + ", missing setTimeOut(long): " + e.getMessage(), e);
    }

    return new LdapConnectionPool(poolableLdapConnectionFactory, poolConfig);
}