[jboss-cvs] JBossAS SVN: r63230 - in trunk/iiop/src/main/org/jboss/tm/iiop: client and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 28 20:54:34 EDT 2007
Author: reverbel
Date: 2007-05-28 20:54:34 -0400 (Mon, 28 May 2007)
New Revision: 63230
Modified:
trunk/iiop/src/main/org/jboss/tm/iiop/TxClientInterceptor.java
trunk/iiop/src/main/org/jboss/tm/iiop/client/IIOPClientUserTransaction.java
Log:
Do not send the transaction propagation context along with requests to the Coordinator or with requests to the Terminator. (Optimization submitted by Ivan Neto.)
Modified: trunk/iiop/src/main/org/jboss/tm/iiop/TxClientInterceptor.java
===================================================================
--- trunk/iiop/src/main/org/jboss/tm/iiop/TxClientInterceptor.java 2007-05-28 20:13:35 UTC (rev 63229)
+++ trunk/iiop/src/main/org/jboss/tm/iiop/TxClientInterceptor.java 2007-05-29 00:54:34 UTC (rev 63230)
@@ -42,6 +42,7 @@
* inserts the transactional context into outgoing requests.
*
* @author <a href="mailto:reverbel at ime.usp.br">Francisco Reverbel</a>
+ * @author <a href="mailto:ivanneto at ime.usp.br">Ivan Neto</a>
* @version $Revision$
*/
public class TxClientInterceptor
@@ -61,6 +62,9 @@
private static final Logger log =
Logger.getLogger(TxClientInterceptor.class);
private static final boolean traceEnabled = log.isTraceEnabled();
+
+ /** Propagation context associated with the current thread. */
+ private static ThreadLocal threadLocalData = new ThreadLocal();
// Static methods ------------------------------------------------
@@ -109,6 +113,43 @@
}
/**
+ * Suspends the transaction propagation context associated with the current
+ * thread.
+ */
+ public static void suspendOutgoingPropagationContext()
+ {
+ try
+ {
+ Any pcAny = piCurrent.get_slot(slotId);
+ threadLocalData.set(pcAny);
+ piCurrent.set_slot(slotId, getEmptyAny());
+ }
+ catch (InvalidSlot e)
+ {
+ throw new RuntimeException("Exception suspending propagation " +
+ "context: " + e);
+ }
+ }
+
+ /**
+ * Resumes the transaction propagation context associated with the current
+ * thread.
+ */
+ public static void resumeOutgoingPropagationContext()
+ {
+ try
+ {
+ Any pcAny = (Any) threadLocalData.get();
+ piCurrent.set_slot(slotId, pcAny);
+ }
+ catch (InvalidSlot e)
+ {
+ throw new RuntimeException("Exception resuming propagation context: "
+ + e);
+ }
+ }
+
+ /**
* Auxiliary method that returns an empty Any.
*/
private static Any getEmptyAny()
Modified: trunk/iiop/src/main/org/jboss/tm/iiop/client/IIOPClientUserTransaction.java
===================================================================
--- trunk/iiop/src/main/org/jboss/tm/iiop/client/IIOPClientUserTransaction.java 2007-05-28 20:13:35 UTC (rev 63229)
+++ trunk/iiop/src/main/org/jboss/tm/iiop/client/IIOPClientUserTransaction.java 2007-05-29 00:54:34 UTC (rev 63230)
@@ -67,6 +67,7 @@
* at the server.
*
* @author <a href="mailto:reverbel at ime.usp.br">Francisco Reverbel</a>
+ * @author <a href="mailto:ivanneto at ime.usp.br">Ivan Neto</a>
* @version $Revision$
*/
public class IIOPClientUserTransaction
@@ -103,10 +104,9 @@
*/
private static class TransactionInfo
{
- int timeout = 0; // for new transactions started by the current thread
- Control control; // null if no current transaction
- Coordinator coord; // null if no current transaction
- Terminator term; // null if no current transaction
+ int timeout = 0; // for new transactions started by the current thread
+ Control control; // null if no current transaction
+ PropagationContext pc; // null if no current transaction
}
// Static accessors to thread-local data -------------------------
@@ -131,25 +131,27 @@
return ((TransactionInfo)threadLocalData.get()).control;
}
- private static void setThreadLocalCoordinator(Coordinator coord)
+ private static void setThreadLocalPropagationContext(PropagationContext pc)
{
- ((TransactionInfo)threadLocalData.get()).coord = coord;
+ ((TransactionInfo)threadLocalData.get()).pc = pc;
}
- private static Coordinator getThreadLocalCoordinator()
+ private static PropagationContext getThreadLocalPropagationContext()
{
- return ((TransactionInfo)threadLocalData.get()).coord;
+ return ((TransactionInfo)threadLocalData.get()).pc;
}
-
- private static void setThreadLocalTerminator(Terminator term)
+
+ private static Coordinator getThreadLocalCoordinator()
{
- ((TransactionInfo)threadLocalData.get()).term = term;
+ PropagationContext pc = ((TransactionInfo)threadLocalData.get()).pc;
+ return pc == null ? null : pc.current.coord;
}
private static Terminator getThreadLocalTerminator()
throws NoTransaction
{
- Terminator term = ((TransactionInfo)threadLocalData.get()).term;
+ PropagationContext pc = ((TransactionInfo)threadLocalData.get()).pc;
+ Terminator term = (pc == null ? null : pc.current.term);
if (term == null)
throw new NoTransaction();
@@ -166,8 +168,7 @@
PropagationContext pc)
{
setThreadLocalControl(control);
- setThreadLocalCoordinator(pc.current.coord);
- setThreadLocalTerminator(pc.current.term);
+ setThreadLocalPropagationContext(pc);
TxClientInterceptor.setOutgoingPropagationContext(pc);
}
@@ -177,8 +178,7 @@
private static void unsetCurrentTransaction()
{
setThreadLocalControl(null);
- setThreadLocalCoordinator(null);
- setThreadLocalTerminator(null);
+ setThreadLocalPropagationContext(null);
TxClientInterceptor.unsetOutgoingPropagationContext();
}
@@ -299,7 +299,11 @@
{
try
{
- getThreadLocalTerminator().commit(true /* reportHeuristics */);
+ Terminator term = getThreadLocalTerminator();
+ // Requests to the Terminator should not propagate the transaction
+ // context.
+ TxClientInterceptor.unsetOutgoingPropagationContext();
+ term.commit(true /* reportHeuristics */);
}
catch (NoTransaction e)
{
@@ -356,7 +360,11 @@
{
try
{
- getThreadLocalTerminator().rollback();
+ Terminator term = getThreadLocalTerminator();
+ // Requests to the Terminator should not propagate the transaction
+ // context.
+ TxClientInterceptor.unsetOutgoingPropagationContext();
+ term.rollback();
}
catch (NoTransaction e)
{
@@ -399,6 +407,9 @@
try
{
+ // Requests to the Coordinator should not propagate the transaction
+ // context.
+ TxClientInterceptor.suspendOutgoingPropagationContext();
coord.rollback_only();
}
catch (Inactive e)
@@ -419,6 +430,10 @@
ex.initCause(e);
throw ex;
}
+ finally
+ {
+ TxClientInterceptor.resumeOutgoingPropagationContext();
+ }
}
public int getStatus()
@@ -428,9 +443,23 @@
{
Coordinator coord = getThreadLocalCoordinator();
if (coord == null)
+ {
return Status.STATUS_NO_TRANSACTION;
- else
- return cosTransactionsToJavax(coord.get_status());
+ }
+ else
+ {
+ try
+ {
+ // Requests to the Coordinator should not propagate the
+ // transaction context.
+ TxClientInterceptor.suspendOutgoingPropagationContext();
+ return cosTransactionsToJavax(coord.get_status());
+ }
+ finally
+ {
+ TxClientInterceptor.resumeOutgoingPropagationContext();
+ }
+ }
}
catch (OBJECT_NOT_EXIST e)
{
More information about the jboss-cvs-commits
mailing list