Class AbstractPoolableLdapConnectionFactory
- java.lang.Object
-
- org.apache.directory.ldap.client.api.AbstractPoolableLdapConnectionFactory
-
- All Implemented Interfaces:
PooledObjectFactory<LdapConnection>
- Direct Known Subclasses:
DefaultPoolableLdapConnectionFactory,ValidatingPoolableLdapConnectionFactory
public abstract class AbstractPoolableLdapConnectionFactory extends Object implements PooledObjectFactory<LdapConnection>
An abstract class implementing the PoolableObjectFactory, for LdapConnections.- Author:
- Apache Directory Project
-
-
Field Summary
Fields Modifier and Type Field Description protected LdapConnectionFactoryconnectionFactoryThe factory to use to create a new connectionprotected LdapConnectionValidatorvalidatorThe validator to use
-
Constructor Summary
Constructors Constructor Description AbstractPoolableLdapConnectionFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateObject(PooledObject<LdapConnection> connection)Reinitializes an instance to be returned by the pool.voiddestroyObject(PooledObject<LdapConnection> connection)Destroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode.LdapApiServicegetLdapApiService()Returns the LdapApiService instance used by this factory.PooledObject<LdapConnection>makeObject()Creates an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.protected static LdapConnectionFactorynewLdapConnectionFactory(LdapConnectionConfig config, Class<? extends LdapConnectionFactory> connectionFactoryClass)voidpassivateObject(PooledObject<LdapConnection> connection)Uninitializes an instance to be returned to the idle object pool.voidsetValidator(LdapConnectionValidator validator)Sets the validator to use when validation occurs.booleanvalidateObject(PooledObject<LdapConnection> connection)Ensures that the instance is safe to be returned by the pool.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.pool2.PooledObjectFactory
destroyObject
-
-
-
-
Field Detail
-
connectionFactory
protected LdapConnectionFactory connectionFactory
The factory to use to create a new connection
-
validator
protected LdapConnectionValidator validator
The validator to use
-
-
Method Detail
-
activateObject
public void activateObject(PooledObject<LdapConnection> connection) throws LdapException
Reinitializes an instance to be returned by the pool. There is nothing to do to activate a connection.- Specified by:
activateObjectin interfacePooledObjectFactory<LdapConnection>- Parameters:
connection- aPooledObjectwrapping the instance to be activated- Throws:
LdapException- See Also:
PooledObjectFactory.destroyObject(org.apache.commons.pool2.PooledObject<T>)
-
destroyObject
public void destroyObject(PooledObject<LdapConnection> connection) throws LdapException
Destroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode.It is important for implementations of this method to be aware that there is no guarantee about what state
objwill be in and the implementation should be prepared to handle unexpected errors.Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.
Destroying a connection will unbind it which will result on a shutdown of teh underlying protocol.- Specified by:
destroyObjectin interfacePooledObjectFactory<LdapConnection>- Parameters:
connection- aPooledObjectwrapping the instance to be destroyed- Throws:
LdapException- See Also:
PooledObjectFactory.validateObject(org.apache.commons.pool2.PooledObject<T>),ObjectPool.invalidateObject(T)
-
getLdapApiService
public LdapApiService getLdapApiService()
Returns the LdapApiService instance used by this factory.- Returns:
- The LdapApiService instance used by this factory
-
makeObject
public PooledObject<LdapConnection> makeObject() throws LdapException
Creates an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool. Specifically, we are creating a new connection based on the LdapConnection Factory we used to create this pool of connections. The default is to create bound connections.- Specified by:
makeObjectin interfacePooledObjectFactory<LdapConnection>- Returns:
- a
PooledObjectwrapping an instance that can be served by the pool - Throws:
LdapException- If unable to connect.
-
newLdapConnectionFactory
protected static LdapConnectionFactory newLdapConnectionFactory(LdapConnectionConfig config, Class<? extends LdapConnectionFactory> connectionFactoryClass)
-
passivateObject
public void passivateObject(PooledObject<LdapConnection> connection) throws LdapException
Uninitializes an instance to be returned to the idle object pool. We don't do anything with the connection. It remains in the state it was before being used.- Specified by:
passivateObjectin interfacePooledObjectFactory<LdapConnection>- Parameters:
connection- aPooledObjectwrapping the instance to be passivated- Throws:
LdapException- If unable to reconfigure and rebind.- See Also:
PooledObjectFactory.destroyObject(org.apache.commons.pool2.PooledObject<T>)
-
setValidator
public void setValidator(LdapConnectionValidator validator)
Sets the validator to use when validation occurs. Note that validation will only occur if the connection pool was configured to validate. This means one of: must have been set to true on the pool. The default validator isLookupLdapConnectionValidator.- Parameters:
validator- The validator
-
validateObject
public boolean validateObject(PooledObject<LdapConnection> connection)
Ensures that the instance is safe to be returned by the pool. Validating a connection is done by checking the connection status.- Specified by:
validateObjectin interfacePooledObjectFactory<LdapConnection>- Parameters:
connection- aPooledObjectwrapping the instance to be validated- Returns:
falseifobjis not valid and should be dropped from the pool,trueotherwise.
-
-