org.apache.directory.ldap.client.api.LdapConnectionPool Java Examples

The following examples show how to use org.apache.directory.ldap.client.api.LdapConnectionPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiLdapClientApiOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@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
    PooledObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() );
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
    ldapConnectionPool.getLdapApiService();
    ldapConnectionPool.getTestOnBorrow();
    ldapConnectionPool.close();
}
 
Example #2
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of LdapConnectionTemplate.
 *
 * @param connectionPool The pool to obtain connections from.
 */
public LdapConnectionTemplate( LdapConnectionPool connectionPool )
{
    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_04174_CREATING_NEW_CONNECTION_TEMPLATE ) );
    }
    
    this.connectionPool = connectionPool;
    this.passwordPolicyRequestControl = new PasswordPolicyResponseImpl();
    this.passwordPolicyResponder = new PasswordPolicyResponderImpl(
        connectionPool.getLdapApiService() );
    this.modelFactory = new ModelFactoryImpl();
}
 
Example #3
Source File: SingularityLDAPDatastore.java    From Singularity with Apache License 2.0 5 votes vote down vote up
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;
}