Search in sources :

Example 1 with DefaultPoolableLdapConnectionFactory

use of org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory in project Singularity by HubSpot.

the class SingularityLDAPDatastore method createConnectionPool.

private static LdapConnectionPool createConnectionPool(LDAPConfiguration configuration) throws IOException {
    final LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(configuration.getHostname());
    config.setLdapPort(configuration.getPort());
    config.setName(configuration.getBindDn());
    config.setCredentials(configuration.getBindPassword());
    final DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory(config);
    final LdapConnectionPool pool = new LdapConnectionPool(factory);
    pool.setTestOnBorrow(configuration.isPoolTestOnBorrow());
    pool.setTestOnReturn(configuration.isPoolTestOnReturn());
    pool.setTestWhileIdle(configuration.isPoolTestWhileIdle());
    pool.setMaxActive(configuration.getPoolMaxActive());
    pool.setMaxIdle(configuration.getPoolMaxIdle());
    pool.setMinIdle(configuration.getPoolMinIdle());
    pool.setMaxWait(configuration.getPoolMaxWait());
    switch(configuration.getPoolWhenExhaustedAction()) {
        case BLOCK:
            pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_BLOCK);
            break;
        case FAIL:
            pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_FAIL);
            break;
        case GROW:
            pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_GROW);
            break;
        default:
            pool.setWhenExhaustedAction(LdapConnectionPool.DEFAULT_WHEN_EXHAUSTED_ACTION);
    }
    return pool;
}
Also used : DefaultPoolableLdapConnectionFactory(org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory) LdapConnectionConfig(org.apache.directory.ldap.client.api.LdapConnectionConfig) LdapConnectionPool(org.apache.directory.ldap.client.api.LdapConnectionPool)

Example 2 with DefaultPoolableLdapConnectionFactory

use of org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory in project directory-ldap-api by apache.

the class ApiLdapClientApiOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    new LdapNetworkConnection().close();
    new SaslGssApiRequest();
    new Krb5LoginConfiguration();
    new AddFuture(new LdapNetworkConnection(), 2);
    new LdapConnectionTemplate(new LdapConnectionPool(new DefaultPoolableLdapConnectionFactory(new LdapConnectionConfig())));
    FilterBuilder.and(FilterBuilder.not(FilterBuilder.contains("cn", "a", "b"))).toString();
    // Test for DIRAPI-239
    PoolableObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(new LdapConnectionConfig());
    Config config = new Config();
    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool(factory, config);
    ldapConnectionPool.getLdapApiService();
    ldapConnectionPool.getTestOnBorrow();
}
Also used : SaslGssApiRequest(org.apache.directory.ldap.client.api.SaslGssApiRequest) Config(org.apache.commons.pool.impl.GenericObjectPool.Config) LdapConnectionConfig(org.apache.directory.ldap.client.api.LdapConnectionConfig) DefaultPoolableLdapConnectionFactory(org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory) LdapConnectionTemplate(org.apache.directory.ldap.client.template.LdapConnectionTemplate) LdapConnectionConfig(org.apache.directory.ldap.client.api.LdapConnectionConfig) LdapConnectionPool(org.apache.directory.ldap.client.api.LdapConnectionPool) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) AddFuture(org.apache.directory.ldap.client.api.future.AddFuture) Krb5LoginConfiguration(org.apache.directory.ldap.client.api.Krb5LoginConfiguration) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

DefaultPoolableLdapConnectionFactory (org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory)2 LdapConnectionConfig (org.apache.directory.ldap.client.api.LdapConnectionConfig)2 LdapConnectionPool (org.apache.directory.ldap.client.api.LdapConnectionPool)2 Config (org.apache.commons.pool.impl.GenericObjectPool.Config)1 Krb5LoginConfiguration (org.apache.directory.ldap.client.api.Krb5LoginConfiguration)1 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)1 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)1 SaslGssApiRequest (org.apache.directory.ldap.client.api.SaslGssApiRequest)1 AddFuture (org.apache.directory.ldap.client.api.future.AddFuture)1 LdapConnectionTemplate (org.apache.directory.ldap.client.template.LdapConnectionTemplate)1