Class Pool
- java.lang.Object
-
- org.mariadb.jdbc.internal.util.pool.Pool
-
- All Implemented Interfaces:
AutoCloseable
,PoolMBean
public class Pool extends Object implements AutoCloseable, PoolMBean
-
-
Constructor Summary
Constructors Constructor Description Pool(UrlParser urlParser, int poolIndex, ScheduledThreadPoolExecutor poolExecutor)
Create pool from configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close pool and underlying connections.boolean
equals(Object obj)
long
getActiveConnections()
MariaDbConnection
getConnection()
Retrieve new connection.MariaDbConnection
getConnection(String username, String password)
Get new connection from pool if user and password correspond to pool.long
getConnectionRequests()
GlobalStateInfo
getGlobalInfo()
long
getIdleConnections()
String
getPoolTag()
long
getTotalConnections()
UrlParser
getUrlParser()
int
hashCode()
void
resetStaticGlobal()
JMX method to remove state (will be reinitialized on next connection creation).List<Long>
testGetConnectionIdleThreadIds()
For testing purpose only.
-
-
-
Constructor Detail
-
Pool
public Pool(UrlParser urlParser, int poolIndex, ScheduledThreadPoolExecutor poolExecutor)
Create pool from configuration.- Parameters:
urlParser
- configuration parserpoolIndex
- pool index to permit distinction of thread namepoolExecutor
- pools common executor
-
-
Method Detail
-
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
- usernamepassword
- password- Returns:
- connection
- Throws:
SQLException
- if any error occur during connection
-
getUrlParser
public UrlParser getUrlParser()
-
close
public void close() throws InterruptedException
Close pool and underlying connections.- Specified by:
close
in interfaceAutoCloseable
- Throws:
InterruptedException
- if interrupted
-
getPoolTag
public String getPoolTag()
-
getGlobalInfo
public GlobalStateInfo getGlobalInfo()
-
getActiveConnections
public long getActiveConnections()
- Specified by:
getActiveConnections
in interfacePoolMBean
-
getTotalConnections
public long getTotalConnections()
- Specified by:
getTotalConnections
in interfacePoolMBean
-
getIdleConnections
public long getIdleConnections()
- Specified by:
getIdleConnections
in interfacePoolMBean
-
getConnectionRequests
public long getConnectionRequests()
- Specified by:
getConnectionRequests
in interfacePoolMBean
-
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 interfacePoolMBean
-
-