com.ibm.as400.access
Class AS400ConnectionPool

java.lang.Object
  |
  +--com.ibm.as400.access.ConnectionPool
        |
        +--com.ibm.as400.access.AS400ConnectionPool

public class AS400ConnectionPool
extends ConnectionPool
implements java.io.Serializable

The AS400ConnectionPool class manages a pool of AS400 objects. A connection pool is used to share connections and manage the number of connections a user can have to the AS/400.

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:

See Also:
Serialized Form

Constructor Summary
AS400ConnectionPool()
          Constructs an AS400ConnectionPool with default ConnectionPoolProperties.
 
Method Summary
 void close()
          Close and cleanup the connection pool.
 void fill(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service, int numberOfConnections)
          Preconnects a specified number of connections to a specific system, userID, password, and service.
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 connections to a system.
 int getAvailableConnectionCount(java.lang.String systemName, java.lang.String userID)
          Get the number of available connections to a system.
 AS400 getConnection(java.lang.String systemName, java.lang.String userID)
          Get an AS400 object from the connection pool.
 AS400 getConnection(java.lang.String systemName, java.lang.String userID, int service)
          Get a connected AS400 object from the connection pool.
 AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password)
          Get an AS400 object from the connection pool.
 AS400 getConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service)
          Get a connected AS400 object from the connection pool.
 AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID)
          Get an secure connected AS400 object from the connection pool.
 AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, 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)
          Get an secure connected AS400 object from the connection pool.
 AS400 getSecureConnection(java.lang.String systemName, java.lang.String userID, java.lang.String password, int service)
          Get a secure connected AS400 object from the connection pool.
 void returnConnectionToPool(AS400 system)
          Return the AS400 object to the connection pool.
 void setLog(Log log)
          Set the Log object to log events.
 
Methods inherited from class com.ibm.as400.access.ConnectionPool
addConnectionPoolListener, addPropertyChangeListener, getCleanupInterval, getMaxConnections, getMaxInactivity, getMaxLifetime, getMaxUseCount, getMaxUseTime, isRunMaintenance, isThreadUsed, removeConnectionPoolListener, removePropertyChangeListener, setCleanupInterval, setMaxConnections, setMaxInactivity, setMaxLifetime, setMaxUseCount, setMaxUseTime, setRunMaintenance, setThreadUsed
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AS400ConnectionPool

public AS400ConnectionPool()
Constructs an AS400ConnectionPool with default ConnectionPoolProperties.
Method Detail

close

public void close()
Close and cleanup the connection pool.
Overrides:
close in class ConnectionPool
Tags copied from class: ConnectionPool
Throws:
ConnectionPoolException - If a pool error occurs.

fill

public void fill(java.lang.String systemName,
                 java.lang.String userID,
                 java.lang.String password,
                 int service,
                 int numberOfConnections)
          throws ConnectionPoolException
Preconnects a specified number of connections to a specific system, userID, password, and service.
Parameters:
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.
Throws:
ConnectionPoolException - If a connection pool error occured.

finalize

protected void finalize()
                 throws java.lang.Throwable
Closes the connection if not explicitly closed by the caller.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - If an error occurs.

getActiveConnectionCount

public int getActiveConnectionCount(java.lang.String systemName,
                                    java.lang.String userID)
Get the number of active connections to a system.
Parameters:
systemName - The name of the system where the connections exist.
userID - The name of the user.
Returns:
The number of active connections to a system.

getAvailableConnectionCount

public int getAvailableConnectionCount(java.lang.String systemName,
                                       java.lang.String userID)
Get the number of available connections to a system.
Parameters:
systemName - The name of the system where the connections exist.
userID - The name of the user.
Returns:
The number of available connections to a system.

getConnection

public AS400 getConnection(java.lang.String systemName,
                           java.lang.String userID,
                           java.lang.String password,
                           int service)
                    throws ConnectionPoolException
Get a connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown.
Parameters:
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.
Returns:
A connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getConnection

public AS400 getConnection(java.lang.String systemName,
                           java.lang.String userID,
                           int service)
                    throws ConnectionPoolException
Get a connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown.
Parameters:
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.
Returns:
A connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getConnection

public AS400 getConnection(java.lang.String systemName,
                           java.lang.String userID,
                           java.lang.String password)
                    throws ConnectionPoolException
Get an AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown. The AS400 object may not be connected to any services.
Parameters:
systemName - The name of the system where the object should exist.
userID - The name of the user.
password - The password of the user.
Returns:
An AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getConnection

public AS400 getConnection(java.lang.String systemName,
                           java.lang.String userID)
                    throws ConnectionPoolException
Get an AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown. The AS400 object may not be connected to any services.
Parameters:
systemName - The name of the system where the object should exist.
userID - The name of the user.
Returns:
An AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getSecureConnection

public AS400 getSecureConnection(java.lang.String systemName,
                                 java.lang.String userID,
                                 java.lang.String password)
                          throws ConnectionPoolException
Get an secure connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown. The AS400 object may not be connected to any services.
Parameters:
systemName - The name of the system where the object should exist.
userID - The name of the user.
password - The password of the user.
Returns:
A secure connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getSecureConnection

public AS400 getSecureConnection(java.lang.String systemName,
                                 java.lang.String userID)
                          throws ConnectionPoolException
Get an secure connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown. The AS400 object may not be connected to any services.
Parameters:
systemName - The name of the system where the object should exist.
userID - The name of the user.
Returns:
A secure connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getSecureConnection

public AS400 getSecureConnection(java.lang.String systemName,
                                 java.lang.String userID,
                                 java.lang.String password,
                                 int service)
                          throws ConnectionPoolException
Get a secure connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown.
Parameters:
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.
Returns:
A connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

getSecureConnection

public AS400 getSecureConnection(java.lang.String systemName,
                                 java.lang.String userID,
                                 int service)
                          throws ConnectionPoolException
Get a secure connected AS400 object from the connection pool. If an appropriate one is not found, one is created. If the maximum connection limit has been reached, an exception will be thrown.
Parameters:
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.
Returns:
A connected AS400 object.
Throws:
ConnectionPoolException - If a connection pool error occured.

returnConnectionToPool

public void returnConnectionToPool(AS400 system)
Return the AS400 object to the connection pool.
Parameters:
system - The system to return to the pool.

setLog

public void setLog(Log log)
Set the Log object to log events. The default is to not log events.
Parameters:
log - The log object to use, or null if events should not be logged.
See Also:
Log