mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
StatFilter refactor
This commit is contained in:
@@ -227,17 +227,19 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException {
|
||||
long nowNano = System.nanoTime();
|
||||
if (connection.getCloseCount() == 0) {
|
||||
long nowNano = System.nanoTime();
|
||||
|
||||
dataSourceStat.getConnectionStat().incrementConnectionCloseCount();
|
||||
dataSourceStat.getConnectionStat().incrementConnectionCloseCount();
|
||||
|
||||
JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection);
|
||||
JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection);
|
||||
|
||||
long aliveNanoSpan = nowNano - connectionInfo.getEstablishNano();
|
||||
long aliveNanoSpan = nowNano - connectionInfo.getEstablishNano();
|
||||
|
||||
JdbcConnectionStat.Entry existsConnection = dataSourceStat.getConnections().remove(connection.getId());
|
||||
if (existsConnection != null) {
|
||||
dataSourceStat.getConnectionStat().afterClose(aliveNanoSpan);
|
||||
JdbcConnectionStat.Entry existsConnection = dataSourceStat.getConnections().remove(connection.getId());
|
||||
if (existsConnection != null) {
|
||||
dataSourceStat.getConnectionStat().afterClose(aliveNanoSpan);
|
||||
}
|
||||
}
|
||||
|
||||
chain.connection_close(connection);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
|
||||
private Date connectedTime = null;
|
||||
|
||||
private boolean closed = false;
|
||||
private int closeCount = 0;
|
||||
|
||||
private TransactionInfo transcationInfo;
|
||||
|
||||
@@ -167,21 +167,22 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
if (closed) {
|
||||
if (closeCount > 0) {
|
||||
closeCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
this.closed = true;
|
||||
this.closeCount++;
|
||||
|
||||
multiDataSource.afterConnectionClosed(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
return closed;
|
||||
return closeCount > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -663,4 +664,9 @@ public class MultiDataSourceConnection extends WrapperAdapter implements Connect
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCloseCount() {
|
||||
return closeCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,4 +33,6 @@ public interface ConnectionProxy extends Connection, WrapperProxy {
|
||||
Date getConnectedTime();
|
||||
|
||||
TransactionInfo getTransactionInfo();
|
||||
|
||||
int getCloseCount();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
|
||||
private TransactionInfo transcationInfo;
|
||||
|
||||
private int closeCount;
|
||||
|
||||
public ConnectionProxyImpl(DataSourceProxy dataSource, Connection connection, Properties properties, long id){
|
||||
super(connection, id);
|
||||
this.dataSource = dataSource;
|
||||
@@ -95,12 +97,13 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
createChain().connection_close(this);
|
||||
closeCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
createChain().connection_commit(this);
|
||||
|
||||
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
@@ -275,7 +278,7 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
createChain().connection_rollback(this);
|
||||
|
||||
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
@@ -284,7 +287,7 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
createChain().connection_rollback(this, savepoint);
|
||||
|
||||
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
@@ -383,4 +386,9 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
public TransactionInfo getTransactionInfo() {
|
||||
return transcationInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCloseCount() {
|
||||
return closeCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user