Package com.netscape.cmscore.ldapconn
Class LdapBoundConnFactory
- java.lang.Object
-
- com.netscape.cmscore.ldapconn.LdapBoundConnFactory
-
- All Implemented Interfaces:
com.netscape.certsrv.ldap.ILdapConnFactory
public class LdapBoundConnFactory extends java.lang.Object implements com.netscape.certsrv.ldap.ILdapConnFactory
Factory for getting LDAP Connections to a LDAP server with the same LDAP authentication. Maintains a pool of connections to the LDAP server. CMS requests are processed on a multi threaded basis. A pool of connections then must be be maintained so this access to the Ldap server can be easily managed. The min and max size of this connection pool should be configurable. Once the maximum limit of connections is exceeded, the factory should provide proper synchronization to resolve contention issues. XXX not sure how useful this is given that LDAPConnection itself can be shared by multiple threads and cloned.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
id
static org.slf4j.Logger
logger
protected LdapAuthInfo
mAuthInfo
protected LdapConnInfo
mConnInfo
protected int
mMaxConns
protected int
mMaxResults
protected int
mMinConns
static java.lang.String
PROP_ERROR_IF_DOWN
static java.lang.String
PROP_LDAPAUTHINFO
static java.lang.String
PROP_LDAPCONNINFO
static java.lang.String
PROP_MAXCONNS
static java.lang.String
PROP_MAXRESULTS
static java.lang.String
PROP_MINCONNS
-
Constructor Summary
Constructors Constructor Description LdapBoundConnFactory(java.lang.String id)
Constructor for initializing from the config store.LdapBoundConnFactory(java.lang.String id, boolean defErrorIfDown)
LdapBoundConnFactory(java.lang.String id, int minConns, int maxConns, int maxResults, LdapConnInfo connInfo, LdapAuthInfo authInfo)
Constructor for LdapBoundConnFactoryLdapBoundConnFactory(java.lang.String id, int minConns, int maxConns, LdapConnInfo connInfo, LdapAuthInfo authInfo)
Constructor for LdapBoundConnFactory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
finalize()
int
freeConn()
Returns the number of free connections available from this pool.LdapAuthInfo
getAuthInfo()
return ldap authentication infonetscape.ldap.LDAPConnection
getConn()
gets a conenction from this factory.LdapBoundConnection
getConn(boolean waitForConn)
Returns a LDAP connection - a clone of the master connection.LdapConnInfo
getConnInfo()
return ldap connection infoIPasswordStore
getPasswordStore()
void
init(PKISocketConfig config, LDAPConfig dbConfig)
void
init(PKISocketConfig config, LDAPConfig dbConfig, IPasswordStore passwordStore)
void
init(PKISocketConfig config, IPasswordStore passwordStore)
protected void
makeConnection(boolean errorIfDown)
makes the initial master connection used to clone others..int
maxConn()
Returns the maximum number of connections available from this pool.void
reset()
used for disconnecting all connections and reset everything to 0 as if connections were never made.void
returnConn(netscape.ldap.LDAPConnection conn)
Teturn connection to the factory.void
setPasswordStore(IPasswordStore passwordStore)
void
shutdown()
int
totalConn()
Returns the number of total connections available from this pool.
-
-
-
Field Detail
-
logger
public static org.slf4j.Logger logger
-
id
protected java.lang.String id
-
mMinConns
protected int mMinConns
-
mMaxConns
protected int mMaxConns
-
mMaxResults
protected int mMaxResults
-
mConnInfo
protected LdapConnInfo mConnInfo
-
mAuthInfo
protected LdapAuthInfo mAuthInfo
-
PROP_MINCONNS
public static final java.lang.String PROP_MINCONNS
- See Also:
- Constant Field Values
-
PROP_MAXCONNS
public static final java.lang.String PROP_MAXCONNS
- See Also:
- Constant Field Values
-
PROP_MAXRESULTS
public static final java.lang.String PROP_MAXRESULTS
- See Also:
- Constant Field Values
-
PROP_LDAPCONNINFO
public static final java.lang.String PROP_LDAPCONNINFO
- See Also:
- Constant Field Values
-
PROP_LDAPAUTHINFO
public static final java.lang.String PROP_LDAPAUTHINFO
- See Also:
- Constant Field Values
-
PROP_ERROR_IF_DOWN
public static final java.lang.String PROP_ERROR_IF_DOWN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LdapBoundConnFactory
public LdapBoundConnFactory(java.lang.String id)
Constructor for initializing from the config store. must be followed by init(IConfigStore)
-
LdapBoundConnFactory
public LdapBoundConnFactory(java.lang.String id, boolean defErrorIfDown)
-
LdapBoundConnFactory
public LdapBoundConnFactory(java.lang.String id, int minConns, int maxConns, LdapConnInfo connInfo, LdapAuthInfo authInfo) throws com.netscape.certsrv.ldap.ELdapException
Constructor for LdapBoundConnFactory- Parameters:
minConns
- minimum number of connections to have availablemaxConns
- max number of connections to have available. This is the maximum number of clones of this connection or separate connections one wants to allow.serverInfo
- server connection info - host, port, etc.- Throws:
com.netscape.certsrv.ldap.ELdapException
-
LdapBoundConnFactory
public LdapBoundConnFactory(java.lang.String id, int minConns, int maxConns, int maxResults, LdapConnInfo connInfo, LdapAuthInfo authInfo) throws com.netscape.certsrv.ldap.ELdapException
Constructor for LdapBoundConnFactory- Parameters:
minConns
- minimum number of connections to have availablemaxConns
- max number of connections to have available. This is the maximum number of clones of this connection or separate connections one wants to allow.maxResults
- max number of results to return per queryserverInfo
- server connection info - host, port, etc.- Throws:
com.netscape.certsrv.ldap.ELdapException
-
-
Method Detail
-
totalConn
public int totalConn()
Description copied from interface:com.netscape.certsrv.ldap.ILdapConnFactory
Returns the number of total connections available from this pool. Includes sum of free and in use connections.- Specified by:
totalConn
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Returns:
- Integer number of total connections.
-
freeConn
public int freeConn()
Description copied from interface:com.netscape.certsrv.ldap.ILdapConnFactory
Returns the number of free connections available from this pool.- Specified by:
freeConn
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Returns:
- Integer number of free connections.
-
maxConn
public int maxConn()
Description copied from interface:com.netscape.certsrv.ldap.ILdapConnFactory
Returns the maximum number of connections available from this pool.- Specified by:
maxConn
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Returns:
- Integer maximum number of connections.
-
init
public void init(PKISocketConfig config, IPasswordStore passwordStore) throws com.netscape.certsrv.ldap.ELdapException
- Throws:
com.netscape.certsrv.ldap.ELdapException
-
init
public void init(PKISocketConfig config, LDAPConfig dbConfig, IPasswordStore passwordStore) throws EBaseException, com.netscape.certsrv.ldap.ELdapException
- Throws:
EBaseException
com.netscape.certsrv.ldap.ELdapException
-
init
public void init(PKISocketConfig config, LDAPConfig dbConfig) throws EBaseException, com.netscape.certsrv.ldap.ELdapException
- Throws:
EBaseException
com.netscape.certsrv.ldap.ELdapException
-
makeConnection
protected void makeConnection(boolean errorIfDown) throws com.netscape.certsrv.ldap.ELdapException
makes the initial master connection used to clone others..- Throws:
com.netscape.certsrv.ldap.ELdapException
- if any error occurs.
-
getConn
public netscape.ldap.LDAPConnection getConn() throws com.netscape.certsrv.ldap.ELdapException
gets a conenction from this factory. All connections obtained from the factory must be returned by returnConn() method. The best thing to do is to put returnConn in a finally clause so it always gets called. For example,LDAPConnection c = null; try { c = factory.getConn(); myclass.do_something_with_c(c); } catch (ELdapException e) { handle_error_here(); } finally { factory.returnConn(c); }
- Specified by:
getConn
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Returns:
- Ldap connection object. connection is not available
- Throws:
com.netscape.certsrv.ldap.ELdapException
- if any error occurs, such as a
-
getConn
public LdapBoundConnection getConn(boolean waitForConn) throws com.netscape.certsrv.ldap.ELdapException
Returns a LDAP connection - a clone of the master connection. All connections should be returned to the factory using returnConn() to recycle connection objects. If not returned the limited max number is affected but if that number is large not much harm is done. Returns null if maximum number of connections reached. The best thing to do is to put returnConn in a finally clause so it always gets called. For example,LDAPConnection c = null; try { c = factory.getConn(); myclass.do_something_with_c(c); } catch (ELdapException e) { handle_error_here(); } finally { factory.returnConn(c); }
- Throws:
com.netscape.certsrv.ldap.ELdapException
-
returnConn
public void returnConn(netscape.ldap.LDAPConnection conn)
Teturn connection to the factory. This is mandatory after a getConn(). The best thing to do is to put returnConn in a finally clause so it always gets called. For example,LDAPConnection c = null; try { c = factory.getConn(); myclass.do_something_with_c(c); } catch (ELdapException e) { handle_error_here(); } finally { factory.returnConn(c); }
- Specified by:
returnConn
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Parameters:
conn
- Ldap connection object to be returned to the free list of the pool.
-
finalize
protected void finalize() throws java.lang.Exception
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Exception
-
reset
public void reset() throws com.netscape.certsrv.ldap.ELdapException
used for disconnecting all connections and reset everything to 0 as if connections were never made. used just before a subsystem shutdown or process exit. useful only if no connections are outstanding.- Specified by:
reset
in interfacecom.netscape.certsrv.ldap.ILdapConnFactory
- Throws:
com.netscape.certsrv.ldap.ELdapException
-
shutdown
public void shutdown() throws com.netscape.certsrv.ldap.ELdapException
- Throws:
com.netscape.certsrv.ldap.ELdapException
-
getConnInfo
public LdapConnInfo getConnInfo()
return ldap connection info
-
getAuthInfo
public LdapAuthInfo getAuthInfo()
return ldap authentication info
-
getPasswordStore
public IPasswordStore getPasswordStore()
-
setPasswordStore
public void setPasswordStore(IPasswordStore passwordStore)
-
-