Class ConnectionPoolUtil


  • public class ConnectionPoolUtil
    extends java.lang.Object
    This SessionPoolUtil is used to handle and create the connection poolUtil. Internally the GenericKeyedObjectPool (Apache Commons Pool) is used. Pleas refer to the following website to get more information about the GenericKeyedObjectPool: http://commons.apache.org/pool/apidocs/org/apache/commons/pool/impl/GenericKeyedObjectPool.html
    Following properties are needed in given property maps to initialize the pool properly: - poolUtil.test.on.return -> default = false
    - poolUtil.test.while.idle -> default = false
    - pool.min.idle -> default = 0
    - pool.max.idle -> default = 8
    - pool.max.active -> default = 10
    - pool.max.total -> default = -1
    - pool.max.wait -> default = -1
    - pool.idle.test.count -> default = 3
    - pool.exhausted.action -> default = 1
    - pool.time.between.eviction -> default = 120000 // 2min - pool.idle.test.count -> default = 3 - pool.idle.min.evictable.time -> default = 120000 // 2min
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.saperion.connector.authentication.Session borrowObject​(com.lexmark.saperion.remote.common.authentication.Credentials key)
      Borrows an object from the keyed pool associated with the given key.
      static org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig buildPoolConfig​(java.util.Properties poolConfiguration)  
      void clearPool()
      Clears the used object poolUtil.
      org.apache.commons.pool2.impl.GenericKeyedObjectPool<com.lexmark.saperion.remote.common.authentication.Credentials,​com.saperion.connector.authentication.Session> getObjectPool()
      Gets the object pool.
      void initialize​(java.util.Properties configuration)
      C'tor taking the pool- and saperion classic connector configuration as combined Properties object.
      void initialize​(java.util.Properties poolConfiguration, GenericKeyedSessionPoolFactory sessionPoolFactory, java.lang.String saperionPropertiesPath)
      Initializes the pool with the given configurations and properties.
      void initialize​(java.util.Properties poolConfiguration, java.lang.String saperionPropertiesPath)
      Initializes the pool with the given configurations and properties.
      void initialize​(java.util.Properties poolConfiguration, java.util.Properties saperionProperties)
      Initializes the pool with the given configurations and properties.
      void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration, GenericKeyedSessionPoolFactory sessionPoolFactory, java.lang.String saperionPropertiesPath)
      Initializes the pool with the given configurations and properties.
      void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration, java.lang.String saperionPropertiesPath)
      Initializes the pool with the given configurations and properties.
      void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration, java.util.Properties saperionProperties)
      Initializes the pool with the given configurations and properties.
      void logStatisticPeriodically​(java.lang.String poolName, long initDelay, long period, java.util.concurrent.TimeUnit unit)
      INFO-logs the pool statistics periodically in an extra Thread.
      void printPoolStatistic()
      Prints the pool statistic.
      void returnObject​(com.lexmark.saperion.remote.common.authentication.Credentials key, com.saperion.connector.authentication.Session value)
      Returns an object to a keyed pool.
      void shutdown()
      Closes the poolUtil.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConnectionPoolUtil

        public ConnectionPoolUtil()
    • Method Detail

      • buildPoolConfig

        public static org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig buildPoolConfig​(java.util.Properties poolConfiguration)
      • initialize

        public void initialize​(java.util.Properties poolConfiguration,
                               java.lang.String saperionPropertiesPath)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The Properties object which is used to build the poolUtil configuration.
        saperionPropertiesPath - the path to the configuration files
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(java.util.Properties poolConfiguration,
                               GenericKeyedSessionPoolFactory sessionPoolFactory,
                               java.lang.String saperionPropertiesPath)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The Properties object which is used to build the poolUtil configuration.
        saperionPropertiesPath - the path to the configuration files
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration,
                               java.lang.String saperionPropertiesPath)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The pool configuration object.
        saperionPropertiesPath - the path to the configuration files
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration,
                               GenericKeyedSessionPoolFactory sessionPoolFactory,
                               java.lang.String saperionPropertiesPath)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The pool configuration object.
        sessionPoolFactory - factory which is responsible to create the pool objects e.g. GenericKeyedSessionPoolFactory or TechUserKeyedSessionPoolFactory
        saperionPropertiesPath - the path to the configuration files
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(java.util.Properties poolConfiguration,
                               java.util.Properties saperionProperties)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The pool configuration object.
        saperionProperties - the classic connector configuration
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig poolConfiguration,
                               java.util.Properties saperionProperties)
                        throws java.lang.Exception
        Initializes the pool with the given configurations and properties.
        Parameters:
        poolConfiguration - The pool configuration object.
        saperionProperties - the classic connector configuration
        Throws:
        java.lang.Exception - if an error occurs.
      • initialize

        public void initialize​(java.util.Properties configuration)
        C'tor taking the pool- and saperion classic connector configuration as combined Properties object.
        Parameters:
        configuration - the pool- and saperion classic connector configuration.
      • clearPool

        public void clearPool()
                       throws FactoryException
        Clears the used object poolUtil.
        Throws:
        FactoryException - if an connection factory failure occurs.
      • getObjectPool

        public org.apache.commons.pool2.impl.GenericKeyedObjectPool<com.lexmark.saperion.remote.common.authentication.Credentials,​com.saperion.connector.authentication.Session> getObjectPool()
        Gets the object pool.
        Returns:
        the object pool.
      • printPoolStatistic

        public void printPoolStatistic()
        Prints the pool statistic.
      • logStatisticPeriodically

        public void logStatisticPeriodically​(java.lang.String poolName,
                                             long initDelay,
                                             long period,
                                             java.util.concurrent.TimeUnit unit)
        INFO-logs the pool statistics periodically in an extra Thread.
        Parameters:
        poolName -
        initDelay -
        period -
        unit -
      • borrowObject

        public com.saperion.connector.authentication.Session borrowObject​(com.lexmark.saperion.remote.common.authentication.Credentials key)
                                                                   throws java.lang.Exception
        Borrows an object from the keyed pool associated with the given key.
        Parameters:
        key - the key to identify the object
        Returns:
        the object (Session) associated with the key
        Throws:
        java.lang.Exception - when make object throws an exception
        See Also:
        GenericKeyedObjectPool.borrowObject(Object)
      • returnObject

        public void returnObject​(com.lexmark.saperion.remote.common.authentication.Credentials key,
                                 com.saperion.connector.authentication.Session value)
                          throws java.lang.Exception
        Returns an object to a keyed pool.
        Parameters:
        key - the objects key
        value - the object (Session) to return
        Throws:
        java.lang.Exception - when returning the session failed