java.lang.Object
org.mariadb.jdbc.internal.util.pool.Pool
All Implemented Interfaces:
AutoCloseable, PoolMBean

public class Pool extends Object implements AutoCloseable, PoolMBean
  • Field Details

  • Constructor Details

    • Pool

      public Pool(UrlParser urlParser, int poolIndex, ScheduledThreadPoolExecutor poolExecutor)
      Create pool from configuration.
      Parameters:
      urlParser - configuration parser
      poolIndex - pool index to permit distinction of thread name
      poolExecutor - pools common executor
  • Method Details

    • addConnectionRequest

      private void addConnectionRequest()
      Add new connection if needed. Only one thread create new connection, so new connection request will wait to newly created connection or for a released connection.
    • removeIdleTimeoutConnection

      private void removeIdleTimeoutConnection()
      Removing idle connection. Close them and recreate connection to reach minimal number of connection.
    • addConnection

      private void addConnection() throws SQLException
      Create new connection.
      Throws:
      SQLException - if connection creation failed
    • getIdleConnection

      private MariaDbPooledConnection getIdleConnection() throws InterruptedException
      Throws:
      InterruptedException
    • getIdleConnection

      private MariaDbPooledConnection getIdleConnection(long timeout, TimeUnit timeUnit) throws InterruptedException
      Get an existing idle connection in pool.
      Returns:
      an IDLE connection.
      Throws:
      InterruptedException
    • silentCloseConnection

      private void silentCloseConnection(MariaDbPooledConnection item)
    • silentAbortConnection

      private void silentAbortConnection(MariaDbPooledConnection item)
    • createPoolConnection

      private MariaDbPooledConnection createPoolConnection(MariaDbConnection connection)
    • getConnection

      public MariaDbConnection getConnection() throws SQLException
      Retrieve new connection. If possible return idle connection, if not, stack connection query, ask for a connection creation, and loop until a connection become idle / a new connection is created.
      Returns:
      a connection object
      Throws:
      SQLException - if no connection is created when reaching timeout (connectTimeout option)
    • getConnection

      public MariaDbConnection getConnection(String username, String password) throws SQLException
      Get new connection from pool if user and password correspond to pool. If username and password are different from pool, will return a dedicated connection.
      Parameters:
      username - username
      password - password
      Returns:
      connection
      Throws:
      SQLException - if any error occur during connection
    • generatePoolTag

      private String generatePoolTag(int poolIndex)
    • getUrlParser

      public UrlParser getUrlParser()
    • close

      public void close() throws InterruptedException
      Close pool and underlying connections.
      Specified by:
      close in interface AutoCloseable
      Throws:
      InterruptedException - if interrupted
    • closeAll

      private void closeAll(ExecutorService connectionRemover, Collection<MariaDbPooledConnection> collection)
    • initializePoolGlobalState

      private void initializePoolGlobalState(MariaDbConnection connection) throws SQLException
      Throws:
      SQLException
    • getPoolTag

      public String getPoolTag()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getGlobalInfo

      public GlobalStateInfo getGlobalInfo()
    • getActiveConnections

      public long getActiveConnections()
      Specified by:
      getActiveConnections in interface PoolMBean
    • getTotalConnections

      public long getTotalConnections()
      Specified by:
      getTotalConnections in interface PoolMBean
    • getIdleConnections

      public long getIdleConnections()
      Specified by:
      getIdleConnections in interface PoolMBean
    • getConnectionRequests

      public long getConnectionRequests()
      Specified by:
      getConnectionRequests in interface PoolMBean
    • registerJmx

      private void registerJmx() throws Exception
      Throws:
      Exception
    • unRegisterJmx

      private void unRegisterJmx() throws Exception
      Throws:
      Exception
    • testGetConnectionIdleThreadIds

      public List<Long> testGetConnectionIdleThreadIds()
      For testing purpose only.
      Returns:
      current thread id's
    • resetStaticGlobal

      public void resetStaticGlobal()
      JMX method to remove state (will be reinitialized on next connection creation).
      Specified by:
      resetStaticGlobal in interface PoolMBean