use of javax.sql.ConnectionEventListener in project tomcat by apache.
the class PooledConnectionImpl method notifyListeners.
/**
* sends a connectionClosed event.
*/
void notifyListeners() {
final ConnectionEvent event = new ConnectionEvent(this);
final Object[] listeners = eventListeners.toArray();
for (final Object listener : listeners) {
((ConnectionEventListener) listener).connectionClosed(event);
}
}
use of javax.sql.ConnectionEventListener in project voltdb by VoltDB.
the class LifeTimeConnectionWrapper method fireCloseEvent.
protected void fireCloseEvent() {
ConnectionEvent connectionEvent = new ConnectionEvent(this.pooledConnection);
for (Iterator iterator = connectionListeners.iterator(); iterator.hasNext(); ) {
ConnectionEventListener connectionListener = (ConnectionEventListener) iterator.next();
connectionListener.connectionClosed(connectionEvent);
}
}
use of javax.sql.ConnectionEventListener in project druid by alibaba.
the class DruidDataSource method handleConnectionException.
public void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t) throws SQLException {
final DruidConnectionHolder holder = pooledConnection.getConnectionHolder();
errorCount.incrementAndGet();
lastError = t;
lastErrorTimeMillis = System.currentTimeMillis();
if (t instanceof SQLException) {
SQLException sqlEx = (SQLException) t;
// broadcastConnectionError
ConnectionEvent event = new ConnectionEvent(pooledConnection, sqlEx);
for (ConnectionEventListener eventListener : holder.getConnectionEventListeners()) {
eventListener.connectionErrorOccurred(event);
}
// exceptionSorter.isExceptionFatal
if (exceptionSorter != null && exceptionSorter.isExceptionFatal(sqlEx)) {
if (pooledConnection.isTraceEnable()) {
activeConnectionLock.lock();
try {
if (pooledConnection.isTraceEnable()) {
activeConnections.remove(pooledConnection);
pooledConnection.setTraceEnable(false);
}
} finally {
activeConnectionLock.unlock();
}
}
boolean requireDiscard = false;
final ReentrantLock lock = pooledConnection.lock;
lock.lock();
try {
if ((!pooledConnection.isClosed()) || !pooledConnection.isDisable()) {
holder.setDiscard(true);
pooledConnection.disable(t);
requireDiscard = true;
}
} finally {
lock.unlock();
}
if (requireDiscard) {
this.discardConnection(holder.getConnection());
holder.setDiscard(true);
}
LOG.error("discard connection", sqlEx);
}
throw sqlEx;
} else {
throw new SQLException("Error", t);
}
}
use of javax.sql.ConnectionEventListener in project druid by alibaba.
the class DruidPooledConnection method syncClose.
public void syncClose() throws SQLException {
lock.lock();
try {
if (this.disable) {
return;
}
DruidConnectionHolder holder = this.holder;
if (holder == null) {
if (dupCloseLogEnable) {
LOG.error("dup close");
}
return;
}
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
listener.connectionClosed(new ConnectionEvent(this));
}
DruidAbstractDataSource dataSource = holder.getDataSource();
List<Filter> filters = dataSource.getProxyFilters();
if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(dataSource);
filterChain.dataSource_recycle(this);
} else {
recycle();
}
this.disable = true;
} finally {
lock.unlock();
}
}
use of javax.sql.ConnectionEventListener in project druid by alibaba.
the class DruidPooledConnection method close.
@Override
public void close() throws SQLException {
if (this.disable) {
return;
}
DruidConnectionHolder holder = this.holder;
if (holder == null) {
if (dupCloseLogEnable) {
LOG.error("dup close");
}
return;
}
DruidAbstractDataSource dataSource = holder.getDataSource();
boolean isSameThread = this.getOwnerThread() == Thread.currentThread();
if (!isSameThread) {
dataSource.setAsyncCloseConnectionEnable(true);
}
if (dataSource.isAsyncCloseConnectionEnable()) {
syncClose();
return;
}
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
listener.connectionClosed(new ConnectionEvent(this));
}
List<Filter> filters = dataSource.getProxyFilters();
if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(dataSource);
filterChain.dataSource_recycle(this);
} else {
recycle();
}
this.disable = true;
}
Aggregations