[jboss-cvs] JBossAS SVN: r67188 - in branches/Branch_4_2/cluster/src/main/org/jboss/invocation: jrmp/server and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 16 14:12:39 EST 2007


Author: galder.zamarreno at jboss.com
Date: 2007-11-16 14:12:39 -0500 (Fri, 16 Nov 2007)
New Revision: 67188

Modified:
   branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
   branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java
   branches/Branch_4_2/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
Log:
[JBAS-4964] Transaction failover authorisation map is now keyed on tpc (transaction propagation context) for both Unified and JRMP invoker proxies. Added convenience methods in JRMP invoker classes to facilitate unit testing.

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2007-11-16 19:09:24 UTC (rev 67187)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2007-11-16 19:12:39 UTC (rev 67188)
@@ -30,6 +30,8 @@
 import java.rmi.ServerException;
 import java.util.ArrayList;
 import java.util.WeakHashMap;
+
+import javax.transaction.SystemException;
 import javax.transaction.TransactionRolledbackException;
 
 import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
@@ -51,6 +53,7 @@
  * 
  * @author <a href="mailto:marc.fleury at jboss.org">Marc Fleury</a>
  * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  * @version $Revision$
  */
 public class JRMPInvokerProxyHA
@@ -128,12 +131,18 @@
    
    public boolean txContextAllowsFailover (Invocation invocation)
    {
-      javax.transaction.Transaction tx = invocation.getTransaction();
-      if (tx != null)
+      Object tpc = getTransactionPropagationContext();
+      if (tpc != null)
       {
-         synchronized (tx)
+         synchronized (tpc)
          {
-            return ! txFailoverAuthorizations.containsKey (tx);               
+            if (trace)
+            {
+               log.trace("checking tx failover authorisation map with tpc " + tpc);
+            }
+            
+            /* if the map contains the tpc, then we can't allow a failover */
+            return ! txFailoverAuthorizations.containsKey (tpc);               
          }
       }
       else
@@ -144,12 +153,17 @@
    
    public void invocationHasReachedAServer (Invocation invocation)
    {
-      javax.transaction.Transaction tx = invocation.getTransaction();
-      if (tx != null)
+      Object tpc = getTransactionPropagationContext();
+      if (tpc != null)
       {
-         synchronized (tx)
+         synchronized (tpc)
          {
-            txFailoverAuthorizations.put (tx, null);               
+            if (trace)
+            {
+               log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
+            }
+            
+            txFailoverAuthorizations.put(tpc, null);
          }
       }
    }
@@ -347,6 +361,26 @@
       if( trace )
          log.trace("Init, clusterInfo: "+familyClusterInfo+", policy="+loadBalancePolicy);
    }
+   
+   /**
+    * Overriden method to rethrow any potential SystemException arising from it.
+    * Looking at the parent implementation, none of the methods called actually 
+    * throw SystemException.
+    */
+   public Object getTransactionPropagationContext()
+   {
+      Object tpc;
+      try
+      {
+         tpc = super.getTransactionPropagationContext();
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException("Unable to retrieve transaction propagation context", e);
+      }
+      
+      return tpc;
+   }
 
    // Private -------------------------------------------------------
 

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java	2007-11-16 19:09:24 UTC (rev 67187)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java	2007-11-16 19:12:39 UTC (rev 67188)
@@ -50,6 +50,7 @@
  * @author <a href="mailto:bill at burkecentral.com>Bill Burke</a>
  * @author  <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
  * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  * @version $Revision$
  */
 public class JRMPInvokerHA
@@ -124,11 +125,7 @@
       if (familyName == null)
          familyName= target.getAssociatedPartition().getPartitionName() + "/" + beanName;
 
-      JRMPInvokerProxyHA proxy = new JRMPInvokerProxyHA(target.getReplicants(), 
-                                                        policy, 
-                                                        familyName, 
-                                                        target.getCurrentViewId ());
-      return proxy;
+      return createProxy(target.getReplicants(), policy, familyName, target.getCurrentViewId ());
    }
 
    public void unregisterBean(ObjectName beanName) throws Exception
@@ -210,5 +207,11 @@
          Thread.currentThread().setContextClassLoader(oldCl);
       }      
    }
+   
+   protected Invoker createProxy(ArrayList targets, LoadBalancePolicy policy, 
+         String proxyFamilyName, long viewId)
+   {
+      return new JRMPInvokerProxyHA(targets, policy, proxyFamilyName, viewId);
+   }
 }
 

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2007-11-16 19:09:24 UTC (rev 67187)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2007-11-16 19:12:39 UTC (rev 67188)
@@ -45,6 +45,8 @@
 import org.jboss.remoting.Client;
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.remoting.serialization.IMarshalledValue;
+import org.jboss.tm.TransactionPropagationContextFactory;
+import org.jboss.tm.TransactionPropagationContextUtil;
 
 
 /**
@@ -90,28 +92,37 @@
 
    public boolean txContextAllowsFailover(Invocation invocation)
    {
-      javax.transaction.Transaction tx = invocation.getTransaction();
-      if(tx != null)
+      Object tpc = getTransactionPropagationContext();
+      if(tpc != null)
       {
-         synchronized(tx)
+         synchronized(tpc)
          {
-            return ! txFailoverAuthorizations.containsKey(tx);
+            if (log.isTraceEnabled())
+            {
+               log.trace("checking tx failover authorisation map with tpc " + tpc);
+            }
+
+            /* if the map contains the tpc, then we can't allow a failover */
+            return ! txFailoverAuthorizations.containsKey(tpc);
          }
       }
-      else
-      {
-         return true;
-      }
+      
+      return true;
    }
 
    public void invocationHasReachedAServer(Invocation invocation)
    {
-      javax.transaction.Transaction tx = invocation.getTransaction();
-      if(tx != null)
+      Object tpc = getTransactionPropagationContext();
+      if(tpc != null)
       {
-         synchronized(tx)
+         synchronized(tpc)
          {
-            txFailoverAuthorizations.put(tx, null);
+            if (log.isTraceEnabled())
+            {
+               log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
+            }
+            
+            txFailoverAuthorizations.put(tpc, null);
          }
       }
    }
@@ -455,5 +466,14 @@
       }
    }
 
-
+   /**
+    * Before invocation, access to transaction propagation context is needed
+    * to find out whether the invocation is part of an on going transaction and 
+    * might need it's target being sticky to this tx. 
+    */
+   protected Object getTransactionPropagationContext()
+   {
+      TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
+      return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext();
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list