1 22 package org.jboss.ha.framework.interfaces; 23 24 import java.util.List ; 25 26 import org.jboss.invocation.Invocation; 27 28 38 public class RoundRobin implements LoadBalancePolicy 39 { 40 42 private static final long serialVersionUID = 8660076707279597114L; 43 44 46 48 50 52 public void init (HARMIClient father) 53 { 54 } 56 57 public Object chooseTarget (FamilyClusterInfo clusterFamily) 58 { 59 return this.chooseTarget(clusterFamily, null); 60 } 61 public Object chooseTarget (FamilyClusterInfo clusterFamily, Invocation routingDecision) 62 { 63 int cursor = clusterFamily.getCursor (); 64 List targets = clusterFamily.getTargets (); 65 66 if (targets.size () == 0) 67 return null; 68 69 if (cursor == FamilyClusterInfo.UNINITIALIZED_CURSOR) 70 { 71 cursor = RandomRobin.localRandomizer.nextInt(targets.size()); 73 } 74 else 75 { 76 cursor = ( (cursor + 1) % targets.size() ); 78 } 79 clusterFamily.setCursor (cursor); 80 81 return targets.get(cursor); 82 } 83 84 } 85 | Popular Tags |