[jboss-cvs] JBossAS SVN: r67623 - in trunk/cluster/src/main/org/jboss: invocation/jrmp/interfaces and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 29 14:50:01 EST 2007


Author: galder.zamarreno at jboss.com
Date: 2007-11-29 14:50:01 -0500 (Thu, 29 Nov 2007)
New Revision: 67623

Added:
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailable.java
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailableIdenticalAllProxies.java
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRandomRobin.java
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRoundRobin.java
Modified:
   trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
   trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
Log:
[JBAS-4455] Transaction sticky load balance policies have been created for each of the default existing ones. JRMP and Unified invoker proxy ha classes now contain the logic to put/get sticky target from the transaction failover authorisation map.

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+import org.jboss.invocation.Invocation;
+import org.jboss.logging.Logger;
+
+/**
+ * Root transaction sticky load balance policy class who checks whether there's
+ * sticky target associated with the invocation. If there is, it returns that
+ * target otherwise, it'll delegate on the given load balance policy to choose 
+ * a new target. 
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class TransactionSticky implements LoadBalancePolicy
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -8750524198817324850L;
+
+   private static final Logger log = Logger.getLogger(TransactionSticky.class);
+   
+   private transient boolean trace;
+   
+   private final LoadBalancePolicy delegateLoadBalancePolicy;
+   
+   public TransactionSticky(LoadBalancePolicy delegate)
+   {
+      delegateLoadBalancePolicy = delegate;
+      
+      if (trace)
+      {
+         log.trace("transaction sticky load balance policy delegates to: " + delegateLoadBalancePolicy);
+      }
+   }
+
+   /**
+    * This method returns either, a new target based on RoundRobin policy, or 
+    * if there's a ongoing transaction, the target associated with that 
+    * transaction.
+    *
+    * @param familyClusterInfo cluster family information
+    * @param invocation current invocation
+    * @return a new target or the target associated with the transaction
+    */
+   public Object chooseTarget(FamilyClusterInfo clusterFamily, Invocation routingDecision)
+   {
+      trace = log.isTraceEnabled();
+      Object txStickyTarget = routingDecision.getTransientValue("TX_STICKY_TARGET");
+      if (txStickyTarget != null && clusterFamily.getTargets().contains(txStickyTarget))
+      {
+         if (trace) 
+         {
+            log.trace("transaction bound target exists: " + txStickyTarget);
+         } 
+         
+         return txStickyTarget;
+      }
+
+      return chooseNewTarget(clusterFamily, routingDecision);
+   }   
+   
+   public void init(HARMIClient father)
+   {
+      delegateLoadBalancePolicy.init(father);
+   }
+
+   public Object chooseTarget(FamilyClusterInfo clusterFamily)
+   {
+      return delegateLoadBalancePolicy.chooseTarget(clusterFamily);
+   }
+   
+   /**
+    * Choses a new target based on RoundRobin load balance policy.
+    *
+    * @param familyClusterInfo cluster family information
+    * @param invocation current invocation
+    * @return a new target
+    */
+   protected Object chooseNewTarget(FamilyClusterInfo familyClusterInfo, Invocation invocation)
+   {
+      Object newTarget = delegateLoadBalancePolicy.chooseTarget(familyClusterInfo, invocation);
+      
+      if (trace) 
+      {
+         log.trace("new target chosen: " + newTarget);
+      }
+      
+      invocation.getTransientPayload().put("TX_STICKY_TARGET", newTarget);
+
+      return newTarget;
+   }
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailable.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailable.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailable.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * TransactionStickyFirstAvailable.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class TransactionStickyFirstAvailable extends TransactionSticky
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -8688525543058853326L;
+
+   /**
+    * Create a new TransactionStickyFirstAvailable.
+    */
+   public TransactionStickyFirstAvailable()
+   {
+      super(new FirstAvailable());
+   }
+
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailableIdenticalAllProxies.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailableIdenticalAllProxies.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyFirstAvailableIdenticalAllProxies.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * TransactionStickyFirstAvailableIdenticalAllProxies.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class TransactionStickyFirstAvailableIdenticalAllProxies extends TransactionSticky
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -108026886517429364L;
+
+   /**
+    * Create a new TransactionStickyFirstAvailableIdenticalAllProxies.
+    * 
+    */
+   public TransactionStickyFirstAvailableIdenticalAllProxies()
+   {
+      super(new FirstAvailableIdenticalAllProxies());
+   }
+
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRandomRobin.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRandomRobin.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRandomRobin.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * TransactionStickyRandomRobin.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class TransactionStickyRandomRobin extends TransactionSticky
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -2684882134710754122L;
+
+   /**
+    * Create a new TransactionStickyRandomRobin.
+    */
+   public TransactionStickyRandomRobin()
+   {
+      super(new RandomRobin());
+   }
+
+}

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRoundRobin.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRoundRobin.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionStickyRoundRobin.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * TransactionStickyRoundRobin.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class TransactionStickyRoundRobin extends TransactionSticky
+{
+   
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 8195610955344716827L;
+   
+   /**
+    * Create a new TransactionStickyRoundRobin.
+    */
+   public TransactionStickyRoundRobin()
+   {
+      super(new RoundRobin());
+   }   
+   
+}

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-29 19:11:11 UTC (rev 67622)
+++ trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -180,7 +180,14 @@
                log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
             }
             
