public class AS400ConnectionPool
extends java.lang.Object
implements java.io.Serializable
Direct references to this class and its methods should only be made by
the AS400PoolManager
class.
Modifier and Type | Class and Description |
---|---|
private class |
AS400ConnectionPool.KeepAliveTask
A timer task used to generate keep-alive activity for pooled connections.
|
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<AS400ConnectionInfo> |
ivAllConnections
A list of all AS400 connections ever created by the pool.
|
private int |
ivCheckedOut
The number of checked out connections from the pool.
|
protected java.util.ArrayList<AS400ConnectionInfo> |
ivFreeConnections
The pool of free AS400 connections available for clients.
|
private long |
ivKeepAlive
The number of milliseconds between keep-alive task executions.
|
private java.util.Timer |
ivKeepAliveTimer
The timer used to control how often keep-alive activity is generated on
a pooled connection.
|
private int |
ivMaxConns
The maximum number of connections in the pool.
|
private java.lang.String |
ivPassword
The password for the system account.
|
private java.lang.String |
ivSystem
The URL for the AS400 system.
|
private long |
ivTimeOut
The number of milliseconds to wait for a connection if none is available
and the maximum limit is reached.
|
private java.util.Hashtable<com.ibm.as400.access.AS400,java.lang.String> |
ivUsedConnections
A list of the in-use AS400 connections.
|
private java.lang.String |
ivUserId
The user id for the system account.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
AS400ConnectionPool(java.lang.String name,
java.lang.String system,
java.lang.String userid,
java.lang.String password,
int maxconns,
int initconns,
int waittimeout,
int idletimeout)
Constructs a new
AS400ConnectionPool object. |
Modifier and Type | Method and Description |
---|---|
private void |
addToUsedList(com.ibm.as400.access.AS400 conn,
java.lang.String consumer)
Adds the given connection to the list of used connections.
|
private void |
enableKeepAlive(boolean enable)
Enables or disables the connection keep-alive timer.
|
void |
freeBadConnection(com.ibm.as400.access.AS400 conn)
Frees a used connection.
|
void |
freeConnection(com.ibm.as400.access.AS400 conn)
Frees a used connection.
|
com.ibm.as400.access.AS400 |
getConnection()
Retrieves a connection from the pool.
|
private AS400ConnectionInfo |
getConnection(java.lang.String consumer,
long timeout)
Retrieves a connection from the pool using the given maximum wait time.
|
private java.lang.String |
getConnectionConsumer()
Returns the consumer of a connection (the reference point within the code
where a connection is being requested or returned).
|
protected java.lang.String |
getConnectionConsumers()
Returns a sorted list of the connection consumers associated with the
connections currently in-use, suitable for display in a listbox (list
is delimited by newline character).
|
protected java.lang.String |
getConnectionStats()
Returns a formatted string containing information on the total number of
AS400 connections, the number of available connections and the number of
checked out connections.
|
private AS400ConnectionInfo |
getPooledConnection()
Retrieves a connection if one is available from the pool.
|
private void |
initializePool(int initconns)
Opens the initial AS400 connections for the pool.
|
private boolean |
isConnectionOK(AS400ConnectionInfo conn)
Checks if the given connection is functioning properly.
|
protected void |
logServiceState(com.ibm.as400.access.AS400 conn)
Logs the current state of connected services for the given AS400
connection.
|
private AS400ConnectionInfo |
newConnection()
Retrieves a newly created connection.
|
void |
release()
Releases all connections in the pool.
|
private java.lang.String |
removeFromUsedList(com.ibm.as400.access.AS400 conn)
Removes the given connection from the list of used connections.
|
private static final long serialVersionUID
private java.lang.String ivSystem
private java.lang.String ivUserId
private java.lang.String ivPassword
private int ivMaxConns
private long ivTimeOut
private long ivKeepAlive
private int ivCheckedOut
protected java.util.ArrayList<AS400ConnectionInfo> ivFreeConnections
private java.util.ArrayList<AS400ConnectionInfo> ivAllConnections
private java.util.Hashtable<com.ibm.as400.access.AS400,java.lang.String> ivUsedConnections
private java.util.Timer ivKeepAliveTimer
public AS400ConnectionPool(java.lang.String name, java.lang.String system, java.lang.String userid, java.lang.String password, int maxconns, int initconns, int waittimeout, int idletimeout)
AS400ConnectionPool
object.
Any Exception
s possibly caused by the system unavailability
are ignored here (only logged) because, by the time the application asks
for a connection from the pool, the connection might then be successfully
created. If the problem still persists, it is handled at that time.name
- (String) The connection pool name.system
- (String) The URL for the AS400 system.userid
- (String) The user id for the system account.password
- (String) The password for the system account.maxconns
- (int) The maximum number of connections in the pool.
0 means no limit.initconns
- (int) The number of initial connections to open for
the pool.waittimeout
- (int) The number of seconds to wait for a connection
if none is available and the maximum limit is reached.idletimeout
- (int) The number of minutes between keep-alive task
executions.private void enableKeepAlive(boolean enable)
enable
- (boolean) true
if enabling the timer,
otherwise false
.public void freeConnection(com.ibm.as400.access.AS400 conn)
conn
- (AS400) The connection to free.public void freeBadConnection(com.ibm.as400.access.AS400 conn)
conn
- (AS400) The AS400 connection to free.public com.ibm.as400.access.AS400 getConnection() throws java.lang.Exception
Exception
is logged and then thrown back to the invoker.java.lang.Exception
- - if an error occurs while obtaining a
connection.private AS400ConnectionInfo getConnection(java.lang.String consumer, long timeout) throws java.lang.Exception
consumer
- (String) The connection consumer (the reference point
within the code where the connection is being requested).timeout
- (long) The maximum wait time for a connection.java.lang.Exception
- - if an error occurs while obtaining a
connection.private java.lang.String getConnectionConsumer()
protected java.lang.String getConnectionConsumers()
protected java.lang.String getConnectionStats()
private AS400ConnectionInfo getPooledConnection() throws java.lang.Exception
newConnection
method.java.lang.Exception
- - if an error occurs while obtaining a
connection.private void initializePool(int initconns) throws java.lang.Exception
initconns
- (int) The number of initial connections.java.lang.Exception
- - if an error occurs while opening the
connections.private boolean isConnectionOK(AS400ConnectionInfo conn)
conn
- (AS400ConnectionInfo) The AS400 connection to check.true
if the connection is okay, otherwise
false
.protected void logServiceState(com.ibm.as400.access.AS400 conn)
conn
- (AS400) An AS400 connection.private AS400ConnectionInfo newConnection() throws java.lang.Exception
java.lang.Exception
- - if an error occurs while creating the
connection.public void release()
private void addToUsedList(com.ibm.as400.access.AS400 conn, java.lang.String consumer)
conn
- (AS400) The connection to add to the list.consumer
- (String) The connection's consumer.private java.lang.String removeFromUsedList(com.ibm.as400.access.AS400 conn)
conn
- (AS400) The connection to remove from the list.