use of javax.sql.PooledConnection in project voltdb by VoltDB.
the class ManagedPoolDataSource method connectionErrorOccurred.
/**
*
* A fatal error has occurred and the connection cannot be used anymore.
* A close event from such a connection should be ignored. The connection should not be reused.
* A new connection will be created to replace the invalid connection, when the next client
* calls getConnection().
*/
public synchronized void connectionErrorOccurred(ConnectionEvent event) {
PooledConnection connection = (PooledConnection) event.getSource();
connection.removeConnectionEventListener(this);
this.connectionsInUse.remove(connection);
this.sessionConnectionWrappers.remove(connection);
logInfo("Fatal exception occurred on pooled connection. Connection is removed from pool: ");
logInfo(event.getSQLException());
closePhysically(connection, "closing invalid, removed connection.");
//notify threads waiting for connections or for the pool to close.
//one waiting thread can now create a new connection since the pool has space for a new connection.
//if a thread waits for the pool to close this could be the last unclosed connection in the pool.
this.notifyAll();
}
use of javax.sql.PooledConnection in project voltdb by VoltDB.
the class ManagedPoolDataSource method createNewConnection.
private PooledConnection createNewConnection() throws SQLException {
PooledConnection pooledConnection;
// I have changed "size() + 1" to "size()". I don't know why
// we would want to report 1 more than the actual pool size,
// so I am assuming that this is a coding error. (The size
// method does return the actual size of an array). -blaine
logInfo("Connection created since no connections available and " + "pool has space for more connections. Pool size: " + size());
pooledConnection = this.connectionPoolDataSource.getPooledConnection();
pooledConnection.addConnectionEventListener(this);
return pooledConnection;
}
use of javax.sql.PooledConnection in project voltdb by VoltDB.
the class ManagedPoolDataSource method connectionClosed.
public synchronized void connectionClosed(ConnectionEvent event) {
PooledConnection connection = (PooledConnection) event.getSource();
this.connectionsInUse.remove(connection);
this.sessionConnectionWrappers.remove(connection);
if (!this.isPoolClosed) {
enqueue(connection);
logInfo("Connection returned to pool.");
} else {
closePhysically(connection, "closing returned connection.");
logInfo("Connection returned to pool was closed because pool is closed.");
//notifies evt. threads waiting for connection or for the pool to close.
this.notifyAll();
}
}
use of javax.sql.PooledConnection in project voltdb by VoltDB.
the class ManagedPoolDataSource method reclaimAbandonedConnections.
private void reclaimAbandonedConnections() {
long now = System.currentTimeMillis();
long sessionTimeoutMillis = ((long) sessionTimeout) * 1000L;
Iterator iterator = this.connectionsInUse.iterator();
List abandonedConnections = new ArrayList();
while (iterator.hasNext()) {
PooledConnection connectionInUse = (PooledConnection) iterator.next();
SessionConnectionWrapper sessionWrapper = (SessionConnectionWrapper) this.sessionConnectionWrappers.get(connectionInUse);
if (isSessionTimedOut(now, sessionWrapper, sessionTimeoutMillis)) {
abandonedConnections.add(sessionWrapper);
}
}
//The timed out sessions are added to a list before being closed to avoid
//ConcurrentModificationException. When the session wrapper is closed the underlying
// connection will eventually call connectionClosed() on this class. connectionClosed()
// will in turn try to remove the pooled connection from the connectionsInUse set. So,
// if the sessionWrapper is closed while iterating the connectionsInUse it would result
// in a ConcurrentModificationException.
iterator = abandonedConnections.iterator();
while (iterator.hasNext()) {
SessionConnectionWrapper sessionWrapper = (SessionConnectionWrapper) iterator.next();
closeSessionWrapper(sessionWrapper, "Error closing abandoned session connection wrapper.");
}
//now have a chance to get a connections. therefore we notify all waiting threads.
if (abandonedConnections.size() > 1) {
abandonedConnections.clear();
this.notifyAll();
}
}
use of javax.sql.PooledConnection in project geode by apache.
the class GemFireConnPooledDataSource method getSQLConnection.
/**
* gets tha connection from the pool
*
* @param poolC
* @return ???
*/
protected Connection getSQLConnection(PooledConnection poolC) throws SQLException {
Connection conn = poolC.getConnection();
boolean val = validateConnection(conn);
if (val)
return conn;
else {
provider.returnAndExpireConnection(poolC);
throw new SQLException(LocalizedStrings.GemFireConnPooledDataSource_GEMFIRECONNPOOLEDDATASOURCEGETCONNFROMCONNPOOLJAVASQLCONNECTION_OBTAINED_IS_INVALID.toLocalizedString());
}
}
Aggregations