}
protected void internalGetConnection(ConnectionInfo connectionInfo) throws ResourceException {
synchronized (pool) {
if (destroyed) {
throw new ResourceException("ManagedConnection pool has been destroyed");
}
ManagedConnectionInfo newMCI = null;
if (pool.isEmpty()) {
next.getConnection(connectionInfo);
connectionCount++;
if (log.isTraceEnabled()) {
log.trace("Returning new connection " + connectionInfo.getManagedConnectionInfo());
}
return;
} else {
newMCI = pool.removeLast();
}
if (connectionCount < minSize) {
timer.schedule(new FillTask(connectionInfo), 10);
}
if (selectOneAssumeMatch) {
connectionInfo.setManagedConnectionInfo(newMCI);
if (log.isTraceEnabled()) {
log.trace("Returning pooled connection without checking matching " + connectionInfo.getManagedConnectionInfo());
}
return;
}
try {
ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
ManagedConnection matchedMC =
newMCI
.getManagedConnectionFactory()
.matchManagedConnections(Collections.singleton(newMCI.getManagedConnection()),
mci.getSubject(),
mci.getConnectionRequestInfo());
if (matchedMC != null) {
connectionInfo.setManagedConnectionInfo(newMCI);
if (log.isTraceEnabled()) {
log.trace("Returning pooled connection " + connectionInfo.getManagedConnectionInfo());
}
return;
} else {
//matching failed.
ConnectionInfo returnCI = new ConnectionInfo();
returnCI.setManagedConnectionInfo(newMCI);
returnConnection(returnCI,
ConnectionReturnAction.RETURN_HANDLE);
throw new ResourceException("The pooling strategy does not match the MatchManagedConnections implementation. Please investigate and reconfigure this pool");
}
} catch (ResourceException e) {
//something is wrong: destroy connection, rethrow, release permit
ConnectionInfo returnCI = new ConnectionInfo();
returnCI.setManagedConnectionInfo(newMCI);