public class AS400ConnectionPool extends ConnectionPool implements java.io.Serializable
A connection is defined by a systemName, userID, and an optional password and/or service. Services should be referred to using constants from the AS400 class (FILE, PRINT, COMMAND, DATAQUEUE, etc.)
When a connection is requested, a fully functional AS400 object is returned to the calling application. It is then up to the application to return the AS400 object to the pool. It is not recommended that an application use this object to create additional connections as the pool would not keep track of these connections.
The AS400ConnectionPool class keeps track of the number of connections it creates. The user can set the maximum number of connections that can be given out by a pool. If the maximum number of connections has already been given out when an additional connection is requested, an exception is thrown.
Note: AS400ConnectionPool objects are threadsafe.
This example creates an AS400ConnectionPool with a limit of 128 connections:
// Create an AS400ConnectionPool. AS400ConnectionPool testPool = new AS400ConnectionPool(); // Set a maximum of 128 connections to this pool. testPool.setMaxConnections(128); // Preconnect 5 connections to the AS400.COMMAND service. testPool.fill("myAS400", "myUserID", "myPassword", AS400.COMMAND, 5); // Create a connection to the AS400.COMMAND service. (Use the service number constants // defined in the AS400 class (FILE, PRINT, COMMAND, DATAQUEUE, etc.)) AS400 newConn = testPool.getConnection("myAS400", "myUserID", "myPassword", AS400.COMMAND); // Create a new command call object and run a command. CommandCall cmd = new CommandCall(newConn); cmd.run("CRTLIB FRED"); // Return the connection to the pool. testPool.returnConnectionToPool(newConn); // Close the test pool. testPool.close();
AS400ConnectionPool objects generate the following events:
Modifier and Type | Field and Description |
---|---|
static int |
CCSID_DEFAULT
Indicates that the CCSID used for new connections is the same as the system default CCSID.
|
Constructor and Description |
---|
AS400ConnectionPool()
Constructs an AS400ConnectionPool with default ConnectionPoolProperties.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close and cleanup the connection pool.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
char[] password,
int service,
int numberOfConnections)
Preconnects a specified number of connections to a specific system, userID,
password, and service.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
char[] password,
int service,
int numberOfConnections,
java.util.Locale locale)
Preconnects a specified number of connections to a specific system, userID,
password, service, and Locale.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
int service,
int numberOfConnections)
Preconnects a specified number of connections to a specific system, userID,
profileToken, and service.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
int service,
int numberOfConnections,
java.util.Locale locale)
Preconnects a specified number of connections to a specific system, userID,
profileToken, service, and Locale.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
int service,
int numberOfConnections)
Deprecated.
Use fill(String systemName, String userID, char[] password, int service, int numberOfConnections) instead.
|
void |
fill(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
int service,
int numberOfConnections,
java.util.Locale locale)
Deprecated.
Use fill(String systemName, String userID, char[] password, int service, int numberOfConnections, Locale locale) instead.
|
protected void |
finalize()
Closes the connection if not explicitly closed by the caller.
|
int |
getActiveConnectionCount(java.lang.String systemName,
java.lang.String userID)
Get the number of active (in-use) connections to a system.
|
int |
getAvailableConnectionCount(java.lang.String systemName,
java.lang.String userID)
Get the number of available connections to a system.
|
int |
getCCSID()
Returns the CCSID that is used when creating new connections.
|
java.lang.String[] |
getConnectedUsers(java.lang.String systemName)
Get a list of the userIds in the pool with connections to a specific system.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID)
Deprecated.
Use method with password instead.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
char[] password)
Get an AS400 object from the connection pool.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
char[] password,
int service)
Get a connected AS400 object from the connection pool.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
char[] password,
int service,
java.util.Locale locale)
Get a connected AS400 object from the connection pool with the specified Locale.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
char[] password,
java.util.Locale locale)
Get an AS400 object from the connection pool with the specified Locale.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
int service)
Deprecated.
Use getConnection(String systemName, String userID, char[] password, int service) instead.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken)
Get an AS400 object from the connection pool.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
int service)
Get a connected AS400 object from the connection pool.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
int service,
java.util.Locale locale)
Get a connected AS400 object from the connection pool with the specified Locale.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
java.util.Locale locale)
Get an AS400 object from the connection pool with the specified Locale.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password)
Deprecated.
Use getConnection(String systemName, String userID, char[] password) instead.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
int service)
Deprecated.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
int service,
java.util.Locale locale)
Deprecated.
Use getConnection(String systemName, String userID, char[] password, int service, Locale locale) instead.
|
AS400 |
getConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
java.util.Locale locale)
Deprecated.
Use getConnection(String systemName, String userID, char[] password, Locale locale) instead.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID)
Deprecated.
Use getSecureConnection(String systemName, String userID, char[] password) instead.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
char[] password)
Get an secure connected AS400 object from the connection pool.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
char[] password,
int service)
Get a secure connected AS400 object from the connection pool.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
int service)
Deprecated.
Use getConnection(String systemName, String userID, char[] password, int service) instead.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken)
Get an secure connected AS400 object from the connection pool.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
ProfileTokenCredential profileToken,
int service)
Get a secure connected AS400 object from the connection pool.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password)
Deprecated.
Use getSecureConnection(String systemName, String userID, char[] password) instead.
|
AS400 |
getSecureConnection(java.lang.String systemName,
java.lang.String userID,
java.lang.String password,
int service)
Deprecated.
Use getSecureConnection(String systemName, String userID, char[] password, int service) instead.
|
SocketProperties |
getSocketProperties()
Returns a copy of the socket properties that this AS400ConnectionPool specifies when it creates new AS400 objects, for example in fill(), getConnection(), or getSecureConnection().
|
java.lang.String[] |
getSystemNames()
Get a list of the system names in the pool.
|
java.util.Enumeration |
getUsers()
Get an enumeration of the systemName/userId pairs in the pool.
|
java.lang.String[] |
getUsers(java.lang.String systemName)
Get a list of the userIds in the pool with connections to a specific system.
|
void |
removeFromPool(AS400 system)
Remove the specified connection from the pool, and disconnect it.
|
void |
removeFromPool(java.lang.String systemName,
java.lang.String userID)
Remove the connections for a systemName/userID.
|
void |
returnConnectionToPool(AS400 system)
Return the AS400 object to the connection pool.
|
void |
setCCSID(int ccsid)
Sets the CCSID to use when creating new connections.
|
void |
setLog(Log log)
Set the Log object to log events.
|
void |
setSocketProperties(SocketProperties properties)
Sets the socket properties that this AS400ConnectionPool specifies when it creates new AS400 objects, for example in fill(), getConnection(), or getSecureConnection().
|
addConnectionPoolListener, addPropertyChangeListener, getCleanupInterval, getMaxConnections, getMaxInactivity, getMaxLifetime, getMaxUseCount, getMaxUseTime, isPretestConnections, isRunMaintenance, isThreadUsed, removeConnectionPoolListener, removePropertyChangeListener, setCleanupInterval, setMaxConnections, setMaxInactivity, setMaxLifetime, setMaxUseCount, setMaxUseTime, setPretestConnections, setRunMaintenance, setThreadUsed
public static final int CCSID_DEFAULT
public AS400ConnectionPool()
public void close()
close
in class ConnectionPool
public void fill(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, int service, int numberOfConnections) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.ConnectionPoolException
- If a connection pool error occurred.public void fill(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, int service, int numberOfConnections, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 objects
created. Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public void fill(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service, int numberOfConnections) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.password
- The password of the user.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.ConnectionPoolException
- If a connection pool error occurred.public void fill(java.lang.String systemName, java.lang.String userID, char[] password, int service, int numberOfConnections) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.password
- The password of the user.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.ConnectionPoolException
- If a connection pool error occurred.public void fill(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service, int numberOfConnections, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.password
- The password of the user.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 objects
created. Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public void fill(java.lang.String systemName, java.lang.String userID, char[] password, int service, int numberOfConnections, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the connections should exist.userID
- The name of the user.password
- The password of the user.service
- The service to be connected. See the service number constants defined by AS400 class.numberOfConnections
- The number of connections to be made.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 objects
created. Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.protected void finalize() throws java.lang.Throwable
finalize
in class ConnectionPool
java.lang.Throwable
- If an error occurs.public int getActiveConnectionCount(java.lang.String systemName, java.lang.String userID)
systemName
- The name of the system where the connections exist.userID
- The name of the user.public int getAvailableConnectionCount(java.lang.String systemName, java.lang.String userID)
systemName
- The name of the system where the connections exist.userID
- The name of the user.public int getCCSID()
CCSID_DEFAULT
if the system default CCSID is used.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, char[] password, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, char[] password, int service, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- Always thrown because this method has been deprecated.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, char[] password) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, char[] password, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.ConnectionPoolException
- Always thrown because this method has been deprecated.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, int service, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.service
- The service to connect. See the service number constants defined by AS400 class.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.ConnectionPoolException
- If a connection pool error occurred.public AS400 getConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, java.util.Locale locale) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.locale
- The Locale used to set the National Language Version (NLV) on the system for the AS400 object returned.
Only the COMMAND, PRINT, and DATABASE services accept an NLV.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, char[] password) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.ConnectionPoolException
- Always thrown because this method has been deprecated.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, char[] password, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.password
- The password of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- Always thrown because this method has been deprecated.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.ConnectionPoolException
- If a connection pool error occurred.public AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, ProfileTokenCredential profileToken, int service) throws ConnectionPoolException
systemName
- The name of the system where the object should exist.userID
- The name of the user.profileToken
- The profile token to use to authenticate to the system.service
- The service to connect. See the service number constants defined by AS400 class.ConnectionPoolException
- If a connection pool error occurred.public SocketProperties getSocketProperties()
public java.lang.String[] getSystemNames()
public java.util.Enumeration getUsers()
public java.lang.String[] getUsers(java.lang.String systemName)
systemName
- The name of the system of interest.public java.lang.String[] getConnectedUsers(java.lang.String systemName)
systemName
- The name of the system of interest.public void removeFromPool(java.lang.String systemName, java.lang.String userID)
systemName
- The system name of connections you want to remove.userID
- The user ID of connections you want to remove.public void removeFromPool(AS400 system)
This method should only be called by the process or thread to which
the connection is currently allocated; that is,
the process or thread that most recently obtained the connection
via getConnection() or getSecureConnection().
To remove the connection from the pool, the process or thread
holding the connection should call this method rather than
returnConnectionToPool()
.
Caution: The pool does not verify that the process or thread removing the connection, is the same as the process or thread to which the connection is currently allocated. This may cause unpredictable results if the connection is in use by another process or thread.
system
- The system to remove from the pool.public void returnConnectionToPool(AS400 system)
This method should only be called by the process or thread to which the connection is currently allocated; that is, the process or thread that most recently obtained the connection via getConnection() or getSecureConnection().
Caution: The pool does not verify that the process or thread returning the connection, is the same as the process or thread to which the connection is currently allocated. This may cause unpredictable results if the connection is in use by another process or thread.
system
- The system to return to the pool.removeFromPool(AS400)
public void setCCSID(int ccsid)
ccsid
- The CCSID to use for connections in the pool, or CCSID_DEFAULT
to indicate that the system default CCSID should be used.public void setLog(Log log)
log
- The log object to use, or null if events should not be logged.Log
public void setSocketProperties(SocketProperties properties)
properties
- The socket properties. If null, then this AS400ConnectionPool will specify no socket properties when it creates new AS400 objects. That is, setSocketProperties(null) cancels the effects of any previous setSocketProperties().