use of org.apache.geronimo.transaction.manager.TransactionImpl in project tomee by apache.
the class AutoConnectionTracker method handleReleased.
/**
* Removes the released collection from the garbage collection reference tracker, since this
* connection is being release via a normal close method.
*
* @param interceptor ignored
* @param connectionInfo the connection that was released
* @param action ignored
*/
@Override
@SuppressWarnings("unchecked")
public void handleReleased(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final ConnectionReturnAction action) {
TransactionImpl currentTx = null;
try {
currentTx = (TransactionImpl) txMgr.getTransaction();
} catch (SystemException | ClassCastException e) {
// ignore
}
if (currentTx != null) {
Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) currentTx.getResource(KEY);
if (txConnections == null) {
txConnections = new HashMap<>();
registry.putResource(KEY, txConnections);
}
Map<ConnectionInfo, Object> connectionObjects = txConnections.computeIfAbsent(connectionInfo.getManagedConnectionInfo(), k -> new HashMap<>());
connectionObjects.remove(connectionInfo);
if (connectionObjects.size() == 0) {
txConnections.remove(connectionInfo.getManagedConnectionInfo());
}
}
@SuppressWarnings("rawtypes") final PhantomReference phantomReference = references.remove(connectionInfo.getManagedConnectionInfo());
if (phantomReference != null) {
phantomReference.clear();
}
}
use of org.apache.geronimo.transaction.manager.TransactionImpl in project tomee by apache.
the class AutoConnectionTracker method handleObtained.
/**
* Proxies new connection handles so we can detect when they have been garbage collected.
*
* @param interceptor the interceptor used to release the managed connection when the handled is garbage collected.
* @param connectionInfo the connection that was obtained
* @param reassociate should always be false
*/
@SuppressWarnings("unchecked")
@Override
public void handleObtained(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final boolean reassociate) throws ResourceException {
if (txMgr != null && registry != null) {
try {
final TransactionImpl currentTx = (TransactionImpl) txMgr.getTransaction();
if (currentTx != null) {
Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY);
if (txConnections == null) {
txConnections = new HashMap<ManagedConnectionInfo, Map<ConnectionInfo, Object>>();
registry.putResource(KEY, txConnections);
}
Map<ConnectionInfo, Object> connectionObjects = txConnections.get(connectionInfo.getManagedConnectionInfo());
if (connectionObjects == null) {
connectionObjects = new HashMap<ConnectionInfo, Object>();
txConnections.put(connectionInfo.getManagedConnectionInfo(), connectionObjects);
}
connectionObjects.put(connectionInfo, connectionInfo.getConnectionProxy());
registry.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
}
@Override
public void afterCompletion(final int status) {
final Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) currentTx.getResource(KEY);
if (txConnections != null && txConnections.size() > 0) {
for (final ManagedConnectionInfo managedConnectionInfo : txConnections.keySet()) {
final StringBuilder sb = new StringBuilder();
final Collection<ConnectionInfo> connectionInfos = txConnections.get(managedConnectionInfo).keySet();
for (final ConnectionInfo connectionInfo : connectionInfos) {
sb.append("\n ").append("Connection handle opened at ").append(stackTraceToString(connectionInfo.getTrace().getStackTrace()));
}
logger.warning("Transaction complete, but connection still has handles associated: " + managedConnectionInfo + "\nAbandoned connection information: " + sb.toString());
}
}
}
});
}
} catch (SystemException | ClassCastException e) {
// ignore
}
}
if (!reassociate) {
proxyConnection(interceptor, connectionInfo);
}
}
Aggregations