1 17 18 package org.objectweb.jac.core.dist; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.core.*; 24 import org.objectweb.jac.util.*; 25 26 41 42 public class StubWrapper extends Wrapper { 43 static Logger logger = Logger.getLogger("stub"); 44 45 50 51 public StubWrapper(AspectComponent ac, RemoteRef remoteRef) { 52 super(ac); 53 this.remoteRef = remoteRef; 54 } 55 56 61 62 public StubWrapper(AspectComponent ac, String serverContainer) { 63 super(ac); 64 this.serverContainer = serverContainer; 65 Topology t = Topology.getPartialTopology( serverContainer ); 66 if( t!=null && t.countContainers()>0 ) { 67 this.serverContainer=t.getContainer(0).getName(); 68 } else { 69 this.serverContainer = serverContainer; 70 } 71 } 72 73 String serverContainer = null; 74 75 76 77 protected RemoteRef remoteRef; 78 79 80 85 86 public RemoteRef getRemoteRef() { return remoteRef; } 87 88 89 92 93 public Object _invoke(Interaction interaction) { 94 95 if( remoteRef == null ) { 96 if( serverContainer == null ) { 97 logger.warn("local call (1) for stub "+interaction.wrappee); 98 return proceed(interaction); 99 } 100 RemoteContainer rc = Topology.get().getFirstContainer(serverContainer); 101 if( rc == null ) { 102 logger.warn("local call (2) for stub "+interaction.wrappee); 103 return proceed(interaction); 104 } 105 remoteRef = rc.bindTo(NameRepository.get().getName(interaction.wrappee)); 106 if( remoteRef == null ) { 107 logger.warn("local call (3) for stub "+interaction.wrappee+ 108 " ("+rc+","+serverContainer+")"); 109 return proceed(interaction); 110 } 111 } 112 113 logger.debug(interaction.wrappee + " forwards to the server"); 114 115 116 117 return remoteRef.invoke(interaction.method.getName(), interaction.args); 118 } 119 120 public Object invoke(MethodInvocation invocation) throws Throwable { 121 return _invoke((Interaction) invocation); 122 } 123 124 public Object construct(ConstructorInvocation invocation) 125 throws Throwable { 126 throw new Exception ("Wrapper "+this+" does not support construction interception."); 127 } 128 129 } 130 131 132 133 134 135 136 137 | Popular Tags |