Class ConnectionPool
- All Implemented Interfaces:
ConnectionPoolMBean
There are a couple of different timeouts that are worth mentioning: the max idle timeout determines how long a connection can be idle in the pool before it is closed; the timeout determines how long a caller will wait for a connection to be available in the pool (assuming heavy load).
The following properties can be set in Infranet.properties to control aspects of this connection pool:
- infranet.connectionpool.maxsize - max connections in the pool
- infranet.connectionpool.minsize - min connections in the pool
- infranet.connectionpool.timeout - time caller waits for a connection
- infranet.connectionpool.maxidletime - time before an idle connection is closed
- infranet.connectionpool.maxrequestlistsize - maximum requests allowed in the waiting list
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property key for specifying the connection reuse algorithmstatic final String
Property key for verifying connection status in the connection poolstatic final String
// Value indicating that the Least Recently Used (LRU) algorithm should be used for connection reusestatic final String
Value indicating that the Most Recently Used (MRU) algorithm should be used for connection reuse -
Constructor Summary
ConstructorsConstructorDescriptionDefault connection pool constructor.ConnectionPool
(ConnectionFactory cf, FList connFL) Constructor that takes an FList containing login params.Constructor that reads in Connectionpool-specific properties info from a properties objectConnectionPool
(ConnectionFactory cf, Properties p, int timeOut) Constructor that reads in Connectionpool-specific properties info from a properties object.Constructor that takes a set of connection related properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToFreeConnection
(PortalContext connection, long lastUsedTime, String descr) Adds a connection to the pool of free connections.void
closeConnection
(PortalContext connection, boolean bDecCntFlag) Closes the specified connection and optionally decrements the connection count.protected void
Closes any idle connections in the free-connection list.protected Object[]
createConnections
(int size) Creates size number of connections and returnsstatic void
A helper singleton that wraps the single-argument constructorstatic void
createInstance
(ConnectionFactory cf, FList fl) A helper singleton that wraps the 2-argument constructorstatic void
A helper singleton that wraps the (connection factory, properties) constructorReturns an instance of connection.returns the current connection factory.long
Retrieves the maximum allowed idle time for a connection in the pool.Retrieves the algorithm used for connection reuse.long
Returns the connection timeout duration.long
int
This method provides the current count of active connections that the pool is managing.int
long
int
Returns the number of free connections currently available in the pool.int
Returns the highest number of open connections that were managed by the pool.int
Returns the highest number of free connections that were in the pool.int
Returns the highest number of pending requests.long
int
int
int
int
long
static ConnectionPool
A helper -static call to create an instance of the pool a la singleton This creates a static instance of Connection Pool and returns it to the calling application.int
How close to queueing did we get? High headroom means that load not high enough to warrant qeueing Zero Headroom means that queuing startedint
Returns the maximum number of connections allowed in the pool.int
Returns the maximum number of connections allowed in the pool.int
int
Returns the minimum number of connections allowed in the pool.int
Returns the minimum number of connections maintained in the pool.int
This method provides the count of connections that are available for use but are not currently allocated to any threads.int
This method provides the count of threads that are pending and waiting for a connection to become available.long
Returns the number of failed connection requests.long
Returns the number of high-priority failed connection requests.int
Returns the highest number of connections that were in use at any point in time.int
long
long
Returns the reconnection frequency in seconds.int
long
Returns the connection test frequency in seconds.long
int
int
protected void
Reads in all the property settings in the property file.protected boolean
isIdleConnection
(com.portal.pfc.infranet.connpool.ConnectionPool.TimedConnection tc) boolean
void
void
Close the bad connections TCP/IP socket, and decreasing the connection pool size.void
releaseConnection
(PortalContext connection) This method does the following: - Checks to see if there are any threads waiting, if not the connection is returned to the free pool and closeIdleConnections is called.protected void
void
void
Reset pool health highest stats.void
setConnectionIdleTime
(long newIdleTime) Sets the maximum allowed idle time for a connection in the pool.void
setConnectionReUseAlgorithm
(String algorithm) void
setConnectionTimeOut
(long poolTimeout) Sets the connection timeout duration.void
setConnPoolTimeout
(long poolTimeout) void
setIdleTime
(long newIdleTime) void
setMaxConnections
(int maxConns) Sets the maximum number of connections allowed in the pool.void
setMaxPoolSize
(int maxPoolSize) Set the maximum connection pool size.void
setMaxRequestListSize
(int reqQSize) void
setMinConnections
(int minConns) Sets the minimum number of connections allowed in the pool.void
setMinPoolSize
(int minPoolSize) Set the minimum connection pool size.void
setReconnectFrequency
(long reconnFreq) void
setReConnFrequency
(long reconFreq) Sets the frequency for reconnection attempts.void
setRequestQSize
(int reqSize) void
setTestConnectionFrequency
(long testFreq) Sets the frequency for testing connections.void
setTestFrequency
(long testFreq) void
setVerifyConnection
(boolean verifyConnection) void
-
Field Details
-
VAL_REUSE_ALGORITHM_MRU
Value indicating that the Most Recently Used (MRU) algorithm should be used for connection reuse- See Also:
-
VAL_REUSE_ALGORITHM_LRU
// Value indicating that the Least Recently Used (LRU) algorithm should be used for connection reuse- See Also:
-
PROP_REUSE_ALGORITHM
Property key for specifying the connection reuse algorithm- See Also:
-
PROP_VERIFY_CONNECTION
Property key for verifying connection status in the connection pool- See Also:
-
-
Constructor Details
-
ConnectionPool
Default connection pool constructor. This would read the property file (infranet.properties) entries using the classloader.- Parameters:
cf
- ConnectionFactory type to be set- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
ConnectionPool
Constructor that reads in Connectionpool-specific properties info from a properties object- Parameters:
cf
- ConnectionFactory type to be usedp
- Properties object- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
ConnectionPool
Constructor that takes an FList containing login params.- Parameters:
cf
- ConnectionFactory type to be usedconnFL
- connection FList- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
ConnectionPool
public ConnectionPool(String host, String port, String user, String password, String service) throws EBufException Constructor that takes a set of connection related properties. The properties reflect the elements needed to construct a pcp-like login uri.- Parameters:
host
- The hostname or IP address of the database or service.port
- The port number on which the database or service is listening.user
- The username used for authenticating the connection.password
- The password associated with the specified username.service
- The name of the service or database to connect to.- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
ConnectionPool
Constructor that reads in Connectionpool-specific properties info from a properties object. It takes a timeOut value in milliseconds for the opcode The timeout is set in the connection and it would be used for calling the opcode. The opcode may throw ERR_TIMEOUT error if the timeOut is exceeded for an opcode operation- Parameters:
cf
- TheConnectionFactory
used to create connections for the pool.p
- TheProperties
object containing configuration settings for the pool.timeOut
- The timeout value, in milliseconds, for establishing a connection.- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
-
Method Details
-
setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize) Set the maximum connection pool size.- Specified by:
setMaxPoolSize
in interfaceConnectionPoolMBean
-
getMaxPoolSize
public int getMaxPoolSize()Returns the maximum number of connections allowed in the pool.- Specified by:
getMaxPoolSize
in interfaceConnectionPoolMBean
- Returns:
- The maximum pool size as an
int
.
-
setMinPoolSize
public void setMinPoolSize(int minPoolSize) Set the minimum connection pool size.- Specified by:
setMinPoolSize
in interfaceConnectionPoolMBean
-
getMinPoolSize
public int getMinPoolSize()Returns the minimum number of connections maintained in the pool.- Specified by:
getMinPoolSize
in interfaceConnectionPoolMBean
- Returns:
- The minimum pool size as an
int
.
-
getFreeConnections
public int getFreeConnections()Returns the number of free connections currently available in the pool.- Specified by:
getFreeConnections
in interfaceConnectionPoolMBean
- Returns:
- The number of free connections as an
int
.
-
getUsedConnections
public int getUsedConnections()- Specified by:
getUsedConnections
in interfaceConnectionPoolMBean
-
getTotalConnections
public int getTotalConnections()- Specified by:
getTotalConnections
in interfaceConnectionPoolMBean
-
getConnPoolTimeout
public long getConnPoolTimeout()- Specified by:
getConnPoolTimeout
in interfaceConnectionPoolMBean
-
setConnPoolTimeout
public void setConnPoolTimeout(long poolTimeout) - Specified by:
setConnPoolTimeout
in interfaceConnectionPoolMBean
-
getIdleTime
public long getIdleTime()- Specified by:
getIdleTime
in interfaceConnectionPoolMBean
-
setIdleTime
public void setIdleTime(long newIdleTime) - Specified by:
setIdleTime
in interfaceConnectionPoolMBean
-
getRequestQSize
public int getRequestQSize()- Specified by:
getRequestQSize
in interfaceConnectionPoolMBean
-
setRequestQSize
public void setRequestQSize(int reqSize) - Specified by:
setRequestQSize
in interfaceConnectionPoolMBean
-
getPendingRequests
public int getPendingRequests()- Specified by:
getPendingRequests
in interfaceConnectionPoolMBean
-
getTestFrequency
public long getTestFrequency()- Specified by:
getTestFrequency
in interfaceConnectionPoolMBean
-
getReconnectFrequency
public long getReconnectFrequency()- Specified by:
getReconnectFrequency
in interfaceConnectionPoolMBean
-
getFailedConnRequest
public long getFailedConnRequest()- Specified by:
getFailedConnRequest
in interfaceConnectionPoolMBean
-
getHighFailedConnRequest
public long getHighFailedConnRequest()- Specified by:
getHighFailedConnRequest
in interfaceConnectionPoolMBean
-
getHighUsedConnections
public int getHighUsedConnections()- Specified by:
getHighUsedConnections
in interfaceConnectionPoolMBean
-
setTestFrequency
public void setTestFrequency(long testFreq) - Specified by:
setTestFrequency
in interfaceConnectionPoolMBean
-
setReconnectFrequency
public void setReconnectFrequency(long reconnFreq) - Specified by:
setReconnectFrequency
in interfaceConnectionPoolMBean
-
getHighFreeCons
public int getHighFreeCons()- Specified by:
getHighFreeCons
in interfaceConnectionPoolMBean
-
getHighTotalCons
public int getHighTotalCons()- Specified by:
getHighTotalCons
in interfaceConnectionPoolMBean
-
getHighPendingRequests
public int getHighPendingRequests()- Specified by:
getHighPendingRequests
in interfaceConnectionPoolMBean
-
getConnectionReUseAlgorithm
Retrieves the algorithm used for connection reuse.- Specified by:
getConnectionReUseAlgorithm
in interfaceConnectionPoolMBean
- Returns:
- The connection reuse algorithm as a
String
.
-
setConnectionReUseAlgorithm
- Specified by:
setConnectionReUseAlgorithm
in interfaceConnectionPoolMBean
-
isVerifyConnection
public boolean isVerifyConnection()- Specified by:
isVerifyConnection
in interfaceConnectionPoolMBean
-
setVerifyConnection
public void setVerifyConnection(boolean verifyConnection) - Specified by:
setVerifyConnection
in interfaceConnectionPoolMBean
-
reconnectAll
public void reconnectAll()- Specified by:
reconnectAll
in interfaceConnectionPoolMBean
-
init
Reads in all the property settings in the property file. Creates the FList encapsulating the login information Also creates min. number of connections with the login- Parameters:
connectionURL
- pcp-type URL (pcp://...)- Throws:
EBufException
- If there is an error related to buffer operations or data processing.
-
getConnection
Returns an instance of connection. Depending on the context factory either a PortalContext or a subclass(viz. PCachedContext) is returned If no connection is available, the requesting thread "wait"s until a connection is released from another thread or, the connection times out. If the caller times out before obtaining a connection a DeterminateException will be thrown - check the messageID of that exception for a value of 1 if you wish to distinguish between this reason for failure and other potential errors.- Returns:
- PortalContext
- Throws:
DeterminateException
- If there is an error while accessing instance of connection.
-
testFreeConnections
public void testFreeConnections() -
releaseConnection
This method does the following: - Checks to see if there are any threads waiting, if not the connection is returned to the free pool and closeIdleConnections is called. - If threads are waiting then verifyBadConnection(connection) method will be called to verify the connection. - Gets the first threads Timed Connection off the wait request queue. - Gives the TimedConnection to the request but only if the thread is still waiting. - If it is not still waiting then the request is removed from the queue and a NAP_CONNECTION_FAILED exception is thrown.- Parameters:
connection
- is the instances of connection
-
addToFreeConnection
Adds a connection to the pool of free connections.This method adds the specified connection to the list of free connections
- Parameters:
connection
- The connection to be added to the free connection pool.lastUsedTime
- The time when the connection was last used.descr
- A description or additional information about the connection.
-
releaseBadConnection
Close the bad connections TCP/IP socket, and decreasing the connection pool size.- Parameters:
pc
- PortalContext
-
closeConnection
Closes the specified connection and optionally decrements the connection count.- Parameters:
connection
- The connection to be closed.bDecCntFlag
- If true, decrement the connection count; otherwise, do not.
-
getMaxRequestListSize
public int getMaxRequestListSize() -
setMaxRequestListSize
public void setMaxRequestListSize(int reqQSize) -
getInstance
A helper -static call to create an instance of the pool a la singleton This creates a static instance of Connection Pool and returns it to the calling application. If one is already created, return that one- Returns:
- ConnectionPool instance
- Throws:
EBufException
- If an error occurs related to the buffer operation.
-
createInstance
A helper singleton that wraps the single-argument constructor- Parameters:
cf
- ConnectionFactory type- Throws:
EBufException
- If an error occurs related to the buffer operation.
-
createInstance
A helper singleton that wraps the 2-argument constructor- Parameters:
cf
- ConnectionFactory typefl
- FList containing login info- Throws:
EBufException
- If an error occurs related to the buffer operation.
-
createInstance
A helper singleton that wraps the (connection factory, properties) constructor- Parameters:
cf
- ConnectionFactory typep
- Properties containing the login info and connection pool settings- Throws:
EBufException
- If an error occurs related to the buffer operation.
-
getConnectionFactory
returns the current connection factory. This is a convenience method for the applications to know about the current connexion factory- Returns:
- ConnectionFactory
-
createConnections
Creates size number of connections and returns- Parameters:
size
- - number of connections to be created- Returns:
- array of connections truly created
- Throws:
EBufException
- If an error occurs related to the buffer operation.ParseException
- If there is an error parsing configuration data or connection parameters required for creating connections.
-
isIdleConnection
protected boolean isIdleConnection(com.portal.pfc.infranet.connpool.ConnectionPool.TimedConnection tc) -
closeIdleConnections
protected void closeIdleConnections()Closes any idle connections in the free-connection list. This has the effect of "shrinking" the pool. Here only the "over-the-min-limit" connections are checked for idle-time. If any they are removed. The connections that are not "idle" are recycled back to the free-pool. The connections to be checked are removed from the front of the Q and added at the end of the Q. -
renewAllConnections
protected void renewAllConnections() -
resetHighestStats
public void resetHighestStats()Reset pool health highest stats. -
resetFailCount
public void resetFailCount() -
getCurrentConnectionCount
public int getCurrentConnectionCount()This method provides the current count of active connections that the pool is managing. It is useful for monitoring the pool's usage and understanding how many connections are in use at any given time.
- Returns:
- number of open connections currently managed by the pool.
-
getCurrentUsedConnections
public int getCurrentUsedConnections() -
getNumberOfPendingRequests
public int getNumberOfPendingRequests()This method provides the count of threads that are pending and waiting for a connection to become available.
- Returns:
- number of threads waiting for a connection
-
getNumberOfFreeConnections
public int getNumberOfFreeConnections()This method provides the count of connections that are available for use but are not currently allocated to any threads.- Returns:
- number of free connections in the pool
-
getConnectionIdleTime
public long getConnectionIdleTime()Retrieves the maximum allowed idle time for a connection in the pool.This method returns the maximum amount of time (in milliseconds) that a connection can remain idle in the pool before it is considered for removal.
- Returns:
- The maximum idle time for a connection in the pool, in milliseconds.
-
setConnectionIdleTime
public void setConnectionIdleTime(long newIdleTime) Sets the maximum allowed idle time for a connection in the pool.This method updates the maximum idle time that a connection can remain idle in the pool before it is considered for removal.
- Parameters:
newIdleTime
- The new maximum idle time for a connection, in milliseconds.
-
getTestConnectionFrequency
public long getTestConnectionFrequency()Returns the connection test frequency in seconds.This method retrieves the frequency with which connections are tested, expressed in seconds.
- Returns:
- The connection test frequency in seconds.
-
getReConnFrequency
public long getReConnFrequency()Returns the reconnection frequency in seconds.This method retrieves the frequency at which reconnections are attempted, expressed in seconds.
- Returns:
- The reconnection frequency in seconds.
-
getNumFailedRequest
public long getNumFailedRequest()Returns the number of failed connection requests.This method retrieves the total count of connection requests that have failed.
- Returns:
- The number of failed connection requests.
-
getNumHighFailedRequest
public long getNumHighFailedRequest()Returns the number of high-priority failed connection requests.This method retrieves the total count of connection requests that have failed and are considered high-priority.
- Returns:
- The number of high-priority failed connection requests.
-
setTestConnectionFrequency
public void setTestConnectionFrequency(long testFreq) Sets the frequency for testing connections.This method sets the interval at which connections are tested, specified in milliseconds.
- Parameters:
testFreq
- The new connection test frequency, in milliseconds.
-
setReConnFrequency
public void setReConnFrequency(long reconFreq) Sets the frequency for reconnection attempts.This method sets the interval at which reconnections are attempted, specified in milliseconds.
- Parameters:
reconFreq
- The new reconnection frequency, in milliseconds.
-
getConnectionTimeOut
public long getConnectionTimeOut()Returns the connection timeout duration.This method retrieves the amount of time, in milliseconds, that the system will wait before considering a connection attempt as timed out.
- Returns:
- The connection timeout duration in milliseconds.
-
setConnectionTimeOut
public void setConnectionTimeOut(long poolTimeout) Sets the connection timeout duration.This method sets the amount of time, in milliseconds.
- Parameters:
poolTimeout
- The new connection timeout duration in milliseconds.
-
getMaxConnections
public int getMaxConnections()Returns the maximum number of connections allowed in the pool.This method retrieves the maximum number of connections that the pool can hold.
- Returns:
- The maximum number of connections allowed in the pool.
-
getMinConnections
public int getMinConnections()Returns the minimum number of connections allowed in the pool.This method retrieves the minimum number of connections that the pool can hold.
- Returns:
- The minimum number of connections allowed in the pool.
-
setMaxConnections
public void setMaxConnections(int maxConns) Sets the maximum number of connections allowed in the pool.This method updates the maximum number of connections that the pool can hold.
- Parameters:
maxConns
- The new maximum number of connections allowed in the pool.
-
setMinConnections
public void setMinConnections(int minConns) Sets the minimum number of connections allowed in the pool.This method updates the minimum number of connections that the pool can hold.
- Parameters:
minConns
- The new minimum number of connections allowed in the pool.
-
getHighestCurConnCount
public int getHighestCurConnCount()Returns the highest number of open connections that were managed by the pool.This method provides the maximum number of concurrent connections that have been active in the pool at any point in time.
- Returns:
- highest number of open connections that were managed by the pool.
-
getHighestFree
public int getHighestFree()Returns the highest number of free connections that were in the pool.This method provides the maximum number of free connections that were available in the pool at any point in time.
- Returns:
- highest number of free connections that were in the pool
-
getNumHighUsedConnections
public int getNumHighUsedConnections()Returns the highest number of connections that were in use at any point in time.This method provides the peak number of connections that were actively in use by the pool.
- Returns:
- highest number of used connections that were in the pool
-
getHighestRequestListSize
public int getHighestRequestListSize()Returns the highest number of pending requests.This method provides the maximum number of requests that were waitinh.
- Returns:
- the highest number of threads blocked waiting for a connection
-
getLowestHeadroom
public int getLowestHeadroom()How close to queueing did we get? High headroom means that load not high enough to warrant qeueing Zero Headroom means that queuing started- Returns:
- mLowestHeadroom
-