[jboss-cvs] JBossAS SVN: r67103 - in projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client: loadbalance and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 14 18:33:39 EST 2007


Author: bstansberry at jboss.com
Date: 2007-11-14 18:33:39 -0500 (Wed, 14 Nov 2007)
New Revision: 67103

Added:
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/AopLoadBalancePolicy.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailable.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailableIdenticalAllProxies.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/LoadBalancePolicy.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RandomRobin.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RoundRobin.java
Removed:
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailable.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailableIdenticalAllProxies.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/LoadBalancePolicy.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RandomRobin.java
   projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RoundRobin.java
Log:
Move LBPs to a separate package

Deleted: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailable.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailable.java	2007-11-14 23:27:50 UTC (rev 67102)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailable.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -1,99 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.client;
-
-import java.util.List;
-
-
-
-/**
- * LoadBalancePolicy implementation that, once a target is chosen, always favors 
- * that same target; i.e. no further load balancing occurs. Useful in cases where
- * "sticky session" behavior is desired. Initially the favored 
- * target is randomly selected, so different instances of this class
- * will likely not all select the same target; thus load balancing does occur
- * across different proxies. Favoring the same target does not 
- * mean that fail-over will not occur if the chosen target dies. In this case, 
- * fail-over will occur, and a new favored target will be randomly chosen and 
- * invocation will continously be invoked on this new target until its death.
- * <p> 
- * Each proxy using this policy will choose its own
- * preferred target: the target is not shared accross the proxy family. For 
- * shared behaviour please take a look at 
- * {@link FirstAvailableIdenticalAllProxies}.
- * </p>
- * 
- * @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 brian.stansberry at jboss.com
- * 
- * @version $Revision$
- * 
- * @see org.jboss.ha.client.LoadBalancePolicy
- *
- * <p><b>Revisions:</b><br>
- * <p><b>2002/08/24: Sacha Labourey</b>
- * <ol>
- *   <li>Use the target repository</li>
- *   <li>First choice is randomly selected to distribute the initial load</li>
- *   <li>When the list of targets change, we try to keep using the same 
-         previously elected target node if it still exists. Previously,
-         we were working with the position id of the target node, thus
-         if the list order changed, we were switching to another node
-         while our prefered node was still up</li>
- * </ol>
- */
-
-public class FirstAvailable implements LoadBalancePolicy
-{
-   // Constants -----------------------------------------------------
-   
-   private static final long serialVersionUID = 2008524502721775114L;
-
-   // Attributes ----------------------------------------------------
-   
-   protected transient Object electedTarget = null;
-   
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-       
-    // Public --------------------------------------------------------
-
-   public Object chooseTarget (FamilyClusterInfo clusterFamily)
-   {
-      List targets = clusterFamily.getTargets ();
-      if (targets.size () == 0)
-         return null;
-
-      if ( (this.electedTarget != null) && targets.contains (this.electedTarget) )
-      {
-         return this.electedTarget;
-      }
-      else
-      {
-         int cursor = RandomRobin.localRandomizer.nextInt(targets.size());
-         this.electedTarget = targets.get(cursor);
-         return this.electedTarget;
-      }
-   }
-}

Deleted: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailableIdenticalAllProxies.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailableIdenticalAllProxies.java	2007-11-14 23:27:50 UTC (rev 67102)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/FirstAvailableIdenticalAllProxies.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -1,78 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.client;
-
-import java.util.List;
-
-
-
-/**
- * Extends the "sticky session" behavior of {@link FirstAvailable} by caching 
- * the favored target in the {@link FamilyClusterInfo}, thus allowing different 
- * proxies for the same family to use the same favored target.
- * <p>
- * See {@link FirstAvailable} for the basic behavior.
- * </p>
- * 
- * @see org.jboss.ha.client.LoadBalancePolicy
- * @see org.jboss.ha.client.FamilyClusterInfo#getObject()
- *
- * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
- * @author brian.stansberry at jboss.com
- * 
- * @version $Revision$
- */
-public class FirstAvailableIdenticalAllProxies implements LoadBalancePolicy
-{
-   // Constants -----------------------------------------------------
-   private static final long serialVersionUID = 2910756623413400467L;
-
-   // Attributes ----------------------------------------------------
-   
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-       
-    // Public --------------------------------------------------------
-
-   public Object chooseTarget (FamilyClusterInfo clusterFamily)
-   {
-      Object target = clusterFamily.getObject ();
-      List targets = clusterFamily.getTargets ();
-
-      if (targets.size () == 0)
-         return null;
-      
-      if (target != null && targets.contains (target) )
-      {
-         return target;
-      }
-      else
-      {
-         int cursor = RandomRobin.localRandomizer.nextInt (targets.size());
-         target = targets.get(cursor);
-         clusterFamily.setObject (target);
-         return target;
-      }   
-   }
-
-}

