1 7 package org.jboss.web.loadbalancer.scheduler; 8 9 import java.net.URL ; 10 11 import org.jboss.mx.util.JBossNotificationBroadcasterSupport; 12 import org.jboss.web.loadbalancer.util.Constants; 13 14 21 public class Host extends JBossNotificationBroadcasterSupport implements HostMBean 22 { 23 private URL url; 24 private int lbFactor; 25 private int state=Constants.STATE_NODE_UP; 26 private HostStatistics statistics=new HostStatistics(); 27 28 public Host(URL url) 29 { 30 this.url=url; 31 } 32 33 public String 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 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 77 public int getCurrentConnections() 78 { 79 return statistics.getCurrentConnections(); 80 } 81 82 85 public URL getUrl() 86 { 87 return url; 88 } 89 90 public void setUrl(URL url) 91 { 92 this.url = url; 93 } 94 95 98 public int getLbFactor() 99 { 100 return lbFactor; 101 } 102 103 106 public void setLbFactor(int lbFactor) 107 { 108 this.lbFactor = lbFactor; 109 } 110 111 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 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 143 public String getStateString() 144 { 145 return Constants.STATE_STRINGS[state]; 146 } 147 148 151 public void markNodeUp() 152 { 153 this.setState(Constants.STATE_NODE_UP); 154 } 155 156 159 public void markNodeDown() 160 { 161 this.setState(Constants.STATE_NODE_DOWN); 162 } 163 164 167 public void markNodeForcedDown() 168 { 169 this.setState(Constants.STATE_NODE_FORCED_DOWN); 170 } 171 172 175 public void resetStatistics() 176 { 177 statistics.reset(); 178 } 179 } 180 | Popular Tags |