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.*; 24 import org.objectweb.jac.core.rtti.ClassRepository; 25 import org.objectweb.jac.util.*; 26 27 40 41 public class StrongPullConsistencyWrapper extends ConsistencyWrapper { 42 static Logger logger = Logger.getLogger("consistency"); 43 44 String hosts = null; 45 46 51 52 public StrongPullConsistencyWrapper(AspectComponent ac, String hosts) { 53 super(ac); 54 this.hosts = hosts; 55 knownReplicas = null; 56 } 57 58 59 public StrongPullConsistencyWrapper(AspectComponent ac) { 60 super(ac); 61 } 62 63 74 75 public Object whenRead(Interaction interaction) { 76 77 Object ret = null; 78 79 ret = proceed(interaction); 80 81 logger.debug("Pull knownReplicas = "+knownReplicas); 82 83 if (ret == null) { 84 85 if (knownReplicas != null) { 86 Collaboration c = Collaboration.get(); 87 Vector asked_replicas = (Vector)c.getAttribute(visitedReplicas); 88 if (asked_replicas == null) { 89 asked_replicas = (Vector)c.addAttribute( 90 visitedReplicas, new Vector()); 91 } 92 93 try { 95 Vector new_ar = new Vector(); 96 RemoteRef cur_replica = RemoteRef.create( 97 NameRepository.get().getName(interaction.wrappee), 98 interaction.wrappee); 99 100 for (int i = 0; i < knownReplicas.size(); i++) { 101 if ( (! asked_replicas.contains( knownReplicas.get(i) ) ) && 102 (! ((RemoteRef)knownReplicas.get(i)).getRemCont().isLocal()) ) { 103 104 Vector kr = new Vector(knownReplicas); 105 kr.remove(knownReplicas.get(i)); 106 new_ar.clear(); 107 new_ar.addAll(asked_replicas); 108 new_ar.addAll(kr); 109 new_ar.add(cur_replica); 110 c.addAttribute(visitedReplicas, new_ar); 111 112 logger.debug("(strong pull) read event on " + 113 interaction.wrappee + ":" + 114 interaction.method + ":" + 115 ((RemoteRef)knownReplicas.get(i)).getRemCont().getName()); 116 ret = ((RemoteRef)knownReplicas.get(i)).invokeRoleMethod( 117 "acceptRemoteRead", 118 new Object [] { null, 119 new Object [] { interaction.method, 120 interaction.args } } ); 121 if (ret != null) { 122 break; 123 } 124 } 125 } 126 } finally { 127 c.addAttribute(visitedReplicas, null); 128 } 129 } 130 } 131 return ret; 132 } 133 134 146 147 public Object acceptRemoteRead(Wrappee wrappee, RemoteRef remoteReplica, 148 Object [] data) { 149 logger.debug("(strong pull) remote read event on " + 150 wrappee + ":" + (String )data[0]); 151 return ClassRepository.get().getClass(wrappee).getMethod((String )data[0]).invoke( 152 wrappee , (Object [])data[1] ); 153 } 154 155 156 } 157 | Popular Tags |