KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > loadbalancer > scheduler > Host


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.scheduler;
8
9 import java.net.URL JavaDoc;
10
11 import org.jboss.mx.util.JBossNotificationBroadcasterSupport;
12 import org.jboss.web.loadbalancer.util.Constants;
13
14 /**
15  * A class that holds information about a target node.
16  *
17  * @jmx:mbean name="jboss.web.loadbalancer: type=Host"
18  * @author Thomas Peuss <jboss@peuss.de>
19  * @version $Revision: 1.3.6.1 $
20  */

21 public class Host extends JBossNotificationBroadcasterSupport implements HostMBean
22 {
23   private URL JavaDoc url;
24   private int lbFactor;
25   private int state=Constants.STATE_NODE_UP;
26   private HostStatistics statistics=new HostStatistics();
27
28   public Host(URL JavaDoc url)
29   {
30     this.url=url;
31   }
32
33   public String JavaDoc toString()
34   {
35     return "[URL=" + this.getUrl().toExternalForm() + ", State=" + this.getStateString() +
36         ", LbFactor=" + this.getLbFactor() + ", Stats=" + this.getStatistics() + "]";
37   }
38
39   public int hashCode()
40   {
41     return url.hashCode();
42   }
43
44   public boolean equals(Object JavaDoc obj)
45   {
46     if (obj==null)
47     {
48       return false;
49     }
50
51     if (!(obj instanceof Host))
52     {
53       return false;
54     }
55
56     return (this.hashCode()==obj.hashCode());
57   }
58
59   public void addRequest(int responseTime)
60   {
61     statistics.addRequest(responseTime);
62   }
63
64   public void incCurrentConnections()
65   {
66     statistics.incCurrentConnections();
67   }
68
69   public void decCurrentConnections()
70   {
71     statistics.decCurrentConnections();
72   }
73
74   /**
75    * @jmx:managed-attribute
76    */

77   public int getCurrentConnections()
78   {
79     return statistics.getCurrentConnections();
80   }
81
82   /**
83    * @jmx:managed-attribute
84    */

85   public URL JavaDoc getUrl()
86   {
87     return url;
88   }
89
90   public void setUrl(URL JavaDoc url)
91   {
92     this.url = url;
93   }
94
95   /**
96    * @jmx:managed-attribute
97    */

98   public int getLbFactor()
99   {
100     return lbFactor;
101   }
102
103   /**
104    * @jmx:managed-attribute
105    */

106   public void setLbFactor(int lbFactor)
107   {
108     this.lbFactor = lbFactor;
109   }
110
111   /**
112    * @jmx:managed-attribute
113    */

114   public HostStatistics getStatistics()
115   {
116     return statistics;
117   }
118
119   public void setStatistics(HostStatistics statistics)
120   {
121     this.statistics = statistics;
122   }
123
124
125   /**
126    * @jmx:managed-attribute
127    * @return
128    */

129   public int getState()
130   {
131     return state;
132   }
133
134   public void setState(int state)
135   {
136     this.state = state;
137     this.sendNotification(new HostStateChangedNotification(this, "Host: "+this+". State changed to "+this.getStateString()));
138   }
139
140   /**
141    * @jmx:managed-attribute
142    */

143   public String JavaDoc getStateString()
144   {
145     return Constants.STATE_STRINGS[state];
146   }
147
148   /**
149    * @jmx:managed-operation
150    */

151   public void markNodeUp()
152   {
153     this.setState(Constants.STATE_NODE_UP);
154   }
155
156   /**
157    * @jmx:managed-operation
158    */

159   public void markNodeDown()
160   {
161     this.setState(Constants.STATE_NODE_DOWN);
162   }
163
164   /**
165    * @jmx:managed-operation
166    */

167   public void markNodeForcedDown()
168   {
169     this.setState(Constants.STATE_NODE_FORCED_DOWN);
170   }
171
172   /**
173    * @jmx:managed-operation
174    */

175   public void resetStatistics()
176   {
177     statistics.reset();
178   }
179 }
180
Popular Tags