1 22 package org.jboss.ha.framework.interfaces; 23 24 import java.util.List ; 25 26 import org.jboss.invocation.Invocation; 27 28 55 56 public class FirstAvailable implements LoadBalancePolicy 57 { 58 private static final long serialVersionUID = 2008524502721775114L; 60 61 63 protected transient Object electedTarget = null; 64 65 67 69 71 public void init (HARMIClient father) 72 { 73 } 75 76 public Object chooseTarget (FamilyClusterInfo clusterFamily) 77 { 78 return chooseTarget(clusterFamily, null); 79 } 80 81 public Object chooseTarget (FamilyClusterInfo clusterFamily, Invocation routingDecision) 82 { 83 List targets = clusterFamily.getTargets (); 84 if (targets.size () == 0) 85 return null; 86 87 if ( (this.electedTarget != null) && targets.contains (this.electedTarget) ) 88 { 89 return this.electedTarget; 90 } 91 else 92 { 93 int cursor = RandomRobin.localRandomizer.nextInt(targets.size()); 94 this.electedTarget = targets.get(cursor); 95 return this.electedTarget; 96 } 97 } 98 } 99 | Popular Tags |