1 22 package fr.dyade.aaa.agent.conf; 23 24 import java.io.*; 25 import java.util.*; 26 27 import org.objectweb.util.monolog.api.BasicLevel; 28 import org.objectweb.util.monolog.api.Logger; 29 30 public class A3CMLCluster implements Serializable { 31 32 public short sid = -1; 33 public String name = null; 34 public String jvmArgs = null; 35 public Hashtable servers = null; 36 public Hashtable properties = null; 37 38 public A3CMLCluster(short sid, 39 String name) throws Exception { 40 this.sid = sid; 41 this.name = name; 42 this.properties = new Hashtable(); 43 this.servers = new Hashtable(); 44 } 45 46 53 public final void addServer(A3CMLServer server) throws DuplicateServerException { 54 Short id = new Short (server.sid); 55 if (servers.containsKey(id)) 56 throw new DuplicateServerException("Duplicate server id. #" + server.sid); 57 server.name = "cluster_" + sid + "_" + server.sid; 58 server.sid = sid; 59 servers.put(id, server); 60 } 61 62 70 public final A3CMLServer removeServer(short sid) throws UnknownServerException { 71 A3CMLServer server = null; 72 Short id = new Short (sid); 73 if (servers.containsKey(id)) 74 server = (A3CMLServer) servers.remove(id); 75 else 76 throw new UnknownServerException("Unknown server id. #" + sid); 77 return server; 78 } 79 80 88 public final A3CMLServer removeServer(String name) throws UnknownServerException { 89 return removeServer(getServerIdByName(name)); 90 } 91 92 98 public final boolean containsServer(short sid) { 99 return servers.containsKey(new Short (sid)); 100 } 101 102 110 public short getServerIdByName(String name) throws UnknownServerException { 111 for (Enumeration s = servers.elements(); s.hasMoreElements(); ) { 112 A3CMLServer server = (A3CMLServer) s.nextElement(); 113 if (server.name.equals(name)) return server.sid; 114 } 115 throw new UnknownServerException("Unknown server " + name); 116 } 117 118 124 public final boolean containsServer(String name) { 125 try { 126 getServerIdByName(name); 127 } catch (UnknownServerException exc) { 128 return false; 129 } 130 return true; 131 } 132 133 141 public final A3CMLServer getServer(short sid) throws UnknownServerException { 142 A3CMLServer server = (A3CMLServer) servers.get(new Short (sid)); 143 if (server == null) 144 throw new UnknownServerException("Unknown server id. #" + sid); 145 return server; 146 } 147 148 156 public final A3CMLServer getServer(String name) throws UnknownServerException { 157 for (Enumeration s = servers.elements(); s.hasMoreElements(); ) { 158 A3CMLServer server = (A3CMLServer) s.nextElement(); 159 if (server.name.equals(name)) return server; 160 } 161 throw new UnknownServerException("Unknown server id for server " + name); 162 } 163 164 172 public final A3CMLProperty addProperty(A3CMLProperty prop) throws Exception { 173 return (A3CMLProperty) properties.put(prop.name, prop); 174 } 175 176 183 public final A3CMLProperty removeProperty(String name) { 184 return (A3CMLProperty) properties.remove(name); 185 } 186 187 193 public final boolean containsProperty(String name) { 194 return properties.containsKey(name); 195 } 196 197 200 public final A3CMLProperty getProperty(String name) { 201 return (A3CMLProperty) properties.get(name); 202 } 203 204 212 public final String getJvmArgs(short sid) throws UnknownServerException { 213 A3CMLServer server = getServer(sid); 214 return server.getJvmArgs(); 215 } 216 217 225 public final String getJvmArgs(String name) throws UnknownServerException { 226 A3CMLServer server = getServer(name); 227 return server.getJvmArgs(); 228 } 229 230 public String toString() { 231 StringBuffer strBuf = new StringBuffer (); 232 strBuf.append("(").append(super.toString()); 233 strBuf.append(",sid=").append(sid); 234 strBuf.append(",name=").append(name); 235 strBuf.append(",jvmArgs=").append(jvmArgs); 236 strBuf.append(",properties=").append(properties); 237 strBuf.append(",servers=").append(servers); 238 strBuf.append(")"); 239 240 return strBuf.toString(); 241 } 242 243 public boolean equals(Object obj) { 244 if (obj == null) return false; 245 246 if (obj instanceof A3CMLCluster) { 247 A3CMLCluster cluster = (A3CMLCluster) obj; 248 249 if (sid == cluster.sid && 250 name.equals(cluster.name) && 251 servers.equals(cluster.servers) && 252 properties.equals(cluster.properties)) 253 return true; 254 } 255 return false; 256 } 257 } 258 | Popular Tags |