1 7 package org.jboss.web.loadbalancer; 8 9 import java.io.IOException ; 10 import javax.management.ObjectName ; 11 import javax.servlet.ServletException ; 12 13 import org.jboss.mx.util.MBeanProxyExt; 14 import org.jboss.system.ServiceMBeanSupport; 15 import org.jboss.web.loadbalancer.scheduler.NoHostAvailableException; 16 import org.jboss.web.loadbalancer.scheduler.SchedulerMBean; 17 import org.jboss.web.loadbalancer.util.Request; 18 import org.w3c.dom.Element ; 19 20 28 public class LoadbalancerService 29 extends ServiceMBeanSupport 30 implements LoadbalancerServiceMBean 31 { 32 protected Element config; 33 protected Loadbalancer loadbalancer; 34 protected ObjectName schedulerObjectName; 35 protected SchedulerMBean scheduler; 36 protected int timeout = 20000; 37 38 protected void startService() throws java.lang.Exception 39 { 40 scheduler = (SchedulerMBean) 41 MBeanProxyExt.create(SchedulerMBean.class, 42 schedulerObjectName); 43 loadbalancer = new Loadbalancer(scheduler, timeout); 44 } 45 46 protected void destroyService() throws java.lang.Exception 47 { 48 loadbalancer = null; 49 } 50 51 56 public void setScheduler(ObjectName schedulerObjectName) 57 { 58 this.schedulerObjectName = schedulerObjectName; 59 } 60 61 65 public ObjectName getScheduler() 66 { 67 return schedulerObjectName; 68 } 69 70 74 public int getConnectionTimeout() 75 { 76 return timeout; 77 } 78 79 83 public void setConnectionTimeout(int newTimeout) 84 { 85 this.timeout = newTimeout; 86 if (loadbalancer != null) 87 { 88 loadbalancer.setConnectionTimeout(newTimeout); 89 } 90 } 91 92 96 public int getConnectionsInUse() 97 { 98 return loadbalancer.getConnectionsInUse(); 99 } 100 101 104 public void createMethod(Request schedRequest) throws NoHostAvailableException 105 { 106 loadbalancer.createMethod(schedRequest); 107 } 108 109 112 public void addRequestData(Request schedRequest) 113 { 114 loadbalancer.addRequestData(schedRequest); 115 } 116 117 120 public void handleRequest(Request schedRequest) throws ServletException , IOException 121 { 122 loadbalancer.handleRequest(schedRequest); 123 } 124 } | Popular Tags |