Deleted: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/LoadBalancePolicy.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/LoadBalancePolicy.java	2007-11-14 23:27:50 UTC (rev 67102)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/LoadBalancePolicy.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -1,57 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.client;
-
-import java.io.Serializable;
-
-
-/**
- * Base interface for load-balancing policies. It is possible to implement many
- * different load-balancing policies by implementing this simple interface and
- * using it in the different clustered services (home interface of SLSB for
- * example)
- *
- * @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 brian.stansberry at jboss.com
- * 
- * @version $Revision$
- */
-public interface LoadBalancePolicy extends Serializable
-{
-   /** The serialVersionUID
-    * @since 1.3.4.2
-    */ 
-   static final long serialVersionUID = -5071668971774090555L;
-
-   /**
-    * Gets the target for the next remote call.
-    * <p>
-    * Called when the client wishes to know on which node the next invocation must
-    * be performed.
-    * </p>
-    * 
-    * @param clusterFamily object encapsulating a list of potential target nodes
-    * @return The selected target for the next invocation
-    */   
-   public Object chooseTarget (FamilyClusterInfo clusterFamily);
-}

Deleted: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RandomRobin.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RandomRobin.java	2007-11-14 23:27:50 UTC (rev 67102)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RandomRobin.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -1,74 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt 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.client;
-
-import java.util.List;
-import java.util.Random;
-
-
-
-/**
- * LoadBalancePolicy implementation that always fully randomly selects its target
- * (without basing its decision on any history).
- *
- * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
- * @author brian.stansberry at jboss.com
- * 
- * @version $Revision$
- * @see org.jboss.ha.client.LoadBalancePolicy
- */
-public class RandomRobin implements LoadBalancePolicy
-{
-   // Constants -----------------------------------------------------
-   /** @since 1.1.2.3 */
-   private static final long serialVersionUID = -3599638697906618428L;
-   
-   /** 
-    * <code>Random</code>  used to pick the target.
-    * This needs to be a class variable or else you end up with multiple
-    * Random numbers with the same seed when many clients lookup a proxy.
-    * We make this public so other LoadBalancePolicy implementations can
-    * use it.
-    */
-   public static final Random localRandomizer = new Random (System.currentTimeMillis ());
-
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-       
-    // Public --------------------------------------------------------
-   
-   // LoadBalancePolicy implementation ----------------------------------------------
-
-   public Object chooseTarget (FamilyClusterInfo clusterFamily)
-   {
-      List targets = clusterFamily.getTargets ();
-      int max = targets.size();
-
-      if (max == 0)
-         return null;
-
-      int cursor = localRandomizer.nextInt (max);
-      return targets.get(cursor);
-   }
-
-}

