KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > loadbalancer > LoadbalancerService


1 /*
2  * JBoss, the OpenSource WebOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.web.loadbalancer;
8
9 import java.io.IOException JavaDoc;
10 import javax.management.ObjectName JavaDoc;
11 import javax.servlet.ServletException JavaDoc;
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 JavaDoc;
19
20 /**
21  *
22  * @jmx:mbean name="jboss.web.loadbalancer: service=Loadbalancer"
23  * extends="org.jboss.system.ServiceMBean"
24  *
25  * @author Thomas Peuss <jboss@peuss.de>
26  * @version $Revision: 1.4 $
27  */

28 public class LoadbalancerService
29     extends ServiceMBeanSupport
30     implements LoadbalancerServiceMBean
31 {
32   protected Element JavaDoc config;
33   protected Loadbalancer loadbalancer;
34   protected ObjectName JavaDoc schedulerObjectName;
35   protected SchedulerMBean scheduler;
36   protected int timeout = 20000;
37
38   protected void startService() throws java.lang.Exception JavaDoc
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 JavaDoc
47   {
48     loadbalancer = null;
49   }
50
51   /**
52    * Set the scheduler for this Loadbalancer.
53    * @jmx:managed-attribute
54    * @param schedulerObjectName
55    */

56   public void setScheduler(ObjectName JavaDoc schedulerObjectName)
57   {
58     this.schedulerObjectName = schedulerObjectName;
59   }
60
61   /**
62    * Get the scheduler for this Loadbalancer.
63    * @jmx:managed-attribute
64    */

65   public ObjectName JavaDoc getScheduler()
66   {
67     return schedulerObjectName;
68   }
69
70   /**
71    * Get the currently used connection timeout to slave hosts.
72    * @jmx:managed-attribute
73    */

74   public int getConnectionTimeout()
75   {
76     return timeout;
77   }
78
79   /**
80    * Set the currently used connection timeout to slave hosts.
81    * @jmx:managed-attribute
82    */

83   public void setConnectionTimeout(int newTimeout)
84   {
85     this.timeout = newTimeout;
86     if (loadbalancer != null)
87     {
88       loadbalancer.setConnectionTimeout(newTimeout);
89     }
90   }
91
92   /**
93    * Get the currently used connections to slave hosts.
94    * @jmx:managed-attribute
95    */

96   public int getConnectionsInUse()
97   {
98     return loadbalancer.getConnectionsInUse();
99   }
100
101   /**
102    * @jmx:managed-operation
103    */

104   public void createMethod(Request schedRequest) throws NoHostAvailableException
105   {
106     loadbalancer.createMethod(schedRequest);
107   }
108
109   /**
110    * @jmx:managed-operation
111    */

112   public void addRequestData(Request schedRequest)
113   {
114     loadbalancer.addRequestData(schedRequest);
115   }
116
117   /**
118    * @jmx:managed-operation
119    */

120   public void handleRequest(Request schedRequest) throws ServletException JavaDoc, IOException JavaDoc
121   {
122     loadbalancer.handleRequest(schedRequest);
123   }
124 }
Popular Tags