| 1 package org.sapia.ubik.rmi.naming.remote.proxy; 2 3 import java.lang.reflect.UndeclaredThrowableException ; 4 import java.rmi.RemoteException ; 5 import java.util.Hashtable ; 6 7 import javax.naming.Context ; 8 import javax.naming.Name ; 9 import javax.naming.NameParser ; 10 import javax.naming.NamingEnumeration ; 11 import javax.naming.NamingException ; 12 13 import org.sapia.archie.jndi.proxy.ContextProxy; 14 import org.sapia.ubik.mcast.DomainName; 15 import org.sapia.ubik.rmi.naming.remote.DomainInfo; 16 import org.sapia.ubik.rmi.naming.remote.RemoteContext; 17 import org.sapia.ubik.rmi.naming.remote.StubTweaker; 18 import org.sapia.ubik.rmi.server.StubContainer; 19 20 21 29 public class LocalContext extends ContextProxy implements java.rmi.Remote { 30 protected DomainName _domainName; 31 protected String _mcastAddress; 32 protected int _mcastPort; 33 protected String _url; 34 35 public LocalContext(String url, RemoteContext remote) throws NamingException { 36 super(remote); 37 _url = url; 38 39 DomainInfo info = remote.getDomainInfo(); 40 _domainName = info.getDomainName(); 41 _mcastAddress = info.getMulticastAddress(); 42 _mcastPort = info.getMulticastPort(); 43 } 44 45 48 public void bind(Name n, Object o) throws NamingException { 49 rebind(n, o); 50 } 51 52 55 public void bind(String n, Object o) throws NamingException { 56 rebind(n, o); 57 } 58 59 62 public void close() throws NamingException { 63 } 64 65 68 public Name composeName(Name n1, Name n2) throws NamingException { 69 try { 70 return super.composeName(n1, n2); 71 } catch (UndeclaredThrowableException e) { 72 doFailOver(e); 73 74 return super.composeName(n1, n2); 75 } 76 } 77 78 81 public String composeName(String n1, String n2) throws NamingException { 82 try { 83 return super.composeName(n1, n2); 84 } catch (UndeclaredThrowableException e) { 85 doFailOver(e); 86 87 return super.composeName(n1, n2); 88 } 89 } 90 91 94 public Context createSubcontext(Name n) throws NamingException { 95 try { 96 return super.createSubcontext(n); 97 } catch (UndeclaredThrowableException e) { 98 doFailOver(e); 99 100 return super.createSubcontext(n); 101 } 102 } 103 104 107 public Context createSubcontext(String name) throws NamingException { 108 try { 109 return super.createSubcontext(name); 110 } catch (UndeclaredThrowableException e) { 111 doFailOver(e); 112 113 return super.createSubcontext(name); 114 } 115 } 116 117 120 public void destroySubcontext(Name n) throws NamingException { 121 try { 122 super.destroySubcontext(n); 123 } catch (UndeclaredThrowableException e) { 124 doFailOver(e); 125 super.destroySubcontext(n); 126 } 127 } 128 129 132 public void destroySubcontext(String name) throws NamingException { 133 try { 134 super.destroySubcontext(name); 135 } catch (UndeclaredThrowableException e) { 136 doFailOver(e); 137 super.destroySubcontext(name); 138 } 139 } 140 141 144 public Hashtable getEnvironment() throws NamingException { 145 try { 146 return super.getEnvironment(); 147 } catch (UndeclaredThrowableException e) { 148 doFailOver(e); 149 150 return super.getEnvironment(); 151 } 152 } 153 154 157 public String getNameInNamespace() throws NamingException { 158 try { 159 return super.getNameInNamespace(); 160 } catch (UndeclaredThrowableException e) { 161 doFailOver(e); 162 163 return super.getNameInNamespace(); 164 } 165 } 166 167 170 public NameParser getNameParser(Name n) throws NamingException { 171 try { 172 return super.getNameParser(n); 173 } catch (UndeclaredThrowableException e) { 174 doFailOver(e); 175 176 return super.getNameParser(n); 177 } 178 } 179 180 183 public NameParser getNameParser(String name) throws NamingException { 184 try { 185 return super.getNameParser(name); 186 } catch (UndeclaredThrowableException e) { 187 doFailOver(e); 188 189 return super.getNameParser(name); 190 } 191 } 192 193 196 public NamingEnumeration list(Name n) throws NamingException { 197 try { 198 return super.list(n); 199 } catch (UndeclaredThrowableException e) { 200 doFailOver(e); 201 202 return super.list(n); 203 } 204 } 205 206 209 public NamingEnumeration list(String name) throws NamingException { 210 try { 211 return super.list(name); 212 } catch (UndeclaredThrowableException e) { 213 doFailOver(e); 214 215 return super.list(name); 216 } 217 } 218 219 222 public NamingEnumeration listBindings(Name n) throws NamingException { 223 try { 224 return super.listBindings(n); 225 } catch (UndeclaredThrowableException e) { 226 doFailOver(e); 227 228 return super.listBindings(n); 229 } 230 } 231 232 235 public NamingEnumeration listBindings(String name) throws NamingException { 236 try { 237 return super.listBindings(name); 238 } catch (UndeclaredThrowableException e) { 239 doFailOver(e); 240 241 return super.listBindings(name); 242 } 243 } 244 245 248 public Object lookup(Name n) throws NamingException { 249 try { 250 return super.lookup(n); 251 } catch (UndeclaredThrowableException e) { 252 doFailOver(e); 253 254 return super.lookup(n); 255 } 256 } 257 258 261 public Object lookup(String name) throws NamingException { 262 try { 263 return super.lookup(name); 264 } catch (UndeclaredThrowableException e) { 265 doFailOver(e); 266 267 return super.lookup(name); 268 } 269 } 270 271 274 public Object lookupLink(Name n) throws NamingException { 275 try { 276 return super.lookupLink(n); 277 } catch (UndeclaredThrowableException e) { 278 doFailOver(e); 279 280 return super.lookupLink(n); 281 } 282 } 283 284 287 public Object lookupLink(String name) throws NamingException { 288 try { 289 return super.lookup(name); 290 } catch (UndeclaredThrowableException e) { 291 doFailOver(e); 292 293 return super.lookup(name); 294 } 295 } 296 297 300 public void rebind(Name n, Object o) throws NamingException { 301 try { 302 super.rebind(n, o); 303 } catch (UndeclaredThrowableException e) { 304 doFailOver(e); 305 super.bind(n, o); 306 } 307 } 308 309 312 public void rebind(String n, Object o) throws NamingException { 313 try { 314 super.rebind(n, o); 315 } catch (UndeclaredThrowableException e) { 316 doFailOver(e); 317 super.rebind(n, o); 318 } 319 } 320 321 324 public Object removeFromEnvironment(String name) throws NamingException { 325 try { 326 return super.removeFromEnvironment(name); 327 } catch (UndeclaredThrowableException e) { 328 doFailOver(e); 329 330 return super.removeFromEnvironment(name); 331 } 332 } 333 334 337 public void rename(Name n1, Name n2) throws NamingException { 338 try { 339 super.rename(n1, n2); 340 } catch (UndeclaredThrowableException e) { 341 doFailOver(e); 342 super.rename(n1, n2); 343 } 344 } 345 346 349 public void rename(String n1, String n2) throws NamingException { 350 try { 351 super.rename(n1, n2); 352 } catch (UndeclaredThrowableException e) { 353 doFailOver(e); 354 super.rename(n1, n2); 355 } 356 } 357 358 361 public void unbind(Name n) throws NamingException { 362 try { 363 super.unbind(n); 364 } catch (UndeclaredThrowableException e) { 365 doFailOver(e); 366 super.unbind(n); 367 } 368 } 369 370 373 public void unbind(String name) throws NamingException { 374 try { 375 super.unbind(name); 376 } catch (UndeclaredThrowableException e) { 377 doFailOver(e); 378 super.unbind(name); 379 } 380 } 381 382 385 protected Object onLookup(Name name, Object obj) throws NamingException { 386 if (obj instanceof StubContainer) { 387 try { 388 return ((StubContainer) obj).toStub(Thread.currentThread() 389 .getContextClassLoader()); 390 } catch (RemoteException e) { 391 NamingException ne = new NamingException ("Could not acquire stub"); 392 ne.setRootCause(e); 393 } 394 } 395 396 return obj; 397 } 398 399 402 protected Object onBind(Name n, Object toBind) throws NamingException { 403 toBind = StubTweaker.tweak(_url, n, _domainName, _mcastAddress, _mcastPort, 404 toBind); 405 return toBind; 406 } 407 408 411 protected Object onRebind(Name n, Object toBind) throws NamingException { 412 return onBind(n, toBind); 413 } 414 415 418 protected NamingEnumeration onEnum(Name n, NamingEnumeration en) { 419 return new LocalNamingEnum(_url, n, en); 420 } 421 422 425 protected Context onSubContext(Name name, Context ctx) 426 throws NamingException { 427 return new LocalContext(_url, (RemoteContext) ctx); 428 } 429 430 protected void doFailOver(UndeclaredThrowableException e) 431 throws NamingException { 432 NamingException ne = new NamingException ("Unavailable naming service for " + 433 _url); 434 ne.setRootCause(e.getUndeclaredThrowable()); 435 } 436 } 437 | Popular Tags |