Class ConnectionPool

java.lang.Object
com.portal.pfc.infranet.connpool.ConnectionPool
All Implemented Interfaces:
ConnectionPoolMBean

public class ConnectionPool extends Object implements ConnectionPoolMBean
This provides encapsulation for many connections (connection pool) for a end-client (webkit, cdk). In other words this manages the multiple CM connections. This is modeled after PortalConnectionPool in CDK and roughly compares to PPooledConnectionClientServices in the BAS world. This class internally has a delegate to ConnectionFactory object which really builds the objects we need.

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 Details

    • VAL_REUSE_ALGORITHM_MRU

      public static final String 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

      public static final String VAL_REUSE_ALGORITHM_LRU
      // Value indicating that the Least Recently Used (LRU) algorithm should be used for connection reuse
      See Also:
    • PROP_REUSE_ALGORITHM

      public static final String PROP_REUSE_ALGORITHM
      Property key for specifying the connection reuse algorithm
      See Also:
    • PROP_VERIFY_CONNECTION

      public static final String PROP_VERIFY_CONNECTION
      Property key for verifying connection status in the connection pool
      See Also:
  • Constructor Details

    • ConnectionPool

      public ConnectionPool(ConnectionFactory cf) throws EBufException
      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

      public ConnectionPool(ConnectionFactory cf, Properties p) throws EBufException
      Constructor that reads in Connectionpool-specific properties info from a properties object
      Parameters:
      cf - ConnectionFactory type to be used
      p - Properties object
      Throws:
      EBufException - If there is an error related to buffer operations or data processing.
    • ConnectionPool

      public ConnectionPool(ConnectionFactory cf, FList connFL) throws EBufException
      Constructor that takes an FList containing login params.
      Parameters:
      cf - ConnectionFactory type to be used
      connFL - 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

      public ConnectionPool(ConnectionFactory cf, Properties p, int timeOut) throws EBufException
      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 - The ConnectionFactory used to create connections for the pool.
      p - The Properties 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 interface ConnectionPoolMBean
    • getMaxPoolSize

      public int getMaxPoolSize()
      Returns the maximum number of connections allowed in the pool.
      Specified by:
      getMaxPoolSize in interface ConnectionPoolMBean
      Returns:
      The maximum pool size as an int.
    • setMinPoolSize

      public void setMinPoolSize(int minPoolSize)
      Set the minimum connection pool size.
      Specified by:
      setMinPoolSize in interface ConnectionPoolMBean
    • getMinPoolSize

      public int getMinPoolSize()
      Returns the minimum number of connections maintained in the pool.
      Specified by:
      getMinPoolSize in interface ConnectionPoolMBean
      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 interface ConnectionPoolMBean
      Returns:
      The number of free connections as an int.
    • getUsedConnections

      public int getUsedConnections()
      Specified by:
      getUsedConnections in interface ConnectionPoolMBean
    • getTotalConnections

      public int getTotalConnections()
      Specified by:
      getTotalConnections in interface ConnectionPoolMBean
    • getConnPoolTimeout

      public long getConnPoolTimeout()
      Specified by:
      getConnPoolTimeout in interface ConnectionPoolMBean
    • setConnPoolTimeout

      public void setConnPoolTimeout(long poolTimeout)
      Specified by:
      setConnPoolTimeout in interface ConnectionPoolMBean
    • getIdleTime

      public long getIdleTime()
      Specified by:
      getIdleTime in interface ConnectionPoolMBean
    • setIdleTime

      public void setIdleTime(long newIdleTime)
      Specified by:
      setIdleTime in interface ConnectionPoolMBean
    • getRequestQSize

      public int getRequestQSize()
      Specified by:
      getRequestQSize in interface ConnectionPoolMBean
    • setRequestQSize

      public void setRequestQSize(int reqSize)
      Specified by:
      setRequestQSize in interface ConnectionPoolMBean
    • getPendingRequests

      public int getPendingRequests()
      Specified by:
      getPendingRequests in interface ConnectionPoolMBean
    • getTestFrequency

      public long getTestFrequency()
      Specified by:
      getTestFrequency in interface ConnectionPoolMBean
    • getReconnectFrequency

      public long getReconnectFrequency()
      Specified by:
      getReconnectFrequency in interface ConnectionPoolMBean
    • getFailedConnRequest

      public long getFailedConnRequest()
      Specified by:
      getFailedConnRequest in interface ConnectionPoolMBean
    • getHighFailedConnRequest

      public long getHighFailedConnRequest()
      Specified by:
      getHighFailedConnRequest in interface ConnectionPoolMBean
    • getHighUsedConnections

      public int getHighUsedConnections()
      Specified by:
      getHighUsedConnections in interface ConnectionPoolMBean
    • setTestFrequency

      public void setTestFrequency(long testFreq)
      Specified by:
      setTestFrequency in interface ConnectionPoolMBean
    • setReconnectFrequency

      public void setReconnectFrequency(long reconnFreq)
      Specified by:
      setReconnectFrequency in interface ConnectionPoolMBean
    • getHighFreeCons

      public int getHighFreeCons()
      Specified by:
      getHighFreeCons in interface ConnectionPoolMBean
    • getHighTotalCons

      public int getHighTotalCons()
      Specified by:
      getHighTotalCons in interface ConnectionPoolMBean
    • getHighPendingRequests

      public int getHighPendingRequests()
      Specified by:
      getHighPendingRequests in interface ConnectionPoolMBean
    • getConnectionReUseAlgorithm

      public String getConnectionReUseAlgorithm()
      Retrieves the algorithm used for connection reuse.
      Specified by:
      getConnectionReUseAlgorithm in interface ConnectionPoolMBean
      Returns:
      The connection reuse algorithm as a String.
    • setConnectionReUseAlgorithm

      public void setConnectionReUseAlgorithm(String algorithm)
      Specified by:
      setConnectionReUseAlgorithm in interface ConnectionPoolMBean
    • isVerifyConnection

      public boolean isVerifyConnection()
      Specified by:
      isVerifyConnection in interface ConnectionPoolMBean
    • setVerifyConnection

      public void setVerifyConnection(boolean verifyConnection)
      Specified by:
      setVerifyConnection in interface ConnectionPoolMBean
    • reconnectAll

      public void reconnectAll()
      Specified by:
      reconnectAll in interface ConnectionPoolMBean
    • init

      protected void init(String connectionURL) throws EBufException
      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

      public PortalContext getConnection() throws DeterminateException
      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

      public 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. - 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

      public void addToFreeConnection(PortalContext connection, long lastUsedTime, String descr)
      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

      public void releaseBadConnection(PortalContext pc)
      Close the bad connections TCP/IP socket, and decreasing the connection pool size.
      Parameters:
      pc - PortalContext
    • closeConnection

      public void closeConnection(PortalContext connection, boolean bDecCntFlag)
      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

      public static ConnectionPool getInstance() throws EBufException
      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

      public static void createInstance(ConnectionFactory cf) throws EBufException
      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

      public static void createInstance(ConnectionFactory cf, FList fl) throws EBufException
      A helper singleton that wraps the 2-argument constructor
      Parameters:
      cf - ConnectionFactory type
      fl - FList containing login info
      Throws:
      EBufException - If an error occurs related to the buffer operation.
    • createInstance

      public static void createInstance(ConnectionFactory cf, Properties p) throws EBufException
      A helper singleton that wraps the (connection factory, properties) constructor
      Parameters:
      cf - ConnectionFactory type
      p - Properties containing the login info and connection pool settings
      Throws:
      EBufException - If an error occurs related to the buffer operation.
    • getConnectionFactory

      public ConnectionFactory getConnectionFactory()
      returns the current connection factory. This is a convenience method for the applications to know about the current connexion factory
      Returns:
      ConnectionFactory
    • createConnections

      protected Object[] createConnections(int size) throws EBufException, ParseException
      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