Class ConnectorPool


  • public class ConnectorPool
    extends java.lang.Object
    This class is a pool for connectors. It stores certain amount and can give them when needed. When not needed the connectors can be returned to the pool. Also the pool is periodically purged, thus shrunk to a specified size.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConnectorPool​(java.lang.String aConnectorLibName, PoolDefConfig aPoolDefConfig, Log aLog)
      Constructor of the connector pool.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ConnectorInterface getConnector()
      Returns a connector from the pool.
      ConnectorInterface getConnector​(boolean aWaitOnExhausted)
      Returns a connector from the pool if there is an available free one.
      int getFreeConnectorsNum()
      Returns the count of the free connectors in the pool.
      java.lang.String getName()
      Returns the name of the connector pool.
      PoolDefConfig getPoolConfig()
      Returns the pool configuration.
      int getSize()
      Returns the size of the pool (the count of connectors in it).
      void initialize()
      Initializes the connector pool.
      void purge()
      Removes connectors from the pool and the free connectors collection until the minimum size of the pool is reached.
      void returnConnector​(ConnectorInterface aConnector)
      Returns a connector to the pool and enlists it again in the free connectors.
      void terminate()
      Terminates the connector pool.
      • Methods inherited from class java.lang.Object

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

      • ConnectorPool

        public ConnectorPool​(java.lang.String aConnectorLibName,
                             PoolDefConfig aPoolDefConfig,
                             Log aLog)
                      throws java.lang.Exception
        Constructor of the connector pool.
        Parameters:
        aConnectorLibName - a connector pool name used for logging.
        aPoolDefConfig - a default configuration for the pool
        aLog - a Log object used to log messages to log files
        Throws:
        java.lang.Exception
    • Method Detail

      • initialize

        public void initialize()
                        throws java.lang.Exception
        Initializes the connector pool.
        Throws:
        java.lang.Exception - if a problem occurs
      • terminate

        public void terminate()
                       throws java.lang.Exception
        Terminates the connector pool. Closes connections and frees resources taken from the free connectors in the pool. Also terminates the timer used to perform shrink operations.
        Throws:
        java.lang.Exception - if a problem occurs
      • getName

        public java.lang.String getName()
        Returns the name of the connector pool.
        Returns:
        the connector pool's name
      • getSize

        public int getSize()
        Returns the size of the pool (the count of connectors in it).
        Returns:
        pool size
      • getFreeConnectorsNum

        public int getFreeConnectorsNum()
        Returns the count of the free connectors in the pool.
        Returns:
        free connectors number
      • getPoolConfig

        public PoolDefConfig getPoolConfig()
        Returns the pool configuration.
        Returns:
        the default pool configuration
      • getConnector

        public ConnectorInterface getConnector()
                                        throws java.lang.Exception
        Returns a connector from the pool. Waits until a connector is returned to the pool and uses it.
        Returns:
        a connector
        Throws:
        java.lang.Exception - if a problem occurs
      • getConnector

        public ConnectorInterface getConnector​(boolean aWaitOnExhausted)
                                        throws java.lang.Exception
        Returns a connector from the pool if there is an available free one. If the aWaitOnExhausted option is used, this method will wait for a connector to be returned to the pool and use it. When a connector is taken from the pool it is no longer a free connector but a used one.
        Parameters:
        aWaitOnExhausted - whether to wait for a connector to be returned to the pool, or take one directly
        Returns:
        a connector.
        Throws:
        java.lang.Exception - if a problem occurs
      • returnConnector

        public void returnConnector​(ConnectorInterface aConnector)
                             throws java.lang.Exception
        Returns a connector to the pool and enlists it again in the free connectors.
        Parameters:
        aConnector - the returned connector
        Throws:
        java.lang.Exception - if a problem occurs
      • purge

        public void purge()
        Removes connectors from the pool and the free connectors collection until the minimum size of the pool is reached.