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 22 public class MinAvgSchedulerService 23 extends AbstractScheduler implements MinAvgSchedulerServiceMBean { 24 25 private int index = 0; 26 private MinAvgHostComparator comparator=new MinAvgHostComparator(); 27 28 public MinAvgSchedulerService() { 29 } 30 31 protected Host getNextHost() { 32 Host host = null; 33 try 34 { 35 synchronized (this) 36 { 37 host=(Host)Collections.min(hostsUp, comparator); 38 } 39 } 40 catch (NoSuchElementException nsee) 41 { 42 return null; 43 } 44 return host; 45 } 46 } 47 48 class MinAvgHostComparator implements Comparator 49 { 50 public int compare(Object o1, Object o2) 51 { 52 Host h1=(Host)o1; 53 Host h2=(Host)o2; 54 55 return (h1.getStatistics().getAvgResponseTime()-h2.getStatistics().getAvgResponseTime()); 56 } 57 } 58 | Popular Tags |