directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harris, Christopher P" <chris_har...@baxter.com>
Subject Proper use of LdapConnectionPool
Date Tue, 27 Jan 2015 05:11:09 GMT
Hi,

I'm running into TimeOut issues when implementing a multi-threaded approach to read all of
LDAP/AD into memory, starting with the CEO and trickling down.  I haven't been using the LdapConnectionPool,
so I thought that I'd give that a try to see if it solves my TimeOut issues.  I'm setting
the timeout for my cursor and connection to 300,000 milliseconds, however the timeout consistently
occurs around 30 seconds I've noticed.

Anyway, I read the docs concerning implementing an LdapConnectionPool, but the example doesn't
show you how to use the connection pool.

Does the following method use the LdapConnectionPool the correct way?

public Person searchLdapUsingConnectionPool() {
             SearchCursor cursor = new SearchCursorImpl(null, 30000, TimeUnit.SECONDS);
             LdapConnectionPool pool = null;
             LdapConnection connection = null;
             Person p = null;
             try {
                    LdapConnectionConfig config = new LdapConnectionConfig();
                    config.setLdapHost( host );
                    config.setLdapPort( port );
                    config.setName( dn );
                    config.setCredentials( pwd );
                    DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory(
config );
                    pool = new LdapConnectionPool( factory );
                    pool.setTestOnBorrow( true );
                    connection = pool.getConnection();

                    Entry entry = null;


            SearchRequest sr = new SearchRequestImpl();
            sr.setBase(new Dn(searchBase));
            StringBuilder sb = new StringBuilder(ceoQuery);
            sr.setFilter(sb.toString());
            sr.setScope( SearchScope.SUBTREE );
            cursor = connection.search(sr);
            Response response;

            while (cursor.next() && cursor.isEntry()) {
                response = cursor.get();
                System.out.println(((SearchResultEntry)response).getEntry());
                entry = cursor.getEntry();
                EntryMapper<Person> em = Person.getEntryMapper();
                   p = em.map(entry);
            }
        } catch (LdapException ex) {
            Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CursorException ex) {
            Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            cursor.close();
            try {
                pool.releaseConnection(connection);
            } catch (LdapException ex) {
            Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
                    }
        }

        return p;
       }

It seems like I just need to grab a connection via pool.getConnection(), but I don't know
for sure if I'm using it the recommended way.  The method is working as expected and returning
a Person object.


-        Chris
The information transmitted is intended only for the person(s) or entity to which it is addressed
and may contain confidential and/or legally privileged material. Delivery of this message
to any person other than the intended recipient(s) is not intended in any way to waive privilege
or confidentiality. Any review, retransmission, dissemination or other use of, or taking of
any action in reliance upon, this information by entities other than the intended recipient
is prohibited. If you receive this in error, please contact the sender and delete the material
from any computer.

For Translation:

http://www.baxter.com/email_disclaimer

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message