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.InvokeRemoteInterceptor; 34 import org.jboss.ejb3.ProxyUtils; 35 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor; 36 import org.jboss.logging.Logger; 37 import org.jboss.remoting.InvokerLocator; 38 39 45 public class StatelessRemoteProxy extends org.jboss.ejb3.session.BaseSessionRemoteProxy 46 { 47 private static final Logger log = Logger.getLogger(StatelessRemoteProxy.class); 48 49 protected InvokerLocator uri; 50 AsynchProvider provider; 51 52 public StatelessRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri) 53 { 54 super(containerId, interceptors); 55 this.uri = uri; 56 } 57 58 public StatelessRemoteProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, InvokerLocator uri) 59 { 60 super(containerId, interceptors); 61 this.uri = uri; 62 this.provider = provider; 63 } 64 65 protected StatelessRemoteProxy() 66 { 67 } 68 69 70 public Object invoke(Object proxy, Method method, Object [] args) 71 throws Throwable 72 { 73 if (method.getDeclaringClass() == AsynchProvider.class) 74 { 75 return provider.getFuture(); 76 } 77 78 long hash = MethodHashing.calculateHash(method); 79 Object ret = ProxyUtils.handleCallLocally(hash, proxy, this, method, args); 80 if (ret != null) 81 { 82 return ret; 83 } 84 85 ret = handleEjb21CallLocally(method, args); 86 if (ret != null) 87 { 88 return ret; 89 } 90 91 MethodInvocation sri = new MethodInvocation(interceptors, hash, method, method, null); 92 sri.setArguments(args); 93 sri.setInstanceResolver(metadata); 94 sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS); 95 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS); 96 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS); 97 98 if (provider != null) 99 { 100 sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS); 101 } 102 return sri.invokeNext(); 103 } 104 105 public Object getAsynchronousProxy(Object proxy) 106 { 107 Class [] infs = proxy.getClass().getInterfaces(); 108 if (!ProxyUtils.isAsynchronous(infs)) 109 { 110 Class [] interfaces = ProxyUtils.addAsynchProviderInterface(infs); 111 AsynchMixin mixin = new AsynchMixin(); 112 Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors); 113 StatelessRemoteProxy handler = new StatelessRemoteProxy(mixin, containerId, newInterceptors, uri); 114 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler); 115 } 116 117 return proxy; 119 } 120 121 public String toString() 122 { 123 return containerId.toString(); 124 } 125 126 private Object handleEjb21CallLocally(Method method, Object [] args) 127 { 128 if (method.equals(ProxyUtils.GET_HOME_HANDLE)) 129 { 130 return homeHandle; 131 } else if (method.equals(ProxyUtils.GET_EJB_METADATA)) 132 { 133 return ejbMetaData; 134 } else if (method.equals(ProxyUtils.GET_HANDLE)) 135 { 136 return handle; 137 } 138 139 return null; 140 } 141 } 142 | Popular Tags |