Folks,

I have created an LDAP Connection pool using the Commons Pooling.  It is described 
below:

        public class LdapConnectionFactory extends BasePoolableObjectFactory {

                public Object makeObject() {
                        try {
                                // Note, I have removed the getEnvironment method for 
brevity.
                                return new InitialDirContext(getEnvironment());
                        }
                        catch (NamingException e )      {
                                logger_.error(this, "Exception during creation of LDAP 
connection.", e);
                                return null;
                        }
                }       

                public void destroyObject(Object o) {
                        try {
                                ((DirContext)o).close();
                        }
                        catch(NamingException e) {
                                logger_.error(this, "Exception during expire of LDAP 
connection.", e);
                        }
                }
        }

I can create and use connections no problem with code like:

        try {
                ObjectPool pool = new StackObjectPool(new LdapConnectionFactory());
                DirContext ctx = (DirContext)pool.borrowObject();
                Attributes attrs = ctx.getAttributes(queryString, REQUEST_ATTRIBUTES);
                ...
        }
        finally {
                pool.returnObject(ctx);
        }

So far, so good ...

The problem is, after being idle for a few hours, the connection expires and the next 
request is invalid.

How can i test to make sure that the connection is valid?  Alternately, how can i 
catch an exception during the query and remove the connection from the pool manually?

I'm pretty sure i might be able to use some sort of combination of activateObject, 
passivateObject and validateObject, just not sure how...

Any help would be greatly appreciated.  Thanks!

---
- Nayan Hajratwala
- Chikli Consulting LLC
- http://www.chikli.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to