1 25 package fr.dyade.aaa.agent; 26 27 import java.io.*; 28 import java.net.InetAddress ; 29 import java.util.Vector ; 30 import java.util.Enumeration ; 31 32 import fr.dyade.aaa.util.Strings; 33 import fr.dyade.aaa.util.SocketAddress; 34 35 41 public final class ServerDesc implements Serializable { 42 43 short sid; 44 45 String name; 46 56 private Vector sockAddrs = null; 57 60 transient ServiceDesc[] services = null; 61 65 short gateway = -1; 66 69 transient MessageConsumer domain = null; 70 71 72 transient volatile boolean active = true; 73 74 transient volatile long last = 0L; 75 76 transient volatile int retry = 0; 77 78 85 public ServerDesc(short sid, 86 String name, 87 String hostname, 88 int port) { 89 this.sid = sid; 90 this.name = name; 91 sockAddrs = new Vector (); 92 sockAddrs.addElement(new SocketAddress(hostname,port)); 93 } 94 95 100 public short getServerId() { 101 return sid; 102 } 103 104 109 public String getServerName() { 110 return name; 111 } 112 113 118 public String getHostname() { 119 return ((SocketAddress) sockAddrs.firstElement()).getHostname(); 120 } 121 122 127 public int getPort() { 128 return ((SocketAddress) sockAddrs.firstElement()).getPort(); 129 } 130 131 136 public InetAddress getAddr() { 137 return ((SocketAddress) sockAddrs.firstElement()).getAddress(); 138 } 139 140 146 public InetAddress resetAddr() { 147 ((SocketAddress) sockAddrs.firstElement()).resetAddr(); 148 return getAddr(); 149 } 150 151 void addSockAddr(String hostname, int port) { 152 sockAddrs.addElement(new SocketAddress(hostname, port)); 153 } 154 155 void updateSockAddr(String hostname, int port) { 156 sockAddrs.remove(0); 157 sockAddrs.insertElementAt(new SocketAddress(hostname,port), 0); 158 } 159 160 164 void moveToFirst(SocketAddress addr) { 165 if (sockAddrs.indexOf(addr) > 0) { 166 if (sockAddrs.remove(addr)) 167 sockAddrs.insertElementAt(addr,0); 168 } 169 } 170 171 175 Enumeration getSockAddrs() { 176 return sockAddrs.elements(); 177 } 178 179 184 public ServiceDesc[] getServices() { 185 return services; 186 } 187 188 public short getGateway() { 189 return gateway; 190 } 191 192 public String getDomainName() { 193 return domain.getDomainName(); 194 } 195 196 197 public Class getDomainType() { 198 return domain.getClass(); 199 } 200 201 206 public String toString() { 207 StringBuffer strBuf = new StringBuffer (); 208 strBuf.append("(").append(super.toString()); 209 strBuf.append(",sid=").append(sid); 210 strBuf.append(",name=").append(name); 211 strBuf.append(",services="); 212 Strings.toString(strBuf, services); 213 strBuf.append(",active=").append(active); 214 strBuf.append(",last=").append(last); 215 strBuf.append(",gateway=").append(gateway); 216 strBuf.append(",sockAddrs=").append(sockAddrs); 217 strBuf.append(",domain=").append(domain); 218 strBuf.append(")"); 219 return strBuf.toString(); 220 } 221 } 222 | Popular Tags |