|
|
|
@ -18,8 +18,6 @@ package com.zaxxer.hikari.pool;
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.sql.Statement;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
@ -37,16 +35,12 @@ import com.zaxxer.hikari.util.FastList;
|
|
|
|
|
*/
|
|
|
|
|
public final class PoolEntry implements IConcurrentBagEntry
|
|
|
|
|
{
|
|
|
|
|
private static final Logger LOGGER;
|
|
|
|
|
private static final SimpleDateFormat DATE_FORMAT;
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(PoolEntry.class);
|
|
|
|
|
|
|
|
|
|
public final long creationTime;
|
|
|
|
|
|
|
|
|
|
public Connection connection;
|
|
|
|
|
public long lastAccess;
|
|
|
|
|
|
|
|
|
|
public volatile long lastOpenTime;
|
|
|
|
|
public volatile boolean evict;
|
|
|
|
|
Connection connection;
|
|
|
|
|
long lastAccessed;
|
|
|
|
|
long lastBorrowed;
|
|
|
|
|
volatile boolean evict;
|
|
|
|
|
|
|
|
|
|
private final FastList<Statement> openStatements;
|
|
|
|
|
private final PoolBase poolBase;
|
|
|
|
@ -54,37 +48,30 @@ public final class PoolEntry implements IConcurrentBagEntry
|
|
|
|
|
|
|
|
|
|
private volatile ScheduledFuture<?> endOfLife;
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
{
|
|
|
|
|
LOGGER = LoggerFactory.getLogger(PoolEntry.class);
|
|
|
|
|
DATE_FORMAT = new SimpleDateFormat("MMM dd, HH:mm:ss.SSS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PoolEntry(final Connection connection, final PoolBase pool)
|
|
|
|
|
{
|
|
|
|
|
this.connection = connection;
|
|
|
|
|
this.poolBase = pool;
|
|
|
|
|
this.creationTime = System.currentTimeMillis();
|
|
|
|
|
this.state = new AtomicInteger(STATE_NOT_IN_USE);
|
|
|
|
|
this.lastAccess = ClockSource.INSTANCE.currentTime();
|
|
|
|
|
this.lastAccessed = ClockSource.INSTANCE.currentTime();
|
|
|
|
|
this.openStatements = new FastList<>(Statement.class, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Release this entry back to the pool.
|
|
|
|
|
*
|
|
|
|
|
* @param lastAccess last access time-stamp
|
|
|
|
|
* @param lastAccessed last access time-stamp
|
|
|
|
|
*/
|
|
|
|
|
public void recycle(final long lastAccess)
|
|
|
|
|
void recycle(final long lastAccessed)
|
|
|
|
|
{
|
|
|
|
|
this.lastAccess = lastAccess;
|
|
|
|
|
this.lastAccessed = lastAccessed;
|
|
|
|
|
poolBase.releaseConnection(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param endOfLife
|
|
|
|
|
*/
|
|
|
|
|
public void setFutureEol(final ScheduledFuture<?> endOfLife)
|
|
|
|
|
void setFutureEol(final ScheduledFuture<?> endOfLife)
|
|
|
|
|
{
|
|
|
|
|
this.endOfLife = endOfLife;
|
|
|
|
|
}
|
|
|
|
@ -94,41 +81,42 @@ public final class PoolEntry implements IConcurrentBagEntry
|
|
|
|
|
return ProxyFactory.getProxyConnection(this, connection, openStatements, leakTask, now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void resetConnectionState(final ProxyConnection proxyConnection, final int dirtyBits) throws SQLException
|
|
|
|
|
void resetConnectionState(final ProxyConnection proxyConnection, final int dirtyBits) throws SQLException
|
|
|
|
|
{
|
|
|
|
|
poolBase.resetConnectionState(connection, proxyConnection, dirtyBits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getPoolName()
|
|
|
|
|
String getPoolName()
|
|
|
|
|
{
|
|
|
|
|
return poolBase.getPoolName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Connection getConnection()
|
|
|
|
|
Connection getConnection()
|
|
|
|
|
{
|
|
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getLastAccess()
|
|
|
|
|
{
|
|
|
|
|
return lastAccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEvicted()
|
|
|
|
|
boolean isEvicted()
|
|
|
|
|
{
|
|
|
|
|
return evict;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void evict()
|
|
|
|
|
void evict()
|
|
|
|
|
{
|
|
|
|
|
this.evict = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FastList<Statement> getStatementsList()
|
|
|
|
|
FastList<Statement> getStatementsList()
|
|
|
|
|
{
|
|
|
|
|
return openStatements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns millis since lastBorrowed */
|
|
|
|
|
public long getElapsedLastBorrowed()
|
|
|
|
|
{
|
|
|
|
|
return ClockSource.INSTANCE.elapsedMillis(lastBorrowed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// IConcurrentBagEntry methods
|
|
|
|
|
// ***********************************************************************
|
|
|
|
@ -158,9 +146,10 @@ public final class PoolEntry implements IConcurrentBagEntry
|
|
|
|
|
@Override
|
|
|
|
|
public String toString()
|
|
|
|
|
{
|
|
|
|
|
final long now = ClockSource.INSTANCE.currentTime();
|
|
|
|
|
return connection
|
|
|
|
|
+ ", created " + formatDateTime(creationTime)
|
|
|
|
|
+ ", last release " + ClockSource.INSTANCE.elapsedMillis(lastAccess) + "ms ago, "
|
|
|
|
|
+ ", borrowed " + ClockSource.INSTANCE.elapsedMillis(lastBorrowed, now) + "ms ago, "
|
|
|
|
|
+ ", accessed " + ClockSource.INSTANCE.elapsedMillis(lastAccessed, now) + "ms ago, "
|
|
|
|
|
+ stateToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -174,11 +163,6 @@ public final class PoolEntry implements IConcurrentBagEntry
|
|
|
|
|
connection = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static synchronized String formatDateTime(final long timestamp)
|
|
|
|
|
{
|
|
|
|
|
return DATE_FORMAT.format(new Date(timestamp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String stateToString()
|
|
|
|
|
{
|
|
|
|
|
switch (state.get()) {
|
|
|
|
|