Deleted: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RoundRobin.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RoundRobin.java	2007-11-14 23:27:50 UTC (rev 67102)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/RoundRobin.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -1,84 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt 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.client;
-
-import java.util.List;
-
-
-
-/**
- * LoadBalancingPolicy implementation that always favors the next available
- * target in the list, ensuring maximum load balancing always occurs.
- * <p>
- * Different instances of this class will coordinate their target
- * selection via the 
- * {@link FamilyClusterInfo#getCursor() FamilyClusterInfo cursor}, so if
- * proxy A makes the first call to target 1, and proxy B makes the next 
- * call, it will invoke on target 2; the third call will go to
- * target 3 no matter which proxy makes it, and so on. 
- * </p>
- *
- * @see org.jboss.ha.client.LoadBalancePolicy
- * @see org.jboss.ha.client.FamilyClusterInfo#getCursor()
- *
- * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
- * @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>.
- * @version $Revision$
- */
-public class RoundRobin implements LoadBalancePolicy
-{
-   // Constants -----------------------------------------------------
-   /** @since 1.3.4.2 */
-   private static final long serialVersionUID = 8660076707279597114L;
-
-   // Attributes ----------------------------------------------------
-   
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-       
-   // Public --------------------------------------------------------
-   
-   public Object chooseTarget (FamilyClusterInfo clusterFamily)
-   {
-      int cursor = clusterFamily.getCursor ();
-      List targets = clusterFamily.getTargets ();
-
-      if (targets.size () == 0)
-         return null;
-      
-      if (cursor == FamilyClusterInfo.UNINITIALIZED_CURSOR)
-      {         
-         // Obtain a random index into targets
-         cursor = RandomRobin.localRandomizer.nextInt(targets.size());
-      }
-      else
-      {
-         // Choose the next target
-         cursor = ( (cursor + 1) % targets.size() );
-      }
-      clusterFamily.setCursor (cursor);
-
-      return targets.get(cursor);
-   }
-
-}

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/AopLoadBalancePolicy.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/AopLoadBalancePolicy.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/AopLoadBalancePolicy.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.client.loadbalance;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+/**
+ * Extends the {@link LoadBalancePolicy parent interface}
+ * by adding support for passing in an AOP {@link Invocation}
+ * as an aid in making the choice of targets. 
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AopLoadBalancePolicy extends LoadBalancePolicy
+{
+   /**
+    * Called when the stub wishes to know on which node the next invocation must
+    * be performed.
+    * @param clusterFamily A list of potential target nodes
+    * @param routingDecision The actual invocation object if the policy wants
+    * to have some kind of invocation-based routing strategy
+    * @return The selected target for the next invocation
+    */   
+   public Object chooseTarget (FamilyClusterInfo clusterFamily, Invocation routingDecision);
+
+}

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailable.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailable.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailable.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.client.loadbalance;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+
+/**
+ * LoadBalancePolicy implementation that, once a target is chosen, always favors 
+ * that same target; i.e. no further load balancing occurs. Useful in cases where
+ * "sticky session" behavior is desired. Initially the favored 
+ * target is randomly selected, so different instances of this class
+ * will likely not all select the same target; thus load balancing does occur
+ * across different proxies. Favoring the same target does not 
+ * mean that fail-over will not occur if the chosen target dies. In this case, 
+ * fail-over will occur, and a new favored target will be randomly chosen and 
+ * invocation will continously be invoked on this new target until its death.
+ * <p> 
+ * Each proxy using this policy will choose its own
+ * preferred target: the target is not shared accross the proxy family. For 
+ * shared behaviour please take a look at 
+ * {@link FirstAvailableIdenticalAllProxies}.
+ * </p>
+ * 
+ * @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 brian.stansberry at jboss.com
+ * 
+ * @version $Revision: 57642 $
+ * 
+ * @see org.jboss.ha.client.LoadBalancePolicy
+ */
+
+public class FirstAvailable implements LoadBalancePolicy
+{
+   // Constants -----------------------------------------------------
+   
+   private static final long serialVersionUID = 2008524502721775114L;
+
+   // Attributes ----------------------------------------------------
+   
+   private Object electedTarget = null;
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+       
+    // Public --------------------------------------------------------
+
+   public Object chooseTarget (FamilyClusterInfo clusterFamily)
+   {
+      List targets = clusterFamily.getTargets ();
+      if (targets.size () == 0)
+         return null;
+
+      if ( (this.electedTarget != null) && targets.contains (this.electedTarget) )
+      {
+         return this.electedTarget;
+      }
+      else
+      {
+         int cursor = RandomRobin.localRandomizer.nextInt(targets.size());
+         this.electedTarget = targets.get(cursor);
+         return this.electedTarget;
+      }
+   }
+}


Property changes on: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailable.java
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailableIdenticalAllProxies.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailableIdenticalAllProxies.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailableIdenticalAllProxies.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.client.loadbalance;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+
+/**
+ * Extends the "sticky session" behavior of {@link FirstAvailable} by caching 
+ * the favored target in the {@link FamilyClusterInfo}, thus allowing different 
+ * proxies for the same family to use the same favored target.
+ * <p>
+ * See {@link FirstAvailable} for the basic behavior.
+ * </p>
+ * 
+ * @see org.jboss.ha.client.LoadBalancePolicy
+ * @see org.jboss.ha.client.FamilyClusterInfo#getObject()
+ *
+ * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author brian.stansberry at jboss.com
+ * 
+ * @version $Revision: 57642 $
+ */
+public class FirstAvailableIdenticalAllProxies implements LoadBalancePolicy
+{
+   // Constants -----------------------------------------------------
+   private static final long serialVersionUID = 2910756623413400467L;
+
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+       
+    // Public --------------------------------------------------------
+
+   public Object chooseTarget (FamilyClusterInfo clusterFamily)
+   {
+      Object target = clusterFamily.getObject ();
+      List targets = clusterFamily.getTargets ();
+
+      if (targets.size () == 0)
+         return null;
+      
+      if (target != null && targets.contains (target) )
+      {
+         return target;
+      }
+      else
+      {
+         int cursor = RandomRobin.localRandomizer.nextInt (targets.size());
+         target = targets.get(cursor);
+         clusterFamily.setObject (target);
+         return target;
+      }   
+   }
+
+}


