1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import javax.resource.ResourceException ; 24 import javax.resource.spi.DissociatableManagedConnection ; 25 import javax.resource.spi.ManagedConnection ; 26 27 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker; 28 29 39 public class ConnectionTrackingInterceptor implements ConnectionInterceptor { 40 41 private final ConnectionInterceptor next; 42 private final String key; 43 private final ConnectionTracker connectionTracker; 44 45 public ConnectionTrackingInterceptor( 46 final ConnectionInterceptor next, 47 final String key, 48 final ConnectionTracker connectionTracker 49 ) { 50 this.next = next; 51 this.key = key; 52 this.connectionTracker = connectionTracker; 53 } 54 55 64 public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { 65 connectionTracker.setEnvironment(connectionInfo, key); 66 next.getConnection(connectionInfo); 67 connectionTracker.handleObtained(this, connectionInfo); 68 } 69 70 78 public void returnConnection( 79 ConnectionInfo connectionInfo, 80 ConnectionReturnAction connectionReturnAction) { 81 connectionTracker.handleReleased(this, connectionInfo); 82 next.returnConnection(connectionInfo, connectionReturnAction); 83 } 84 85 public void destroy() { 86 next.destroy(); 87 } 88 89 public void enter(Collection connectionInfos) 90 throws ResourceException { 91 for (Iterator i = connectionInfos.iterator(); i.hasNext();) { 92 ConnectionInfo connectionInfo = (ConnectionInfo) i.next(); 93 next.getConnection(connectionInfo); 94 } 95 96 } 97 98 public void exit(Collection connectionInfos) 99 throws ResourceException { 100 for (Iterator i = connectionInfos.iterator(); i.hasNext();) { 101 ConnectionInfo connectionInfo = (ConnectionInfo) i.next(); 102 if (connectionInfo.isUnshareable()) { 103 return; 105 } 106 ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo(); 107 ManagedConnection managedConnection = managedConnectionInfo.getManagedConnection(); 108 if (managedConnection instanceof DissociatableManagedConnection 109 && managedConnectionInfo.isFirstConnectionInfo(connectionInfo)) { 110 int size = connectionInfos.size(); 111 i.remove(); 112 assert size - 1 == connectionInfos.size(); 113 ((DissociatableManagedConnection ) managedConnection).dissociateConnections(); 114 managedConnectionInfo.clearConnectionHandles(); 115 returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); 118 } 119 } 120 } 121 } 122 | Popular Tags |