You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2003/12/09 05:16:26 UTC
cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound ConnectionHandleInterceptor.java ConnectionInterceptor.java ConnectionManagerDeployment.java ConnectionManagerDeployment.xml GeronimoConnectionEventListener.java LocalXAResource.java LocalXAResourceInsertionInterceptor.java MCFConnectionInterceptor.java ManagedConnectionInfo.java MultiPoolConnectionInterceptor.java SinglePoolConnectionInterceptor.java SubjectInterceptor.java TransactionCachingInterceptor.java TransactionEnlistingInterceptor.java XAResourceInsertionInterceptor.java
djencks 2003/12/08 20:16:26
Modified: modules/core/src/java/org/apache/geronimo/connector/outbound
ConnectionHandleInterceptor.java
ConnectionInterceptor.java
ConnectionManagerDeployment.java
ConnectionManagerDeployment.xml
GeronimoConnectionEventListener.java
LocalXAResource.java
LocalXAResourceInsertionInterceptor.java
MCFConnectionInterceptor.java
ManagedConnectionInfo.java
MultiPoolConnectionInterceptor.java
SinglePoolConnectionInterceptor.java
SubjectInterceptor.java
TransactionCachingInterceptor.java
TransactionEnlistingInterceptor.java
XAResourceInsertionInterceptor.java
Log:
Modified interceptors for connector framework refactoring
Revision Changes Path
1.3 +15 -17 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionHandleInterceptor.java
Index: ConnectionHandleInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionHandleInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConnectionHandleInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ ConnectionHandleInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -62,9 +62,7 @@
* ConnectionHandleInterceptor.java
*
*
- * Created: Thu Sep 25 14:48:32 2003
- *
- * @version 1.0
+ * @version $Revision$ $Date$
*/
public class ConnectionHandleInterceptor implements ConnectionInterceptor {
@@ -74,30 +72,30 @@
this.next = next;
}
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- next.getConnection(ci);
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
- if (ci.getConnectionHandle() == null) {
- ci.setConnectionHandle(
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ next.getConnection(connectionInfo);
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
+ if (connectionInfo.getConnectionHandle() == null) {
+ connectionInfo.setConnectionHandle(
mci.getManagedConnection().getConnection(
mci.getSubject(),
mci.getConnectionRequestInfo()));
} else {
mci.getManagedConnection().associateConnection(
- ci.getConnectionHandle());
- } // end of else
- mci.addConnectionHandle(ci.getConnectionHandle());
+ connectionInfo.getConnectionHandle());
+ }
+ mci.addConnectionHandle(connectionInfo.getConnectionHandle());
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
- if (ci.getConnectionHandle() != null) {
- ci.getManagedConnectionInfo().removeConnectionHandle(
- ci.getConnectionHandle());
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
+ if (connectionInfo.getConnectionHandle() != null) {
+ connectionInfo.getManagedConnectionInfo().removeConnectionHandle(
+ connectionInfo.getConnectionHandle());
}
- next.returnConnection(ci, cra);
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
}
1.3 +3 -5 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionInterceptor.java
Index: ConnectionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConnectionInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ ConnectionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -65,14 +65,12 @@
* or releasing a ManagedConnection.
*
*
- * Created: Tue Sep 23 21:57:08 2003
- *
- * @version 1.0
+ * @version $Revision$ $Date$
*/
public interface ConnectionInterceptor {
- void getConnection(ConnectionInfo ci) throws ResourceException;
+ void getConnection(ConnectionInfo connectionInfo) throws ResourceException;
- void returnConnection(ConnectionInfo ci, ConnectionReturnAction cra);
+ void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction);
} // ConnectionInterceptor
1.3 +13 -12 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java
Index: ConnectionManagerDeployment.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConnectionManagerDeployment.java 13 Nov 2003 22:22:30 -0000 1.2
+++ ConnectionManagerDeployment.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -62,6 +62,7 @@
import javax.transaction.TransactionManager;
import org.apache.geronimo.connector.deployment.ConnectionManagerFactory;
+import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
import org.apache.geronimo.kernel.service.AbstractManagedObject;
import org.apache.geronimo.kernel.service.GeronimoMBeanTarget;
import org.apache.geronimo.kernel.service.GeronimoMBeanContext;
@@ -121,7 +122,7 @@
/**
* Actual CachedConnectionManager we relate to.
*/
- private CachedConnectionManager cachedConnectionManager;
+ private ConnectionTracker connectionTracker;
public void setMBeanContext(GeronimoMBeanContext context) {
this.context = context;
@@ -177,16 +178,16 @@
stack =
new TransactionCachingInterceptor(
stack,
- transactionManager);
+ connectionTracker);
}
}
stack = new ConnectionHandleInterceptor(stack);
- if (cachedConnectionManager != null) {
+ if (connectionTracker != null) {
stack =
- new MetaCallConnectionInterceptor(
+ new ConnectionTrackingInterceptor(
stack,
jndiName,
- cachedConnectionManager,
+ connectionTracker,
securityDomain);
}
@@ -211,7 +212,7 @@
cm = null;
securityDomain = null;
transactionManager = null;
- cachedConnectionManager = null;
+ connectionTracker = null;
}
@@ -255,16 +256,16 @@
* @return
* @jmx.managed-attribute
*/
- public CachedConnectionManager getCachedConnectionManager() {
- return cachedConnectionManager;
+ public ConnectionTracker getConnectionTracker() {
+ return connectionTracker;
}
/**
- * @param cachedConnectionManager
+ * @param connectionTracker
* @jmx.managed-attribute
*/
- public void setCachedConnectionManager(CachedConnectionManager cachedConnectionManager) {
- this.cachedConnectionManager = cachedConnectionManager;
+ public void setConnectionTracker(ConnectionTracker connectionTracker) {
+ this.connectionTracker = connectionTracker;
}
/**
1.2 +2 -2 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.xml
Index: ConnectionManagerDeployment.xml
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectionManagerDeployment.xml 11 Nov 2003 21:11:56 -0000 1.1
+++ ConnectionManagerDeployment.xml 9 Dec 2003 04:16:25 -0000 1.2
@@ -23,7 +23,7 @@
<endpoint name="SecurityDomain" type="org.apache.geronimo.connector.outbound.SecurityDomain" required="false" >
<peer pattern="geronimo.connector:role=SecurityDomain"/>
</endpoint>
- <endpoint name="CachedConnectionManager" type="org.apache.geronimo.connector.outbound.CachedConnectionManager">
- <peer pattern="geronimo.connector:role=CachedConnectionManager"/>
+ <endpoint name="ConnectionTracker" type="org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker">
+ <peer pattern="geronimo.connector:role=ConnectionTrackingCoordinator"/>
</endpoint>
</mbean>
1.4 +6 -20 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java
Index: GeronimoConnectionEventListener.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GeronimoConnectionEventListener.java 19 Nov 2003 09:45:57 -0000 1.3
+++ GeronimoConnectionEventListener.java 9 Dec 2003 04:16:25 -0000 1.4
@@ -61,6 +61,7 @@
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
+import javax.transaction.Synchronization;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
@@ -87,13 +88,8 @@
final ManagedConnectionInfo mci) {
this.stack = stack;
this.mci = mci;
- } // ConnectionEventListener constructor
+ }
- /**
- * The <code>connectionClosed</code> method
- *
- * @param connectionEvent a <code>ConnectionEvent</code> value
- */
public void connectionClosed(ConnectionEvent connectionEvent) {
if (connectionEvent.getSource() != mci.getManagedConnection()) {
throw new IllegalArgumentException(
@@ -101,7 +97,7 @@
+ mci.getManagedConnection()
+ ", actual "
+ connectionEvent.getSource());
- } // end of if ()
+ }
if (log.isTraceEnabled()) {
log.trace("connectionClosed called with " + connectionEvent.getConnectionHandle());
}
@@ -110,11 +106,6 @@
stack.returnConnection(ci, ConnectionReturnAction.RETURN_HANDLE);
}
- /**
- * The <code>connectionErrorOccurred</code> method
- *
- * @param connectionEvent a <code>ConnectionEvent</code> value
- */
public void connectionErrorOccurred(ConnectionEvent connectionEvent) {
if (connectionEvent.getSource() != mci.getManagedConnection()) {
throw new IllegalArgumentException(
@@ -122,20 +113,15 @@
+ mci.getManagedConnection()
+ ", actual "
+ connectionEvent.getSource());
- } // end of if ()
+ }
log.info("connectionErrorOccurred called with " + connectionEvent.getConnectionHandle(),connectionEvent.getException());
ConnectionInfo ci = new ConnectionInfo(mci);
ci.setConnectionHandle(connectionEvent.getConnectionHandle());
stack.returnConnection(ci, ConnectionReturnAction.DESTROY);
}
- /**
- * The <code>localTransactionStarted</code> method
- *
- * @param event a <code>ConnectionEvent</code> value
- * @todo implement this method
- */
public void localTransactionStarted(ConnectionEvent event) {
+ //TODO implement this method
}
/**
@@ -172,4 +158,4 @@
connectionHandles.clear();
}
-} // ConnectionEventListener
+}
1.4 +11 -12 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/LocalXAResource.java
Index: LocalXAResource.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/LocalXAResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalXAResource.java 18 Nov 2003 02:15:59 -0000 1.3
+++ LocalXAResource.java 9 Dec 2003 04:16:25 -0000 1.4
@@ -68,18 +68,17 @@
* semantics.
*
*
- * Created: Tue Sep 30 00:32:44 2003
- *
- * @version 1.0
+ * @version $Revision$ $Date$
*/
public class LocalXAResource implements XAResource {
- private final LocalTransaction localTx;
+ //accessible in package for testing
+ final LocalTransaction localTransaction;
private Xid xid;
- private int txTimeout;
+ private int transactionTimeout;
- public LocalXAResource(LocalTransaction localTx) {
- this.localTx = localTx;
+ public LocalXAResource(LocalTransaction localTransaction) {
+ this.localTransaction = localTransaction;
}
// Implementation of javax.transaction.xa.XAResource
@@ -89,7 +88,7 @@
throw new XAException();
}
try {
- localTx.commit();
+ localTransaction.commit();
} catch (ResourceException e) {
XAException xae = new XAException();
//xae.setLinkedException(e);
@@ -105,7 +104,7 @@
}
public int getTransactionTimeout() throws XAException {
- return txTimeout;
+ return transactionTimeout;
}
public boolean isSameRM(XAResource xares) throws XAException {
@@ -121,7 +120,7 @@
throw new XAException();
}
try {
- localTx.rollback();
+ localTransaction.rollback();
} catch (ResourceException e) {
XAException xae = new XAException();
//xae.setLinkedException(e);
@@ -133,7 +132,7 @@
}
public boolean setTransactionTimeout(int txTimeout) throws XAException {
- this.txTimeout = txTimeout;
+ this.transactionTimeout = txTimeout;
return true;
}
@@ -145,7 +144,7 @@
}
this.xid = xid;
try {
- localTx.begin();
+ localTransaction.begin();
} catch (ResourceException e) {
throw (XAException) new XAException("could not start local tx").initCause(e);
}
1.3 +8 -9 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptor.java
Index: LocalXAResourceInsertionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LocalXAResourceInsertionInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ LocalXAResourceInsertionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -62,9 +62,8 @@
* LocalXAResourceInsertionInterceptor.java
*
*
- * Created: Tue Sep 30 00:50:34 2003
- *
- * @version 1.0
+ * @version $Revision$ $Date$
+
*/
public class LocalXAResourceInsertionInterceptor
implements ConnectionInterceptor {
@@ -75,18 +74,18 @@
this.next = next;
} // XAResourceInsertionInterceptor constructor
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- next.getConnection(ci);
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ next.getConnection(connectionInfo);
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
mci.setXAResource(
new LocalXAResource(
mci.getManagedConnection().getLocalTransaction()));
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
- next.returnConnection(ci, cra);
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
} // XAResourceInsertionInterceptor
1.3 +13 -12 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java
Index: MCFConnectionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MCFConnectionInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ MCFConnectionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -63,10 +63,7 @@
* MCFConnectionInterceptor.java
*
*
- * Created: Thu Sep 25 14:36:26 2003
- *
- * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
- * @version 1.0
+ * @version $Revision$ $Date$
*/
public class MCFConnectionInterceptor implements ConnectionInterceptor {
@@ -74,10 +71,10 @@
public MCFConnectionInterceptor(ConnectionManagerDeployment head) {
this.head = head;
- } // MCFConnectionInterceptor constructor
+ }
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
ManagedConnection mc =
mci.getManagedConnectionFactory().createManagedConnection(
mci.getSubject(),
@@ -88,15 +85,19 @@
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
ManagedConnection mc = mci.getManagedConnection();
try {
mc.destroy();
} catch (ResourceException e) {
//log and forget
- } // end of try-catch
+ } catch (Error e) {
+ throw e;
+ } catch (Throwable t) {
+ //log and forget
+ }
}
-} // MCFConnectionInterceptor
+}
1.3 +1 -2 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java
Index: ManagedConnectionInfo.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ManagedConnectionInfo.java 14 Nov 2003 16:00:23 -0000 1.2
+++ ManagedConnectionInfo.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -69,7 +69,6 @@
*
* Created: Thu Sep 25 14:29:07 2003
*
- * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
* @version 1.0
*/
public class ManagedConnectionInfo {
@@ -234,4 +233,4 @@
: cri.equals(other.getConnectionRequestInfo()));
}
-} // ManagedConnectionInfo
+}
1.3 +7 -7 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java
Index: MultiPoolConnectionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MultiPoolConnectionInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ MultiPoolConnectionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -100,8 +100,8 @@
this.useCRI = useCRI;
}
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
SubjectCRIKey key =
new SubjectCRIKey(
useSubject ? mci.getSubject() : null,
@@ -122,15 +122,15 @@
}
mci.setPoolInterceptor(poolInterceptor);
- poolInterceptor.getConnection(ci);
+ poolInterceptor.getConnection(connectionInfo);
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
ConnectionInterceptor poolInterceptor = mci.getPoolInterceptor();
- poolInterceptor.returnConnection(ci, cra);
+ poolInterceptor.returnConnection(connectionInfo, connectionReturnAction);
}
static class SubjectCRIKey {
1.4 +14 -14 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java
Index: SinglePoolConnectionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SinglePoolConnectionInterceptor.java 19 Nov 2003 09:45:57 -0000 1.3
+++ SinglePoolConnectionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.4
@@ -110,16 +110,16 @@
pool = new PoolDeque(maxSize);
}
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
try {
if (permits.attempt(blockingTimeout)) {
ManagedConnectionInfo newMCI = null;
synchronized (pool) {
if (pool.isEmpty()) {
- next.getConnection(ci);
+ next.getConnection(connectionInfo);
if (log.isTraceEnabled()) {
- log.trace("Returning new connection " + ci.getManagedConnectionInfo());
+ log.trace("Returning new connection " + connectionInfo.getManagedConnectionInfo());
}
return;
} else {
@@ -135,9 +135,9 @@
mci.getSubject(),
mci.getConnectionRequestInfo());
if (matchedMC != null) {
- ci.setManagedConnectionInfo(newMCI);
+ connectionInfo.setManagedConnectionInfo(newMCI);
if (log.isTraceEnabled()) {
- log.trace("Returning pooled connection " + ci.getManagedConnectionInfo());
+ log.trace("Returning pooled connection " + connectionInfo.getManagedConnectionInfo());
}
return;
} else {
@@ -174,14 +174,14 @@
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
if (log.isTraceEnabled()) {
- log.trace("returning connection" + ci.getConnectionHandle());
+ log.trace("returning connection" + connectionInfo.getConnectionHandle());
}
boolean wasInPool = false;
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
- if (cra == ConnectionReturnAction.DESTROY) {
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
+ if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
synchronized (pool) {
wasInPool = pool.remove(mci);
}
@@ -195,11 +195,11 @@
try {
mc.cleanup();
} catch (ResourceException e) {
- cra = ConnectionReturnAction.DESTROY;
+ connectionReturnAction = ConnectionReturnAction.DESTROY;
}
- if (cra == ConnectionReturnAction.DESTROY) {
- next.returnConnection(ci, cra);
+ if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
+ next.returnConnection(connectionInfo, connectionReturnAction);
} else {
synchronized (pool) {
mci.setLastUsed(System.currentTimeMillis());
1.3 +10 -10 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/SubjectInterceptor.java
Index: SubjectInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/SubjectInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SubjectInterceptor.java 13 Nov 2003 22:22:30 -0000 1.2
+++ SubjectInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -77,24 +77,24 @@
final SecurityDomain securityDomain) {
this.next = next;
this.securityDomain = securityDomain;
- } // SubjectInterceptor constructor
+ }
- public void getConnection(ConnectionInfo ci) throws ResourceException {
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
Subject subject = null;
try {
subject = securityDomain.getSubject();
} catch (SecurityException e) {
throw new ResourceException("Can not obtain Subject for login", e);
- } // end of try-catch
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ }
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
mci.setSubject(subject);
- next.getConnection(ci);
+ next.getConnection(connectionInfo);
}
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
- next.returnConnection(ci, cra);
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
-} // SubjectInterceptor
+}
1.4 +41 -114 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
Index: TransactionCachingInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TransactionCachingInterceptor.java 19 Nov 2003 17:33:44 -0000 1.3
+++ TransactionCachingInterceptor.java 9 Dec 2003 04:16:25 -0000 1.4
@@ -56,146 +56,73 @@
package org.apache.geronimo.connector.outbound;
-import java.util.WeakHashMap;
-import java.util.Iterator;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.HashMap;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.SystemException;
-import javax.transaction.Synchronization;
-import javax.transaction.RollbackException;
import javax.resource.ResourceException;
-import org.apache.geronimo.connector.TxUtils;
+import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
/**
* TransactionCachingInterceptor.java
+ * TODO: This implementation does not take account of unshareable resources
+ * TODO: This implementation does not take account of application security
+ * where several connections with different security info are obtained.
+ * TODO: This implementation does not take account of container managed security where,
+ * within one transaction, a security domain boundary is crossed
+ * and connections are obtained with two (or more) different subjects.
+ *
+ * I suggest a state pattern, with the state set in a threadlocal upon entering a component,
+ * will be a usable implementation.
+ *
+ * The afterCompletion method will need to move to an interface, and that interface include the
+ * security info to distinguish connections.
*
*
* Created: Mon Sep 29 15:07:07 2003
*
* @version 1.0
*/
-public class TransactionCachingInterceptor implements ConnectionInterceptor {
+public class TransactionCachingInterceptor implements ConnectionInterceptor, ConnectionReleaser{
private final ConnectionInterceptor next;
- private final TransactionManager tm;
- private final Map txToConnectionList = new HashMap();
+ private final ConnectionTracker connectionTracker;
- public TransactionCachingInterceptor(final ConnectionInterceptor next, final TransactionManager tm) {
+ public TransactionCachingInterceptor(final ConnectionInterceptor next, final ConnectionTracker connectionTracker) {
this.next = next;
- this.tm = tm;
- }
-
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- try {
- Transaction tx = tm.getTransaction();
- if (TxUtils.isActive(tx)) {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
- Collection mcis;
- synchronized (txToConnectionList) {
- mcis = (Collection)txToConnectionList.get(tx);
- if (mcis == null) {
- mcis = new LinkedList();
- txToConnectionList.put(tx, mcis);
- tx.registerSynchronization(new Synch(tx, this, mcis));
- }
- }
-
- /*Access to mcis should not need to be synchronized
- * unless several requests in the same transaction in
- * different threads are being processed at the same
- * time. This cannot occur with transactions imported
- * through jca. I don't know about any other possible
- * ways this could occur.*/
- for (Iterator i = mcis.iterator(); i.hasNext();) {
- ManagedConnectionInfo oldmci = (ManagedConnectionInfo) i.next();
- if (mci.securityMatches(oldmci)) {
- ci.setManagedConnectionInfo(oldmci);
- return;
- }
-
- }
-
- next.getConnection(ci);
- //put it in the map
- mcis.add(ci.getManagedConnectionInfo());
-
- } else {
- next.getConnection(ci);
- }
- } catch (SystemException e) {
- throw new ResourceException("Could not get transaction from transaction manager", e);
- } catch (RollbackException e) {
- throw new ResourceException("Transaction is rolled back, can't enlist synchronization", e);
- }
- }
-
- public void returnConnection(ConnectionInfo ci, ConnectionReturnAction cra) {
-
- try {
- if (cra == ConnectionReturnAction.DESTROY) {
- next.returnConnection(ci, cra);
- }
-
- Transaction tx = tm.getTransaction();
- if (TxUtils.isActive(tx)) {
- return;
- }
- if (ci.getManagedConnectionInfo().hasConnectionHandles()) {
- return;
- }
- //No transaction, no handles, we return it.
- next.returnConnection(ci, cra);
- } catch (SystemException e) {
- //throw new ResourceException("Could not get transaction from transaction manager", e);
- }
-
+ this.connectionTracker = connectionTracker;
}
-
- public void afterCompletion(Transaction tx) {
- Collection connections = (Collection) txToConnectionList.get(tx);
- if (connections != null) {
- for (Iterator iterator = connections.iterator(); iterator.hasNext();) {
- ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo) iterator.next();
- ConnectionInfo connectionInfo = new ConnectionInfo();
- connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
- returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
- }
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ ConnectorTransactionContext connectorTransactionContext = connectionTracker.getConnectorTransactionContext();
+ ManagedConnectionInfo managedConnectionInfo = connectorTransactionContext.getManagedConnectionInfo(this);
+ if (managedConnectionInfo != null) {
+ connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
+ return;
+ } else {
+ next.getConnection(connectionInfo);
+ connectorTransactionContext.setManagedConnectionInfo(this, connectionInfo.getManagedConnectionInfo());
}
-
}
- private static class Synch implements Synchronization {
+ public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
- private final Transaction transaction;
- private final TransactionCachingInterceptor returnStack;
- private final Collection connections;
-
- public Synch(Transaction transaction, TransactionCachingInterceptor returnStack, Collection connections) {
- this.transaction = transaction;
- this.returnStack = returnStack;
- this.connections = connections;
+ if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
- public void beforeCompletion() {
+ ConnectorTransactionContext connectorTransactionContext = connectionTracker.getConnectorTransactionContext();
+ if (connectorTransactionContext.isActive()) {
+ return;
}
-
- public void afterCompletion(int status) {
- for (Iterator iterator = connections.iterator(); iterator.hasNext();) {
- ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo) iterator.next();
- iterator.remove();
- if (!managedConnectionInfo.hasConnectionHandles()) {
- returnStack.returnConnection(new ConnectionInfo(managedConnectionInfo), ConnectionReturnAction.RETURN_HANDLE);
- }
- }
+ if (connectionInfo.getManagedConnectionInfo().hasConnectionHandles()) {
+ return;
}
+ //No transaction, no handles, we return it.
+ next.returnConnection(connectionInfo, connectionReturnAction);
+ }
+ public void afterCompletion(ManagedConnectionInfo managedConnectionInfo) {
+ ConnectionInfo connectionInfo = new ConnectionInfo();
+ connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
+ returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
}
}
1.3 +24 -24 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptor.java
Index: TransactionEnlistingInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransactionEnlistingInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ TransactionEnlistingInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -76,63 +76,63 @@
public class TransactionEnlistingInterceptor implements ConnectionInterceptor {
private final ConnectionInterceptor next;
- private final TransactionManager tm;
+ private final TransactionManager transactionManager;
public TransactionEnlistingInterceptor(
ConnectionInterceptor next,
- TransactionManager tm) {
+ TransactionManager transactionManager) {
this.next = next;
- this.tm = tm;
- } // TransactionEnlistingInterceptor constructor
+ this.transactionManager = transactionManager;
+ }
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- next.getConnection(ci);
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ next.getConnection(connectionInfo);
try {
- Transaction tx = tm.getTransaction();
+ Transaction tx = transactionManager.getTransaction();
if (TxUtils.isActive(tx)) {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
XAResource xares = mci.getXAResource();
tx.enlistResource(xares);
mci.setTransaction(tx);
- } // end of if ()
+ }
} catch (SystemException e) {
throw new ResourceException("Could not get transaction", e);
- } // end of try-catch
+ }
catch (RollbackException e) {
throw new ResourceException(
"Could not enlist resource in rolled back transaction",
e);
- } // end of catch
+ }
}
/**
* The <code>returnConnection</code> method
*
- * @todo Probably the logic needs improvement if a connection
+ * todo Probably the logic needs improvement if a connection
* error occurred and we are destroying the handle.
- * @param ci a <code>ConnectionInfo</code> value
- * @param cra a <code>ConnectionReturnAction</code> value
- * @exception ResourceException if an error occurs
+ * @param connectionInfo a <code>ConnectionInfo</code> value
+ * @param connectionReturnAction a <code>ConnectionReturnAction</code> value
*/
public void returnConnection(
- ConnectionInfo ci,
- ConnectionReturnAction cra) {
+ ConnectionInfo connectionInfo,
+ ConnectionReturnAction connectionReturnAction) {
try {
- Transaction tx = tm.getTransaction();
+ Transaction tx = transactionManager.getTransaction();
if (TxUtils.isActive(tx)) {
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
XAResource xares = mci.getXAResource();
tx.delistResource(xares, XAResource.TMSUSPEND);
mci.setTransaction(null);
- } // end of if ()
+ }
} catch (SystemException e) {
- //throw new ResourceException("Could not get transaction", e);
- } // end of try-catch
+ //maybe we should warn???
+ connectionReturnAction = ConnectionReturnAction.DESTROY;
+ }
- next.returnConnection(ci, cra);
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
-} // TransactionEnlistingInterceptor
+}
1.3 +8 -11 incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptor.java
Index: XAResourceInsertionInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XAResourceInsertionInterceptor.java 14 Nov 2003 16:00:23 -0000 1.2
+++ XAResourceInsertionInterceptor.java 9 Dec 2003 04:16:25 -0000 1.3
@@ -62,9 +62,7 @@
* XAResourceInsertionInterceptor.java
*
*
- * Created: Tue Sep 30 00:50:34 2003
- *
- * @version 1.0
+ * @version $Revision$ $Date$
*/
public class XAResourceInsertionInterceptor implements ConnectionInterceptor {
@@ -72,17 +70,16 @@
public XAResourceInsertionInterceptor(final ConnectionInterceptor next) {
this.next = next;
- } // XAResourceInsertionInterceptor constructor
+ }
- public void getConnection(ConnectionInfo ci) throws ResourceException {
- next.getConnection(ci);
- ManagedConnectionInfo mci = ci.getManagedConnectionInfo();
+ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+ next.getConnection(connectionInfo);
+ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
mci.setXAResource(mci.getManagedConnection().getXAResource());
}
- public void returnConnection(ConnectionInfo ci, ConnectionReturnAction cra) {
- next.returnConnection(ci, cra);
+ public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
+ next.returnConnection(connectionInfo, connectionReturnAction);
}
-
-} // XAResourceInsertionInterceptor
+}