1 7 package org.jboss.web.loadbalancer.scheduler; 8 9 import java.net.URL ; 10 import java.util.Comparator ; 11 import java.util.Collections ; 12 import java.util.NoSuchElementException ; 13 14 25 public class WeightedLeastConnectionSchedulerService 26 extends AbstractScheduler implements WeightedLeastConnectionSchedulerServiceMBean { 27 28 private int index = 0; 29 private WeightedLeastConnectionComparator comparator=new WeightedLeastConnectionComparator(); 30 31 public WeightedLeastConnectionSchedulerService() { 32 } 33 34 protected Host getNextHost() { 35 Host host = null; 36 try 37 { 38 synchronized (this) 39 { 40 host=(Host)Collections.min(hostsUp, comparator); 41 } 42 } 43 catch (NoSuchElementException nsee) 44 { 45 return null; 46 } 47 return host; 48 } 49 } 50 51 class WeightedLeastConnectionComparator implements Comparator 52 { 53 public int compare(Object o1, Object o2) 54 { 55 Host h1=(Host)o1; 56 Host h2=(Host)o2; 57 58 return ((h1.getCurrentConnections()/h1.getLbFactor())-(h2.getCurrentConnections()/h2.getLbFactor())); 59 } 60 } 61 | Popular Tags |