Property changes on: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/FirstAvailableIdenticalAllProxies.java
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/LoadBalancePolicy.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/LoadBalancePolicy.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/LoadBalancePolicy.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.client.loadbalance;
+
+import java.io.Serializable;
+
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+/**
+ * Base interface for load-balancing policies. It is possible to implement many
+ * different load-balancing policies by implementing this simple interface and
+ * using it in the different clustered services (home interface of SLSB for
+ * example)
+ *
+ * @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 brian.stansberry at jboss.com
+ * 
+ * @version $Revision: 57642 $
+ */
+public interface LoadBalancePolicy extends Serializable
+{
+   /** The serialVersionUID
+    * @since 1.3.4.2
+    */ 
+   static final long serialVersionUID = -5071668971774090555L;
+
+   /**
+    * Gets the target for the next remote call.
+    * <p>
+    * Called when the client wishes to know on which node the next invocation must
+    * be performed.
+    * </p>
+    * 
+    * @param clusterFamily object encapsulating a list of potential target nodes
+    * @return The selected target for the next invocation
+    */   
+   public Object chooseTarget (FamilyClusterInfo clusterFamily);
+}


Property changes on: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/LoadBalancePolicy.java
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RandomRobin.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RandomRobin.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RandomRobin.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,76 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.client.loadbalance;
+
+import java.util.List;
+import java.util.Random;
+
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+
+/**
+ * LoadBalancePolicy implementation that always fully randomly selects its target
+ * (without basing its decision on any history).
+ *
+ * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author brian.stansberry at jboss.com
+ * 
+ * @version $Revision: 57642 $
+ * @see org.jboss.ha.client.LoadBalancePolicy
+ */
+public class RandomRobin implements LoadBalancePolicy
+{
+   // Constants -----------------------------------------------------
+   /** @since 1.1.2.3 */
+   private static final long serialVersionUID = -3599638697906618428L;
+   
+   /** 
+    * <code>Random</code>  used to pick the target.
+    * This needs to be a class variable or else you end up with multiple
+    * Random numbers with the same seed when many clients lookup a proxy.
+    * We make this public so other LoadBalancePolicy implementations can
+    * use it.
+    */
+   public static final Random localRandomizer = new Random (System.currentTimeMillis ());
+
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+       
+    // Public --------------------------------------------------------
+   
+   // LoadBalancePolicy implementation ----------------------------------------------
+
+   public Object chooseTarget (FamilyClusterInfo clusterFamily)
+   {
+      List targets = clusterFamily.getTargets ();
+      int max = targets.size();
+
+      if (max == 0)
+         return null;
+
+      int cursor = localRandomizer.nextInt (max);
+      return targets.get(cursor);
+   }
+
+}


Property changes on: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RandomRobin.java
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RoundRobin.java
===================================================================
--- projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RoundRobin.java	                        (rev 0)
+++ projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RoundRobin.java	2007-11-14 23:33:39 UTC (rev 67103)
@@ -0,0 +1,86 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.client.loadbalance;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+
+
+
+/**
+ * LoadBalancePolicy implementation that always favors the next available
+ * target in the list, ensuring maximum load balancing always occurs.
+ * <p>
+ * Different instances of this class will coordinate their target
+ * selection via the 
+ * {@link FamilyClusterInfo#getCursor() FamilyClusterInfo cursor}, so if
+ * proxy A makes the first call to target 1, and proxy B makes the next 
+ * call, it will invoke on target 2; the third call will go to
+ * target 3 no matter which proxy makes it, and so on. 
+ * </p>
+ *
+ * @see org.jboss.ha.client.LoadBalancePolicy
+ * @see org.jboss.ha.client.FamilyClusterInfo#getCursor()
+ *
+ * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>.
+ * @version $Revision: 57642 $
+ */
+public class RoundRobin implements LoadBalancePolicy
+{
+   // Constants -----------------------------------------------------
+   /** @since 1.3.4.2 */
+   private static final long serialVersionUID = 8660076707279597114L;
+
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+       
+   // Public --------------------------------------------------------
+   
+   public Object chooseTarget (FamilyClusterInfo clusterFamily)
+   {
+      int cursor = clusterFamily.getCursor ();
+      List targets = clusterFamily.getTargets ();
+
+      if (targets.size () == 0)
+         return null;
+      
+      if (cursor == FamilyClusterInfo.UNINITIALIZED_CURSOR)
+      {         
+         // Obtain a random index into targets
+         cursor = RandomRobin.localRandomizer.nextInt(targets.size());
+      }
+      else
+      {
+         // Choose the next target
+         cursor = ( (cursor + 1) % targets.size() );
+      }
+      clusterFamily.setCursor (cursor);
+
+      return targets.get(cursor);
+   }
+
+}


Property changes on: projects/cluster/trunk/ha-client/src/main/java/org/jboss/ha/client/loadbalance/RoundRobin.java
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list