Package netscape.ldap.util
Class ConnectionPool
java.lang.Object
netscape.ldap.util.ConnectionPool
Connection pool, typically used by a server to avoid creating
a new connection for each client
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classWrapper for LDAPConnection object in pool -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConnectionPool(int min, int max, String host, int port) Constructor for specifying all parameters, anonymous identityConnectionPool(int min, int max, String host, int port, String authdn, String authpw) Constructor for specifying all parametersprivateConnectionPool(int min, int max, String host, int port, String authdn, String authpw, LDAPConnection ldc) ConnectionPool(int min, int max, LDAPConnection ldc) Constructor for using an existing connection to clone from.ConnectionPool(String host, int port) Constructor for using default parameters, anonymous identity -
Method Summary
Modifier and TypeMethodDescriptionprivate intvoidclose(LDAPConnection ld) This is our soft close - all we do is mark the connection as available for others to use.private voidprivate voidprivate voidvoiddestroy()Destroy the whole pool - called during a shutdownprivate voiddisconnect(ConnectionPool.LDAPConnectionObject ldapconnObject) private intfind(LDAPConnection con) Gets a connection from the pool If no connections are available, the pool will be extended if the number of connections is less than the maximum; if the pool cannot be extended, the method blocks until a free connection becomes available.getConnection(int timeout) Gets a connection from the pool within a time limit.protected LDAPConnectionGets a connection from the pool If no connections are available, the pool will be extended if the number of connections is less than the maximum; if the pool cannot be extended, the method returns null.booleangetDebug()Reports the debug printout mode.voidDebug method to print the contents of the poolvoidsetDebug(boolean mode) Sets the debug printout mode.private voidsetUpPool(int size)
-
Field Details
-
poolSize
private int poolSize -
poolMax
private int poolMax -
host
-
port
private int port -
authdn
-
authpw
-
ldc
-
pool
-
debugMode
private boolean debugMode
-
-
Constructor Details
-
ConnectionPool
public ConnectionPool(int min, int max, String host, int port, String authdn, String authpw) throws LDAPException Constructor for specifying all parameters- Parameters:
min- initial number of connectionsmax- maximum number of connectionshost- hostname of LDAP serverport- port number of LDAP serverauthdn- DN to authenticate asauthpw- password for authentication- Throws:
LDAPException- on failure to create connections
-
ConnectionPool
Constructor for specifying all parameters, anonymous identity- Parameters:
min- initial number of connectionsmax- maximum number of connectionshost- hostname of LDAP serverport- port number of LDAP server- Throws:
LDAPException- on failure to create connections
-
ConnectionPool
Constructor for using default parameters, anonymous identity- Parameters:
host- hostname of LDAP serverport- port number of LDAP server- Throws:
LDAPException- on failure to create connections
-
ConnectionPool
Constructor for using an existing connection to clone from.The connection to clone must be already established and the user authenticated.
- Parameters:
min- initial number of connectionsmax- maximum number of connectionsldc- connection to clone- Throws:
LDAPException- on failure to create connections
-
ConnectionPool
private ConnectionPool(int min, int max, String host, int port, String authdn, String authpw, LDAPConnection ldc) throws LDAPException - Throws:
LDAPException
-
-
Method Details
-
destroy
public void destroy()Destroy the whole pool - called during a shutdown -
getConnection
Gets a connection from the pool If no connections are available, the pool will be extended if the number of connections is less than the maximum; if the pool cannot be extended, the method blocks until a free connection becomes available.- Returns:
- an active connection.
-
getConnection
Gets a connection from the pool within a time limit. If no connections are available, the pool will be extended if the number of connections is less than the maximum; if the pool cannot be extended, the method blocks until a free connection becomes available or the time limit is exceeded.- Parameters:
timeout- timeout in milliseconds- Returns:
- an active connection or
nullif timed out.
-
getConnFromPool
Gets a connection from the pool If no connections are available, the pool will be extended if the number of connections is less than the maximum; if the pool cannot be extended, the method returns null.- Returns:
- an active connection or null.
-
close
This is our soft close - all we do is mark the connection as available for others to use. We also reset the auth credentials in case they were changed by the caller.- Parameters:
ld- a connection to return to the pool
-
printPool
public void printPool()Debug method to print the contents of the pool -
disconnect
-
createPool
- Throws:
LDAPException
-
addConnection
private int addConnection() -
setUpPool
- Throws:
LDAPException
-
find
-
setDebug
public void setDebug(boolean mode) Sets the debug printout mode.- Parameters:
mode- debug mode to use
-
getDebug
public boolean getDebug()Reports the debug printout mode.- Returns:
- debug mode in use.
-
debug
-
debug
-