[jboss-cvs] JBossAS SVN: r67146 - in trunk/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
Thu Nov 15 12:46:35 EST 2007


Author: galder.zamarreno at jboss.com
Date: 2007-11-15 12:46:35 -0500 (Thu, 15 Nov 2007)
New Revision: 67146

Modified:
   trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
   trunk/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java
   trunk/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. Fixed some trace message logs to check transient variable. Added convenience methods in JRMP invoker classes to facilitate unit testing.

Modified: trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2007-11-15 17:18:08 UTC (rev 67145)
+++ trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2007-11-15 17:46:35 UTC (rev 67146)
@@ -32,6 +32,8 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.WeakHashMap;
+
+import javax.transaction.SystemException;
 import javax.transaction.TransactionRolledbackException;
 
 import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
@@ -54,6 +56,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
@@ -145,12 +148,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
@@ -161,12 +170,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);
          }
       }
    }
@@ -373,6 +387,27 @@
          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 -------------------------------------------------------
 
    // Inner classes -------------------------------------------------

Modified: trunk/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java	2007-11-15 17:18:08 UTC (rev 67145)
+++ trunk/cluster/src/main/org/jboss/invocation/jrmp/server/JRMPInvokerHA.java	2007-11-15 17:46:35 UTC (rev 67146)
@@ -51,6 +51,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
@@ -127,11 +128,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
@@ -237,6 +234,11 @@
       return result;
    }
    
+   protected Invoker createProxy(ArrayList targets, LoadBalancePolicy policy,
+         String proxyFamilyName, long viewId)
+   {
+      return new JRMPInvokerProxyHA(targets, policy, proxyFamilyName, viewId);
+   }   
    
    
    

Modified: trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2007-11-15 17:18:08 UTC (rev 67145)
+++ trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2007-11-15 17:46:35 UTC (rev 67146)
@@ -44,6 +44,8 @@
 import org.jboss.remoting.CannotConnectException;
 import org.jboss.remoting.Client;
 import org.jboss.remoting.InvokerLocator;
+import org.jboss.tm.TransactionPropagationContextFactory;
+import org.jboss.tm.TransactionPropagationContextUtil;
 
 /**
  * Unified invoker implementation for InvokerProxyHA
@@ -72,7 +74,12 @@
    {
       super();
       trace = log.isTraceEnabled();
-      log.trace("UnifiedInvokerHAProxy constructor called with no arguments.");
+      
+      if (trace)
+      {
+         log.trace("UnifiedInvokerHAProxy constructor called with no arguments.");
+      }
+      
       setSubSystem("invokerha");
    }
 
@@ -92,28 +99,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 (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
-      {
-         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 (trace)
+            {
+               log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
+            }
+            
+            txFailoverAuthorizations.put(tpc, null);
          }
       }
    }
@@ -190,8 +206,8 @@
             
             if (trace)
             {
-               log.debug("Client cluster view id: " + familyClusterInfo.getCurrentViewId());
-               log.debug(printPossibleTargets());
+               log.trace("Client cluster view id: " + familyClusterInfo.getCurrentViewId());
+               log.trace(printPossibleTargets());
             }
 
             Client clientInstance = getClient(invocation);
@@ -241,7 +257,10 @@
                      failoverCounter++;
                      invocation.setValue("FAILOVER_COUNTER", new Integer(failoverCounter), PayloadKey.AS_IS);
 
-                     log.trace("Received GenericClusteringException where request was not completed.  Will retry.");
+                     if (trace)
+                     {
+                        log.trace("Received GenericClusteringException where request was not completed.  Will retry.");
+                     }
 
                      continue;
                   }
@@ -279,7 +298,11 @@
          }
          catch(CannotConnectException cncEx)
          {
-            log.trace("Invocation failed: CannotConnectException - " + cncEx, cncEx);
+            if (trace)
+            {
+               log.trace("Invocation failed: CannotConnectException - " + cncEx, cncEx);
+            }
+            
             removeDeadTarget(getLocator());
             resetView();
             failoverAuthorized = txContextAllowsFailover(invocation);
@@ -315,8 +338,11 @@
 
                failoverCounter++;
                invocation.setValue("FAILOVER_COUNTER", new Integer(failoverCounter), PayloadKey.AS_IS);
-
-               log.trace("Received GenericClusteringException where request was not completed.  Will retry.");
+               
+               if (trace)
+               {
+                  log.trace("Received GenericClusteringException where request was not completed.  Will retry.");
+               }
             }
             else
             {
@@ -326,7 +352,10 @@
          }
          catch(RemoteException aex)
          {
-            log.trace("Invocation failed: RemoteException - " + aex, aex);
+            if (trace)
+            {
+               log.trace("Invocation failed: RemoteException - " + aex, aex);
+            }
 
             // per Jira issue JBREM-61
             if(isStrictRMIException())
@@ -340,7 +369,10 @@
          }
          catch(Throwable throwable)
          {
-            log.trace("Invocation failed: " + throwable, throwable);
+            if (trace)
+            {
+               log.trace("Invocation failed: " + throwable, throwable);
+            }
 
             // this is somewhat of a hack as remoting throws throwable,
             // so will let Exception types bubble up, but if Throwable type,
@@ -393,7 +425,9 @@
          {
             familyClusterInfo.removeDeadTarget(locator);
             if (trace)
+            {
                log.trace("Removed " + locator + " from target list.");
+            }
          }
       }
    }
@@ -404,7 +438,7 @@
       if(familyClusterInfo != null)
       {
          familyClusterInfo.updateClusterInfo(newReplicants, currentViewId);
-         if (log.isTraceEnabled())
+         if (trace)
          {
             log.trace("Updating cluster info.  New view id: " + currentViewId);
             log.trace("New cluster target list is:");
@@ -470,9 +504,20 @@
       }
       
       trace = log.isTraceEnabled();
-      if( trace )
+      if(trace)
+      {
          log.trace("Init, clusterInfo: "+familyClusterInfo+", policy="+loadBalancePolicy);
+      }
    }
 
-
+   /**
+    * 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