package org.jboss.web.loadbalancer.scheduler;
import java.net.URL;
import java.util.Comparator;
import java.util.Collections;
import java.util.NoSuchElementException;
public class WeightedLeastConnectionSchedulerService
extends AbstractScheduler implements WeightedLeastConnectionSchedulerServiceMBean {
private int index = 0;
private WeightedLeastConnectionComparator comparator=new WeightedLeastConnectionComparator();
public WeightedLeastConnectionSchedulerService() {
}
protected Host getNextHost() {
Host host = null;
try
{
synchronized (this)
{
host=(Host)Collections.min(hostsUp, comparator);
}
}
catch (NoSuchElementException nsee)
{
return null;
}
return host;
}
}
class WeightedLeastConnectionComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
Host h1=(Host)o1;
Host h2=(Host)o2;
return ((h1.getCurrentConnections()/h1.getLbFactor())-(h2.getCurrentConnections()/h2.getLbFactor()));
}
}