public class BoneCP extends Object implements Serializable, Closeable
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
cachedPoolStrategy
Config setting.
|
protected Properties |
clientInfo
Config setting.
|
protected boolean |
closeConnectionWatch
If set to true, create a new thread that monitors a connection and displays warnings if application failed to
close the connection.
|
protected BoneCPConfig |
config
Configuration object used in constructor.
|
protected static String |
connectionClass
This is moved here to aid testing.
|
protected ConnectionStrategy |
connectionStrategy
Currently active get connection strategy class to use.
|
protected long |
connectionTimeoutInMs
Time to wait before timing out the connection.
|
protected boolean |
driverInitialized
If false, we haven't made a dummy driver call first.
|
protected int |
jvmMajorVersion
Keep track of our jvm version.
|
protected ScheduledExecutorService |
keepAliveScheduler
Handle to factory that creates 1 thread per partition that periodically wakes up and performs some
activity on the connection.
|
static String |
MBEAN_BONECP
JMX constant.
|
static String |
MBEAN_CONFIG
JMX constant.
|
protected boolean |
nullOnConnectionTimeout
Config setting.
|
protected int |
partitionCount
Number of partitions passed in constructor.
|
protected ConnectionPartition[] |
partitions
Partitions handle.
|
protected int |
poolAvailabilityThreshold
Create more connections when we hit x% of our possible number of connections.
|
protected boolean |
poolShuttingDown
set to true if the connection pool has been flagged as shutting down.
|
protected boolean |
resetConnectionOnClose
Config setting.
|
protected String |
shutdownStackTrace
Placeholder to give more useful info in case of a double shutdown.
|
protected Statistics |
statistics
statistics handle.
|
protected boolean |
statisticsEnabled
if true, we care about statistics.
|
| Constructor and Description |
|---|
BoneCP(BoneCPConfig config)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
captureStackTrace(String message)
Throw an exception to capture it so as to be able to print it out later on
|
void |
close()
Just a synonym to shutdown.
|
protected void |
destroyConnection(ConnectionHandle conn)
Physically close off the internal connection.
|
com.google.common.util.concurrent.ListenableFuture<Connection> |
getAsyncConnection()
Obtain a connection asynchronously by queueing a request to obtain a connection in a separate thread.
|
BoneCPConfig |
getConfig()
Gets config object.
|
Connection |
getConnection()
Returns a free connection.
|
AtomicBoolean |
getDbIsDown()
Returns the dbIsDown field.
|
protected com.google.common.base.FinalizableReferenceQueue |
getFinalizableRefQueue()
Watch for connections that should have been safely closed but the application forgot.
|
protected Map<Connection,Reference<ConnectionHandle>> |
getFinalizableRefs()
Return the finalizable refs handle.
|
Statistics |
getStatistics()
Returns a reference to the statistics class.
|
int |
getTotalCreatedConnections()
Return total number of connections created in all partitions.
|
int |
getTotalFree()
Return the number of free connections available to an application right away (excluding connections that can be
created dynamically)
|
int |
getTotalLeased()
Return total number of connections currently in use by an application
|
protected void |
internalReleaseConnection(ConnectionHandle connectionHandle)
Release a connection by placing the connection back in the pool.
|
boolean |
isConnectionHandleAlive(ConnectionHandle connection)
Sends a dummy statement to the server to keep the connection alive
|
protected void |
maybeSignalForMoreConnections(ConnectionPartition connectionPartition)
Tests if this partition has hit a threshold and signal to the pool watch thread to create new connections
|
protected Connection |
obtainInternalConnection(ConnectionHandle connectionHandle)
Obtains a database connection, retrying if necessary.
|
protected Connection |
obtainRawInternalConnection()
Returns a database connection by using Driver.getConnection() or DataSource.getConnection()
|
protected void |
postDestroyConnection(ConnectionHandle handle)
Update counters and call hooks.
|
protected void |
putConnectionBackInPartition(ConnectionHandle connectionHandle)
Places a connection back in the originating partition.
|
protected void |
registerUnregisterJMX(boolean doRegister)
Initialises JMX stuff.
|
protected void |
releaseConnection(Connection connection)
Releases the given connection back to the pool.
|
void |
shutdown()
Closes off this connection pool.
|
protected void |
unregisterDriver()
Drops a driver from the DriverManager's list.
|
protected void |
watchConnection(ConnectionHandle connectionHandle)
Starts off a new thread to monitor this connection attempt.
|
public static final String MBEAN_CONFIG
public static final String MBEAN_BONECP
protected final int poolAvailabilityThreshold
protected int partitionCount
protected ConnectionPartition[] partitions
protected ScheduledExecutorService keepAliveScheduler
protected BoneCPConfig config
protected boolean closeConnectionWatch
protected volatile boolean poolShuttingDown
protected String shutdownStackTrace
protected long connectionTimeoutInMs
protected boolean statisticsEnabled
protected Statistics statistics
protected boolean nullOnConnectionTimeout
protected boolean resetConnectionOnClose
protected boolean cachedPoolStrategy
protected ConnectionStrategy connectionStrategy
protected Properties clientInfo
protected volatile boolean driverInitialized
protected int jvmMajorVersion
protected static String connectionClass
public BoneCP(BoneCPConfig config) throws SQLException
config - Configuration for poolSQLException - on errorpublic void shutdown()
protected void unregisterDriver()
public void close()
close in interface Closeableclose in interface AutoCloseableprotected void destroyConnection(ConnectionHandle conn)
conn - protected void postDestroyConnection(ConnectionHandle handle)
handle - connection handle.protected Connection obtainInternalConnection(ConnectionHandle connectionHandle) throws SQLException
connectionHandle - SQLExceptionprotected Connection obtainRawInternalConnection() throws SQLException
SQLException - on errorprotected void registerUnregisterJMX(boolean doRegister)
doRegister - if true, perform registration, if false unregisterpublic Connection getConnection() throws SQLException
SQLExceptionprotected void watchConnection(ConnectionHandle connectionHandle)
connectionHandle - to monitorprotected String captureStackTrace(String message)
message - message to displaypublic com.google.common.util.concurrent.ListenableFuture<Connection> getAsyncConnection()
Future<Connection> result = pool.getAsyncConnection();
... do something else in your application here ...
Connection connection = result.get(); // get the connection
protected void maybeSignalForMoreConnections(ConnectionPartition connectionPartition)
connectionPartition - to test for.protected void releaseConnection(Connection connection) throws SQLException
connection - to releaseSQLExceptionprotected void internalReleaseConnection(ConnectionHandle connectionHandle) throws SQLException
connectionHandle - Connection being released.SQLExceptionprotected void putConnectionBackInPartition(ConnectionHandle connectionHandle) throws SQLException
connectionHandle - to place backSQLException - on errorpublic boolean isConnectionHandleAlive(ConnectionHandle connection)
connection - Connection handle to perform activity onpublic int getTotalLeased()
public int getTotalFree()
public int getTotalCreatedConnections()
public BoneCPConfig getConfig()
protected Map<Connection,Reference<ConnectionHandle>> getFinalizableRefs()
protected com.google.common.base.FinalizableReferenceQueue getFinalizableRefQueue()
public Statistics getStatistics()
public AtomicBoolean getDbIsDown()
Copyright © 2009-2013 JolBox. All Rights Reserved.