Minor code cleanup.

pull/192/head
Brett Wooldridge 10 years ago
parent 7297633894
commit 7f9734e025

@ -21,6 +21,7 @@ import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer; import com.codahale.metrics.Timer;
import com.zaxxer.hikari.pool.HikariPool; import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry; import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.PoolUtilities;
public final class CodaHaleMetricsTracker extends MetricsTracker public final class CodaHaleMetricsTracker extends MetricsTracker
{ {
@ -39,18 +40,18 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public Context recordConnectionRequest(long requestTime) public Context recordConnectionRequest(final long requestTime)
{ {
return new Context(connectionObtainTimer); return new Context(connectionObtainTimer);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void recordConnectionUsage(long usageMilleseconds) public void recordConnectionUsage(final PoolBagEntry bagEntry)
{ {
connectionUsage.update(usageMilleseconds); connectionUsage.update(PoolUtilities.elapsedTimeMs(bagEntry.lastOpenTime));
} }
public Timer getConnectionAcquisitionTimer() public Timer getConnectionAcquisitionTimer()
{ {
return connectionObtainTimer; return connectionObtainTimer;

@ -38,9 +38,9 @@ public interface IMetricsTracker
* This method is called when a Connection is closed, with the total time in milliseconds * This method is called when a Connection is closed, with the total time in milliseconds
* that the Connection was out of the pool. * that the Connection was out of the pool.
* *
* @param usageMilleseconds the Connection usage time in milliseconds * @param bagEntry the entry to calculate usage for
*/ */
void recordConnectionUsage(long usageMilleseconds); void recordConnectionUsage(PoolBagEntry bagEntry);
/** /**
* Get the current number of idle connections. * Get the current number of idle connections.

@ -17,6 +17,7 @@
package com.zaxxer.hikari.metrics; package com.zaxxer.hikari.metrics;
import com.zaxxer.hikari.pool.HikariPool; import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
/** /**
* This class only supports realtime, not historical metrics. * This class only supports realtime, not historical metrics.
@ -43,7 +44,7 @@ public class MetricsTracker implements IMetricsTracker
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void recordConnectionUsage(long usageMilleseconds) public void recordConnectionUsage(final PoolBagEntry bagEntry)
{ {
} }

@ -216,9 +216,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
*/ */
public void releaseConnection(final PoolBagEntry bagEntry, final boolean isBroken) public void releaseConnection(final PoolBagEntry bagEntry, final boolean isBroken)
{ {
if (isRecordMetrics) { metricsTracker.recordConnectionUsage(bagEntry);
metricsTracker.recordConnectionUsage(elapsedTimeMs(bagEntry.lastOpenTime));
}
if (isBroken || isShutdown) { if (isBroken || isShutdown) {
LOGGER.debug("Connection returned to pool {} is broken, or the pool has been shut down. Closing connection.", configuration.getPoolName()); LOGGER.debug("Connection returned to pool {} is broken, or the pool has been shut down. Closing connection.", configuration.getPoolName());

@ -21,6 +21,7 @@ import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer; import com.codahale.metrics.Timer;
import com.zaxxer.hikari.pool.HikariPool; import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry; import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.PoolUtilities;
public final class CodaHaleMetricsTracker extends MetricsTracker public final class CodaHaleMetricsTracker extends MetricsTracker
{ {
@ -39,18 +40,18 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public Context recordConnectionRequest(long requestTime) public Context recordConnectionRequest(final long requestTime)
{ {
return new Context(connectionObtainTimer); return new Context(connectionObtainTimer);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void recordConnectionUsage(long usageMilleseconds) public void recordConnectionUsage(final PoolBagEntry bagEntry)
{ {
connectionUsage.update(usageMilleseconds); connectionUsage.update(PoolUtilities.elapsedTimeMs(bagEntry.lastOpenTime));
} }
public Timer getConnectionAcquisitionTimer() public Timer getConnectionAcquisitionTimer()
{ {
return connectionObtainTimer; return connectionObtainTimer;

@ -38,9 +38,9 @@ public interface IMetricsTracker
* This method is called when a Connection is closed, with the total time in milliseconds * This method is called when a Connection is closed, with the total time in milliseconds
* that the Connection was out of the pool. * that the Connection was out of the pool.
* *
* @param usageMilleseconds the Connection usage time in milliseconds * @param bagEntry the entry to calculate usage for
*/ */
void recordConnectionUsage(long usageMilleseconds); void recordConnectionUsage(PoolBagEntry bagEntry);
/** /**
* Get the current number of idle connections. * Get the current number of idle connections.

@ -17,6 +17,7 @@
package com.zaxxer.hikari.metrics; package com.zaxxer.hikari.metrics;
import com.zaxxer.hikari.pool.HikariPool; import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
/** /**
* This class only supports realtime, not historical metrics. * This class only supports realtime, not historical metrics.
@ -43,7 +44,7 @@ public class MetricsTracker implements IMetricsTracker
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void recordConnectionUsage(long usageMilleseconds) public void recordConnectionUsage(final PoolBagEntry bagEntry)
{ {
} }

@ -213,9 +213,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
*/ */
public void releaseConnection(final PoolBagEntry bagEntry, final boolean isBroken) public void releaseConnection(final PoolBagEntry bagEntry, final boolean isBroken)
{ {
if (isRecordMetrics) { metricsTracker.recordConnectionUsage(bagEntry);
metricsTracker.recordConnectionUsage(elapsedTimeMs(bagEntry.lastOpenTime));
}
if (isBroken || isShutdown) { if (isBroken || isShutdown) {
LOGGER.debug("Connection returned to pool {} is broken, or the pool has been shut down. Closing connection.", configuration.getPoolName()); LOGGER.debug("Connection returned to pool {} is broken, or the pool has been shut down. Closing connection.", configuration.getPoolName());

Loading…
Cancel
Save