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.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.PoolUtilities;
public final class CodaHaleMetricsTracker extends MetricsTracker
{
@ -39,16 +40,16 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
/** {@inheritDoc} */
@Override
public Context recordConnectionRequest(long requestTime)
public Context recordConnectionRequest(final long requestTime)
{
return new Context(connectionObtainTimer);
}
/** {@inheritDoc} */
@Override
public void recordConnectionUsage(long usageMilleseconds)
public void recordConnectionUsage(final PoolBagEntry bagEntry)
{
connectionUsage.update(usageMilleseconds);
connectionUsage.update(PoolUtilities.elapsedTimeMs(bagEntry.lastOpenTime));
}
public Timer getConnectionAcquisitionTimer()

@ -38,9 +38,9 @@ public interface IMetricsTracker
* This method is called when a Connection is closed, with the total time in milliseconds
* 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.

@ -17,6 +17,7 @@
package com.zaxxer.hikari.metrics;
import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
/**
* This class only supports realtime, not historical metrics.
@ -43,7 +44,7 @@ public class MetricsTracker implements IMetricsTracker
/** {@inheritDoc} */
@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)
{
if (isRecordMetrics) {
metricsTracker.recordConnectionUsage(elapsedTimeMs(bagEntry.lastOpenTime));
}
metricsTracker.recordConnectionUsage(bagEntry);
if (isBroken || isShutdown) {
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.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
import com.zaxxer.hikari.util.PoolUtilities;
public final class CodaHaleMetricsTracker extends MetricsTracker
{
@ -39,16 +40,16 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
/** {@inheritDoc} */
@Override
public Context recordConnectionRequest(long requestTime)
public Context recordConnectionRequest(final long requestTime)
{
return new Context(connectionObtainTimer);
}
/** {@inheritDoc} */
@Override
public void recordConnectionUsage(long usageMilleseconds)
public void recordConnectionUsage(final PoolBagEntry bagEntry)
{
connectionUsage.update(usageMilleseconds);
connectionUsage.update(PoolUtilities.elapsedTimeMs(bagEntry.lastOpenTime));
}
public Timer getConnectionAcquisitionTimer()

@ -38,9 +38,9 @@ public interface IMetricsTracker
* This method is called when a Connection is closed, with the total time in milliseconds
* 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.

@ -17,6 +17,7 @@
package com.zaxxer.hikari.metrics;
import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.pool.PoolBagEntry;
/**
* This class only supports realtime, not historical metrics.
@ -43,7 +44,7 @@ public class MetricsTracker implements IMetricsTracker
/** {@inheritDoc} */
@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)
{
if (isRecordMetrics) {
metricsTracker.recordConnectionUsage(elapsedTimeMs(bagEntry.lastOpenTime));
}
metricsTracker.recordConnectionUsage(bagEntry);
if (isBroken || isShutdown) {
LOGGER.debug("Connection returned to pool {} is broken, or the pool has been shut down. Closing connection.", configuration.getPoolName());

Loading…
Cancel
Save