-            txFailoverAuthorizations.put(tpc, null);
+            Object stickyTarget = invocation.getTransientValue("TX_STICKY_TARGET");
+            
+            if (trace && stickyTarget != null)
+            {
+               log.trace("remember transaction bound target[" + stickyTarget + "] for tpc[" + tpc + "]");
+            }
+            
+            txFailoverAuthorizations.put(tpc, stickyTarget);
          }
       }
    }
@@ -197,6 +204,9 @@
       //
       int failoverCounter = 0;
       invocation.setValue ("FAILOVER_COUNTER", new Integer(failoverCounter), PayloadKey.AS_IS);
+      
+      // If transaction sticky, put chosen target
+      putIfExistsTransactionTarget(invocation, getTransactionPropagationContext());
 
       // optimize if calling another bean in same EJB-application
       if (isLocal(invocation))
@@ -408,6 +418,38 @@
       return tpc;
    }   
    
+   /**
+    * Called at the beginning of the invocation to check whether the current tpc
+    * is already present in the tx failover map. If it is, get the chosen 
+    * target associated to it and add it to the invocation transient payload so 
+    * that the load balance policy can choose the right target.
+    */
+   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+   {
+      if (tpc != null)
+      {
+         synchronized (tpc)
+         {
+            if (trace)
+            {
+               log.trace("in the proxy, transaction propagation context (tpc) is " + tpc);
+            }
+
+            Object stickyTarget = txFailoverAuthorizations.get(tpc);
+               
+            if (stickyTarget != null)
+            {
+               if (trace)
+               {
+                  log.trace("put transaction bound target [" + stickyTarget + "] into transient payload");
+               }
+               
+               invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
+            }
+         }
+      }
+   }
+   
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------

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-29 19:11:11 UTC (rev 67622)
+++ trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2007-11-29 19:50:01 UTC (rev 67623)
@@ -129,7 +129,14 @@
                log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
             }
             
-            txFailoverAuthorizations.put(tpc, null);
+            Object stickyTarget = invocation.getTransientValue("TX_STICKY_TARGET");
+            
+            if (trace && stickyTarget != null)
+            {
+               log.trace("remember transaction bound target[" + stickyTarget + "] for tpc[" + tpc + "]");
+            }
+            
+            txFailoverAuthorizations.put(tpc, stickyTarget);
          }
       }
    }
@@ -191,6 +198,9 @@
       //
       int failoverCounter = 0;
       invocation.setValue("FAILOVER_COUNTER", new Integer(failoverCounter), PayloadKey.AS_IS);
+      
+      // If transaction sticky, put chosen target
+      putIfExistsTransactionTarget(invocation, getTransactionPropagationContext());
 
       Object response = null;
       Exception lastException = null;
@@ -520,4 +530,36 @@
       TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
       return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext();
    }
+   
+   /**
+    * Called at the beginning of the invocation to check whether the current tpc
+    * is already present in the tx failover map. If it is, get the chosen 
+    * target associated to it and add it to the invocation transient payload so 
+    * that the load balance policy can choose the right target.
+    */
+   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+   {
+      if (tpc != null)
+      {
+         synchronized (tpc)
+         {
+            if (trace)
+            {
+               log.trace("in the proxy, transaction propagation context (tpc) is " + tpc);
+            }
+
+            Object stickyTarget = txFailoverAuthorizations.get(tpc);
+               
+            if (stickyTarget != null)
+            {
+               if (trace)
+               {
+                  log.trace("put transaction bound target [" + stickyTarget + "] into transient payload");
+               }
+               
+               invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
+            }
+         }
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list