Minor cleanup suggested by Nitin

pull/333/head
Brett Wooldridge 10 years ago
parent 826257058b
commit 8993f4d0be

@ -193,7 +193,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
final long now = clockSource.currentTime(); final long now = clockSource.currentTime();
if (bagEntry.evicted || (clockSource.elapsedMillis(bagEntry.lastAccess, now) > ALIVE_BYPASS_WINDOW_MS && !isConnectionAlive(bagEntry.connection))) { if (bagEntry.evicted || (clockSource.elapsedMillis(bagEntry.lastAccess, now) > ALIVE_BYPASS_WINDOW_MS && !isConnectionAlive(bagEntry.connection))) {
closeConnection(bagEntry, "connection evicted or dead"); // Throw away the dead connection and try again closeConnection(bagEntry, "(connection evicted or dead)"); // Throw away the dead connection and try again
timeout = hardTimeout - clockSource.elapsedMillis(startTime, now); timeout = hardTimeout - clockSource.elapsedMillis(startTime, now);
} }
else { else {
@ -225,7 +225,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
metricsTracker.recordConnectionUsage(bagEntry); metricsTracker.recordConnectionUsage(bagEntry);
if (bagEntry.evicted) { if (bagEntry.evicted) {
closeConnection(bagEntry, "connection broken or evicted"); closeConnection(bagEntry, "(connection broken or evicted)");
} }
else { else {
connectionBag.requite(bagEntry); connectionBag.requite(bagEntry);
@ -285,7 +285,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
*/ */
public final void evictConnection(IHikariConnectionProxy proxyConnection) public final void evictConnection(IHikariConnectionProxy proxyConnection)
{ {
closeConnection(proxyConnection.getPoolBagEntry(), "connection evicted by user"); closeConnection(proxyConnection.getPoolBagEntry(), "(connection evicted by user)");
} }
/** /**
@ -416,7 +416,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
for (PoolBagEntry bagEntry : connectionBag.values(STATE_NOT_IN_USE)) { for (PoolBagEntry bagEntry : connectionBag.values(STATE_NOT_IN_USE)) {
if (connectionBag.reserve(bagEntry)) { if (connectionBag.reserve(bagEntry)) {
closeConnection(bagEntry, "connection evicted by user"); closeConnection(bagEntry, "(connection evicted by user)");
} }
} }
} }
@ -521,7 +521,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
if (poolState == POOL_NORMAL) { if (poolState == POOL_NORMAL) {
LOGGER.debug("Connection attempt to database in pool {} failed: {}", config.getPoolName(), e.getMessage(), e); LOGGER.debug("Connection attempt to database in pool {} failed: {}", config.getPoolName(), e.getMessage(), e);
} }
poolUtils.quietlyCloseConnection(connection, "exception during connection creation"); poolUtils.quietlyCloseConnection(connection, "(exception during connection creation)");
return false; return false;
} }
} }
@ -595,7 +595,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
bagEntry.connection.abort(assassinExecutor); bagEntry.connection.abort(assassinExecutor);
} }
catch (Throwable e) { catch (Throwable e) {
poolUtils.quietlyCloseConnection(bagEntry.connection, "connection aborted during shutdown"); poolUtils.quietlyCloseConnection(bagEntry.connection, "(connection aborted during shutdown)");
} }
finally { finally {
bagEntry.connection = null; bagEntry.connection = null;
@ -682,10 +682,10 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
for (PoolBagEntry bagEntry : connectionBag.values(STATE_NOT_IN_USE)) { for (PoolBagEntry bagEntry : connectionBag.values(STATE_NOT_IN_USE)) {
if (connectionBag.reserve(bagEntry)) { if (connectionBag.reserve(bagEntry)) {
if (bagEntry.evicted) { if (bagEntry.evicted) {
closeConnection(bagEntry, "connection evicted"); closeConnection(bagEntry, "(connection evicted)");
} }
else if (idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) { else if (idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) {
closeConnection(bagEntry, "connection passed idleTimeout"); closeConnection(bagEntry, "(connection passed idleTimeout)");
} }
else { else {
connectionBag.unreserve(bagEntry); connectionBag.unreserve(bagEntry);

@ -62,7 +62,7 @@ public final class PoolBagEntry implements IConcurrentBagEntry
{ {
// If we can reserve it, close it // If we can reserve it, close it
if (pool.connectionBag.reserve(PoolBagEntry.this)) { if (pool.connectionBag.reserve(PoolBagEntry.this)) {
pool.closeConnection(PoolBagEntry.this, "connection reached maxLifetime"); pool.closeConnection(PoolBagEntry.this, "(connection reached maxLifetime)");
} }
else { else {
// else the connection is "in-use" and we mark it for eviction by pool.releaseConnection() or the housekeeper // else the connection is "in-use" and we mark it for eviction by pool.releaseConnection() or the housekeeper

@ -55,13 +55,12 @@ public final class PoolUtilities
*/ */
public void quietlyCloseConnection(final Connection connection, final String closureReason) public void quietlyCloseConnection(final Connection connection, final String closureReason)
{ {
final String addendum = closureReason != null ? " (" + closureReason + ")" : "";
try { try {
if (connection == null || connection.isClosed()) { if (connection == null || connection.isClosed()) {
return; return;
} }
LOGGER.debug("Closing connection {} in pool {}{}", connection, poolName, addendum); LOGGER.debug("Closing connection {} in pool {} {}", connection, poolName, closureReason);
try { try {
setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15)); setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15));
} }
@ -71,7 +70,7 @@ public final class PoolUtilities
} }
} }
catch (Throwable e) { catch (Throwable e) {
LOGGER.debug("Exception closing connection {} in pool {}{}", connection, poolName, addendum, e); LOGGER.debug("Exception closing connection {} in pool {} {}", connection, poolName, closureReason, e);
} }
} }

@ -292,7 +292,7 @@ public class ShutdownTest
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
} }
finally { finally {
new PoolUtilities(config).quietlyCloseConnection(connection, "because this is a test"); new PoolUtilities(config).quietlyCloseConnection(connection, "(because this is a test)");
ds.close(); ds.close();
} }
}; };

Loading…
Cancel
Save