1 22 package org.jboss.ejb3.stateless; 23 24 import java.lang.reflect.Method ; 25 import java.lang.reflect.Proxy ; 26 import org.jboss.aop.Dispatcher; 27 import org.jboss.aop.advice.Interceptor; 28 import org.jboss.aop.joinpoint.MethodInvocation; 29 import org.jboss.aop.util.MethodHashing; 30 import org.jboss.aop.util.PayloadKey; 31 import org.jboss.aspects.asynch.AsynchMixin; 32 import org.jboss.aspects.asynch.AsynchProvider; 33 import org.jboss.aspects.remoting.ClusterConstants; 34 import org.jboss.aspects.remoting.FamilyWrapper; 35 import org.jboss.aspects.remoting.InvokeRemoteInterceptor; 36 import org.jboss.ejb3.JBossProxy; 37 import org.jboss.ejb3.ProxyUtils; 38 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor; 39 import org.jboss.ejb3.remoting.BaseRemoteProxy; 40 import org.jboss.ha.framework.interfaces.LoadBalancePolicy; 41 42 48 public class StatelessClusteredProxy extends BaseRemoteProxy 49 { 50 protected FamilyWrapper family; 51 protected LoadBalancePolicy lbPolicy; 52 AsynchProvider provider; 53 54 public StatelessClusteredProxy(Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy) 55 { 56 super(containerId, interceptors); 57 this.family = family; 58 this.lbPolicy = lbPolicy; 59 } 60 61 public StatelessClusteredProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, FamilyWrapper family, LoadBalancePolicy lbPolicy) 62 { 63 super(containerId, interceptors); 64 this.family = family; 65 this.lbPolicy = lbPolicy; 66 this.provider = provider; 67 } 68 69 public StatelessClusteredProxy() 70 { 71 } 72 73 public Object invoke(Object proxy, Method method, Object [] args) 74 throws Throwable 75 { 76 if (method.getDeclaringClass() == AsynchProvider.class) 77 { 78 return provider.getFuture(); 79 } 80 81 long hash = MethodHashing.calculateHash(method); 82 Object ret = ProxyUtils.handleCallLocally(hash, (JBossProxy) proxy, this, method, args); 83 if (ret != null) 84 { 85 return ret; 86 } 87 88 MethodInvocation sri = new MethodInvocation(interceptors, hash, method, method, null); 89 sri.setArguments(args); 90 sri.setInstanceResolver(metadata); 91 sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS); 92 sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.CLUSTER_FAMILY_WRAPPER, family, PayloadKey.AS_IS); 93 sri.getMetaData().addMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY, lbPolicy, PayloadKey.AS_IS); 94 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS); 95 96 if (provider != null) 97 { 98 sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS); 99 } 100 return sri.invokeNext(); 101 } 102 103 public Object getAsynchronousProxy(Object proxy) 104 { 105 Class [] infs = proxy.getClass().getInterfaces(); 106 if (!ProxyUtils.isAsynchronous(infs)) 107 { 108 Class [] interfaces = ProxyUtils.addAsynchProviderInterface(infs); 109 AsynchMixin mixin = new AsynchMixin(); 110 Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors); 111 StatelessClusteredProxy handler = new StatelessClusteredProxy(mixin, containerId, newInterceptors, family, lbPolicy); 112 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler); 113 } 114 115 return proxy; 117 } 118 119 public String toString() 120 { 121 return containerId.toString(); 122 } 123 124 } 125 | Popular Tags |