1 package org.jacorb.imr; 2 3 22 23 import java.util.*; 24 import java.io.*; 25 import org.jacorb.imr.RegistrationPackage.*; 26 import org.jacorb.imr.AdminPackage.*; 27 28 39 40 public class ServerTable 41 implements Serializable 42 { 43 private Hashtable servers; 44 private transient ResourceLock servers_lock; 45 private Hashtable poas; 46 private transient ResourceLock poas_lock; 47 private Hashtable hosts; 48 private transient ResourceLock hosts_lock; 49 50 public transient ResourceLock table_lock; 51 52 public ServerTable() 53 { 54 servers = new Hashtable(); 55 poas = new Hashtable(); 56 hosts = new Hashtable(); 57 58 initTransient(); 59 } 60 61 64 65 private void initTransient() 66 { 67 table_lock = new ResourceLock(); 77 78 servers_lock = new ResourceLock(); 84 poas_lock = new ResourceLock(); 85 hosts_lock = new ResourceLock(); 86 } 87 88 95 96 public boolean hasServer( String name ) 97 { 98 return servers.containsKey(name); 99 } 100 101 102 110 111 public ImRServerInfo getServer(String name) 112 throws UnknownServerName 113 { 114 ImRServerInfo _tmp = (ImRServerInfo) servers.get(name); 115 if (_tmp == null) 116 throw new UnknownServerName(name); 117 118 return _tmp; 119 } 120 121 129 130 public void putServer(String name, ImRServerInfo server) 131 throws DuplicateServerName 132 { 133 if (servers.containsKey(name)) 134 throw new DuplicateServerName(name); 135 136 table_lock.gainSharedLock(); 137 servers_lock.gainSharedLock(); 138 139 servers.put(name, server); 140 141 servers_lock.releaseSharedLock(); 142 table_lock.releaseSharedLock(); 143 } 144 145 152 153 public void removeServer(String name) 154 throws UnknownServerName 155 { 156 table_lock.gainSharedLock(); 157 servers_lock.gainSharedLock(); 158 159 Object _obj = servers.remove(name); 160 161 servers_lock.releaseSharedLock(); 162 table_lock.releaseSharedLock(); 163 164 if (_obj == null) 165 throw new UnknownServerName(name); 166 } 167 168 175 176 public ImRPOAInfo getPOA (String name) 177 { 178 return (ImRPOAInfo) poas.get(name); 179 } 180 181 187 188 public void putPOA(String name, ImRPOAInfo poa) 189 { 190 table_lock.gainSharedLock(); 191 poas_lock.gainSharedLock(); 192 193 poas.put(name, poa); 194 195 poas_lock.releaseSharedLock(); 196 table_lock.releaseSharedLock(); 197 } 198 199 204 205 public void removePOA(String name) 206 { 207 table_lock.gainSharedLock(); 208 poas_lock.gainSharedLock(); 209 210 poas.remove(name); 211 212 poas_lock.releaseSharedLock(); 213 table_lock.releaseSharedLock(); 214 } 215 216 222 223 public ServerInfo[] getServers() 224 { 225 table_lock.gainSharedLock(); 226 servers_lock.gainExclusiveLock(); 227 228 ServerInfo[] _servers = new ServerInfo[servers.size()]; 230 Enumeration _server_enum = servers.elements(); 231 232 int _i = 0; 234 while (_server_enum.hasMoreElements()) 235 _servers[_i++] = ((ImRServerInfo) _server_enum.nextElement()).toServerInfo(); 236 237 servers_lock.releaseExclusiveLock(); 238 table_lock.releaseSharedLock(); 239 240 return _servers; 241 } 242 243 249 250 public HostInfo[] getHosts() 251 { 252 table_lock.gainSharedLock(); 253 hosts_lock.gainExclusiveLock(); 254 255 HostInfo[] _hosts = new HostInfo[hosts.size()]; 257 Enumeration _host_enum = hosts.elements(); 258 259 int _i = 0; 261 while (_host_enum.hasMoreElements()) 262 _hosts[_i++] = ((ImRHostInfo) _host_enum.nextElement()).toHostInfo(); 263 264 hosts_lock.releaseExclusiveLock(); 265 table_lock.releaseSharedLock(); 266 267 return _hosts; 268 } 269 270 276 277 public POAInfo[] getPOAs() 278 { 279 table_lock.gainSharedLock(); 280 poas_lock.gainExclusiveLock(); 281 282 POAInfo[] _poas = new POAInfo[poas.size()]; 284 Enumeration _poa_enum = poas.elements(); 285 286 int _i = 0; 288 while (_poa_enum.hasMoreElements()) 289 _poas[_i++] = ((ImRPOAInfo) _poa_enum.nextElement()).toPOAInfo(); 290 291 poas_lock.releaseExclusiveLock(); 292 table_lock.releaseSharedLock(); 293 294 return _poas; 295 } 296 297 304 305 public void putHost(String name, ImRHostInfo host) 306 { 307 table_lock.gainSharedLock(); 308 hosts_lock.gainSharedLock(); 309 310 hosts.put(name, host); 311 312 hosts_lock.releaseSharedLock(); 313 table_lock.releaseSharedLock(); 314 } 315 316 321 322 public Object removeHost(String name) 323 { 324 return hosts.remove(name); 325 } 326 327 334 335 public ImRHostInfo getHost(String name) 336 { 337 return (ImRHostInfo) hosts.get(name); 338 } 339 340 344 345 private void readObject(java.io.ObjectInputStream in) 346 throws java.io.IOException , java.io.NotActiveException , 347 ClassNotFoundException 348 { 349 in.defaultReadObject(); 350 initTransient(); 351 } 352 } 354 355 | Popular Tags |