1 17 18 package org.objectweb.jac.aspects.distribution.consistency; 19 20 import java.util.*; 21 import org.apache.log4j.Logger; 22 import org.objectweb.jac.core.*; 23 import org.objectweb.jac.core.dist.RemoteRef; 24 import org.objectweb.jac.core.rtti.MethodItem; 25 import org.objectweb.jac.util.Log; 26 27 42 43 public class StrongPushConsistencyWrapper extends ConsistencyWrapper { 44 static Logger logger = Logger.getLogger("consistency"); 45 46 47 boolean inNotification = false; 48 49 54 55 public StrongPushConsistencyWrapper(AspectComponent ac, String hosts) { 56 super(ac); 57 knownReplicas = null; 58 this.hosts = hosts; 59 } 60 61 62 public StrongPushConsistencyWrapper(AspectComponent ac) { 63 super(ac); 64 } 65 66 75 76 public Object whenWrite(Interaction interaction) { 77 78 Object ret = null; 79 80 if (knownReplicas == null) { 81 calculateKnownReplicas(interaction.wrappee); 82 } 83 84 attrdef("Persistence.disabled", "true"); 85 86 if (knownReplicas != null) { 87 if (inNotification) return proceed(interaction); 88 inNotification = true; 89 Collaboration c = Collaboration.get(); 90 Vector notified_replicas = (Vector)c.getAttribute(visitedReplicas); 91 if (notified_replicas == null) { 92 notified_replicas = (Vector)c.addAttribute( 93 visitedReplicas, new Vector()); 94 } 95 96 try { 97 Vector new_nr = new Vector(); 98 RemoteRef cur_replica = RemoteRef.create( 99 NameRepository.get().getName(interaction.wrappee), 100 interaction.wrappee); 101 102 for (int i = 0; i < knownReplicas.size(); i++) { 103 if ( (! notified_replicas.contains(knownReplicas.get(i)) ) && 104 (! ((RemoteRef)knownReplicas.get(i)).getRemCont().isLocal()) ) { 105 106 Vector kr = new Vector(knownReplicas); 107 kr.remove(knownReplicas.get(i)); 108 new_nr.clear(); 109 new_nr.addAll(notified_replicas); 110 new_nr.addAll(kr); 111 new_nr.add (cur_replica); 112 c.addAttribute(visitedReplicas, new_nr); 113 114 logger.debug("(strong) write event on " + 115 NameRepository.get().getName(interaction.wrappee)+ 116 ":" + interaction.method + ":" + 117 ((RemoteRef)knownReplicas.get(i)).getRemCont().getName()); 118 try { 119 ((RemoteRef)knownReplicas.get(i)).invokeRoleMethod( 120 "acceptRemoteWrite", 121 new Object [] { null, 122 new Object [] { interaction.method, 123 interaction.args } } 124 ); 125 } catch ( Exception e ) { 126 logger.error("strong consistency error: "+ 127 "failed to remotely invoke "+ 128 "acceptRemoteWrite for "+ 129 interaction.wrappee+"."+interaction.method); 130 e.printStackTrace(); 131 break; 132 } 133 } 134 } 135 } finally { 136 c.addAttribute(visitedReplicas,null); 137 } 138 } else { 139 logger.debug("none replicas are known for "+ 140 NameRepository.get().getName(interaction.wrappee)); 141 } 142 ret = proceed(interaction); 143 144 inNotification = false; 145 146 return ret; 147 } 148 149 164 165 public Object acceptRemoteWrite(Wrappee wrappee, RemoteRef remoteReplica, 166 Object [] data) { 167 logger.debug("(strong) remote write event on " + 168 NameRepository.get().getName(wrappee) + 169 ":" + data[0]); 170 Object ret=null; 171 try { 172 ret = ((MethodItem)data[0]).invoke( 173 wrappee, (Object [])data[1]); 174 } catch (Exception e) { 175 e.printStackTrace(); 176 } 177 return ret; 178 } 179 180 185 186 public void whenBindingNewReplica(Wrappee wrappee, RemoteRef newReplica) { 187 logger.debug("(strong) initialized " + 188 newReplica + " with " + 189 NameRepository.get().getName(wrappee)); 190 newReplica.remoteCopy(wrappee); 191 } 192 193 } 194 | Popular Tags |