Class LDAPConnectionPool
- java.lang.Object
-
- org.opends.guitools.controlpanel.browser.LDAPConnectionPool
-
public class LDAPConnectionPool extends Object
An LDAPConnectionPool is a pool of LDAPConnection.
When a client class needs to access an LDAPUrl, it simply passes this URL to getConnection() and gets an LDAPConnection back. When the client has finished with this LDAPConnection, it *must* pass it releaseConnection() which will take care of its disconnection or caching.
LDAPConnectionPool maintains a pool of authentications. This pool is populated using registerAuth(). When getConnection() has created a new connection for accessing a host:port, it looks in the authentication pool if any authentication is available for this host:port and, if yes, tries to bind the connection. If no authentication is available, the returned connection is simply connected (ie anonymous bind).
LDAPConnectionPool shares connections and maintains a usage counter for each connection: two calls to getConnection() with the same URL will return the same connection. Two calls to releaseConnection() will be needed to make the connection 'potentially disconnectable'.
releaseConnection() does not disconnect systematically a connection whose usage counter is null. It keeps it connected a while (TODO: to be implemented).
TODO: synchronization is a bit simplistic...
-
-
Constructor Summary
Constructors Constructor Description LDAPConnectionPool()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddReferralAuthenticationListener(ReferralAuthenticationListener listener)Adds a referral authentication listener.ConnectionWithControlsgetConnection(LDAPURL ldapUrl)Returns an LDAPConnection for accessing the specified url.intgetConnectTimeout()Returns the timeout to establish the connection in milliseconds.ApplicationTrustManagergetTrustManager()Returns the ApplicationTrustManager used by the connection pool to connect to servers.booleanisConnectionRegistered(ConnectionWrapper conn)Returns whether the connection passed is registered in the connection pool.static LDAPURLmakeLDAPUrl(HostPort hostPort, String dn, boolean isLdaps)Make an url from the specified arguments.static LDAPURLmakeLDAPUrl(LDAPURL url, String dn)Make an url from the specified arguments.voidregisterConnection(ConnectionWrapper conn)Registers a connection in this connection pool.voidreleaseConnection(ConnectionWithControls conn)Release an LDAPConnection created by getConnection().voidsetConnectTimeout(int connectTimeout)Sets the timeout to establish the connection in milliseconds.voidsetRequestControls(ServerSideSortRequestControl sortControl, ManageDsaITRequestControl followReferralsControl)Sets the request controls to be used by the connections of this connection pool.voidsetTrustManager(ApplicationTrustManager trustManager)Sets the ApplicationTrustManager used by the connection pool to connect to servers.voidunregisterConnection(ConnectionWrapper conn)Unregisters a connection from this connection pool.
-
-
-
Method Detail
-
isConnectionRegistered
public boolean isConnectionRegistered(ConnectionWrapper conn)
Returns whether the connection passed is registered in the connection pool.- Parameters:
conn- the connection.- Returns:
trueif the connection passed is registered in the connection pool,falseotherwise.
-
registerConnection
public void registerConnection(ConnectionWrapper conn)
Registers a connection in this connection pool.- Parameters:
conn- the connection to be registered.
-
unregisterConnection
public void unregisterConnection(ConnectionWrapper conn) throws LdapException
Unregisters a connection from this connection pool.- Parameters:
conn- the connection to be unregistered.- Throws:
LdapException- if there is a problem unregistering the connection.
-
addReferralAuthenticationListener
public void addReferralAuthenticationListener(ReferralAuthenticationListener listener)
Adds a referral authentication listener.- Parameters:
listener- the referral authentication listener.
-
getConnection
public ConnectionWithControls getConnection(LDAPURL ldapUrl) throws LdapException
Returns an LDAPConnection for accessing the specified url. If no connection are available for the protocol/host/port of the URL, getConnection() makes a new one and call connect(). If authentication data available for this protocol/host/port, getConnection() call bind() on the new connection. If connect() or bind() failed, getConnection() forward the LdapException. When getConnection() succeeds, the returned connection must be passed to releaseConnection() after use.- Parameters:
ldapUrl- the LDAP URL to which the connection must connect.- Returns:
- a connection to the provided LDAP URL.
- Throws:
LdapException- if there was an error connecting.
-
setRequestControls
public void setRequestControls(ServerSideSortRequestControl sortControl, ManageDsaITRequestControl followReferralsControl)
Sets the request controls to be used by the connections of this connection pool.- Parameters:
sortControl- the sort control.followReferralsControl- the manage dsa it control.
-
releaseConnection
public void releaseConnection(ConnectionWithControls conn)
Release an LDAPConnection created by getConnection(). The connection should be considered as virtually disconnected and not be used anymore.- Parameters:
conn- the connection to be released.
-
setTrustManager
public void setTrustManager(ApplicationTrustManager trustManager)
Sets the ApplicationTrustManager used by the connection pool to connect to servers.- Parameters:
trustManager- the ApplicationTrustManager.
-
getTrustManager
public ApplicationTrustManager getTrustManager()
Returns the ApplicationTrustManager used by the connection pool to connect to servers.- Returns:
- the ApplicationTrustManager used by the connection pool to connect to servers.
-
getConnectTimeout
public int getConnectTimeout()
Returns the timeout to establish the connection in milliseconds.- Returns:
- the timeout to establish the connection in milliseconds.
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Sets the timeout to establish the connection in milliseconds. Use0to express no timeout.- Parameters:
connectTimeout- the timeout to establish the connection in milliseconds. Use0to express no timeout.
-
makeLDAPUrl
public static LDAPURL makeLDAPUrl(HostPort hostPort, String dn, boolean isLdaps)
Make an url from the specified arguments.- Parameters:
hostPort- the host name and port of the server.dn- the base DN of the URL.isLdaps- whether the connection uses LDAPS- Returns:
- an LDAP URL from the specified arguments.
-
-