1 package org.sapia.ubik.rmi.naming.remote.archie; 2 3 import org.sapia.archie.Entry; 4 import org.sapia.archie.NamePart; 5 import org.sapia.archie.ProcessingException; 6 import org.sapia.archie.impl.AttributeNode; 7 import org.sapia.archie.impl.Offer; 8 import org.sapia.archie.sync.SynchronizedNode; 9 10 import org.sapia.ubik.rmi.naming.remote.StubTweaker; 11 import org.sapia.ubik.rmi.server.HealthCheck; 12 import org.sapia.ubik.rmi.server.Stub; 13 14 import java.lang.reflect.InvocationHandler ; 15 import java.lang.reflect.Proxy ; 16 17 import java.rmi.Remote ; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 25 33 public class UbikSyncNode extends SynchronizedNode implements java.rmi.Remote { 34 public UbikSyncNode(UbikNodeFactory fac) throws ProcessingException { 35 super(new UbikReliableNode(fac)); 36 } 37 38 static final class UbikReliableNode extends AttributeNode implements Remote { 39 public UbikReliableNode(UbikNodeFactory fac) throws ProcessingException { 40 super(new HashMap (), new HashMap (), fac); 41 } 42 43 46 protected Object onWrite(NamePart name, Object obj) { 47 Iterator itr = getEntries(); 48 List entries = new ArrayList (); 49 Entry entry; 50 51 while (itr.hasNext()) { 52 entry = (Entry) itr.next(); 53 entries.add(entry.getValue()); 54 } 55 56 return StubTweaker.tweak(entries.iterator(), obj); 57 } 58 59 62 protected Offer onSelectOffer(List offers) { 63 return super.onSelectOffer(offers); 64 } 65 66 69 protected boolean isValid(Offer offer) { 70 Object stub = offer.getObject(); 71 72 if (stub instanceof Stub && Proxy.isProxyClass(stub.getClass())) { 73 InvocationHandler handler = Proxy.getInvocationHandler(stub); 74 75 if (handler instanceof HealthCheck) { 76 try { 77 return ((HealthCheck) handler).isValid(); 78 } catch (Exception e) { 79 return false; 80 } 81 } 82 83 return true; 84 } else if (stub instanceof HealthCheck) { 85 try { 86 boolean valid = ((HealthCheck) stub).isValid(); 87 88 return valid; 89 } catch (Exception e) { 90 return false; 91 } 92 } else { 93 return true; 94 } 95 } 96 } 97 } 98 | Popular Tags |