1 17 18 package org.objectweb.jac.aspects.distribution; 19 20 21 22 import java.util.*; 23 import org.aopalliance.intercept.ConstructorInvocation; 24 import org.aopalliance.intercept.MethodInvocation; 25 import org.apache.log4j.Logger; 26 import org.objectweb.jac.core.*; 27 import org.objectweb.jac.core.dist.*; 28 import org.objectweb.jac.util.Log; 29 30 39 40 public class BroadcastingAC 41 extends AspectComponent 42 implements BroadcastingConf 43 { 44 static Logger logger = Logger.getLogger("broadcasting"); 45 46 public void addBroadcaster( 47 String wrappeeName, 48 String methods, 49 String broadcasterHost, 50 String replicasHost) { 51 52 pointcut( 53 wrappeeName, 54 ".*", 55 methods + " && !CONSTRUCTORS", 56 new BroadcastingWrapper(this, replicasHost), 57 broadcasterHost, 58 null); 59 } 60 61 64 65 public class BroadcastingWrapper extends Wrapper { 66 67 Vector replicas = null; 68 String hostExpr; 69 boolean doFill = true; 70 71 public BroadcastingWrapper(AspectComponent ac, String hostExpr) { 72 super(ac); 73 this.hostExpr = hostExpr; 74 } 75 76 public Object invoke(MethodInvocation invocation) throws Throwable { 77 return broadcast((Interaction) invocation); 78 } 79 80 public Object construct(ConstructorInvocation invocation) 81 throws Throwable { 82 throw new Exception ("This wrapper does not support constructor wrapping"); 83 } 84 85 public void invalidate() { 86 doFill = true; 87 } 88 89 91 92 public Object broadcast(Interaction interaction) { 93 if (doFill) { 94 replicas = 95 Topology.getPartialTopology(hostExpr).getReplicas( 96 interaction.wrappee); 97 doFill = false; 98 } 99 if (replicas.size() == 0) { 100 doFill = true; 103 logger.warn("no replica found, local call performed"); 104 return proceed(interaction); 105 } 106 Object ret = null; 107 for (int i = 0; i < replicas.size(); i++) { 108 ret = 109 ((RemoteRef) replicas.get(i)).invoke( 110 interaction.method.getName(), 111 interaction.args); 112 } 113 return ret; } 115 116 } 117 } 118 | Popular Tags |