1 22 package org.jboss.ejb3.service; 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.JBossProxy; 35 import org.jboss.ejb3.ProxyUtils; 36 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor; 37 import org.jboss.remoting.InvokerLocator; 38 39 43 public class ServiceRemoteProxy extends org.jboss.ejb3.remoting.BaseRemoteProxy 44 { 45 protected InvokerLocator uri; 46 AsynchProvider provider; 47 48 public ServiceRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri) 49 { 50 super(containerId, interceptors); 51 this.uri = uri; 52 } 53 54 public ServiceRemoteProxy(AsynchProvider provider, Object containerId, Interceptor[] interceptors, InvokerLocator uri) 55 { 56 super(containerId, interceptors); 57 this.uri = uri; 58 this.provider = provider; 59 } 60 61 protected ServiceRemoteProxy() 62 { 63 } 64 65 66 public Object invoke(Object proxy, Method method, Object [] args) 67 throws Throwable 68 { 69 if (method.getDeclaringClass() == AsynchProvider.class) 70 { 71 return provider.getFuture(); 72 } 73 74 long hash = MethodHashing.calculateHash(method); 75 Object ret = ProxyUtils.handleCallLocally((JBossProxy) proxy, this, method, args); 76 if (ret != null) 77 { 78 return ret; 79 } 80 81 MethodInvocation sri = new MethodInvocation(interceptors, hash, method, method, null); 82 sri.setArguments(args); 83 sri.setInstanceResolver(metadata); 84 sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS); 85 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS); 86 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS); 87 88 if (provider != null) 89 { 90 sri.getMetaData().addMetaData(AsynchronousInterceptor.ASYNCH, AsynchronousInterceptor.INVOKE_ASYNCH, "YES", PayloadKey.AS_IS); 91 } 92 return sri.invokeNext(); 93 } 94 95 public Object getAsynchronousProxy(Object proxy) 96 { 97 Class [] infs = proxy.getClass().getInterfaces(); 98 if (!ProxyUtils.isAsynchronous(infs)) 99 { 100 Class [] interfaces = ProxyUtils.addAsynchProviderInterface(infs); 101 AsynchMixin mixin = new AsynchMixin(); 102 Interceptor[] newInterceptors = ProxyUtils.addAsynchProxyInterceptor(mixin, interceptors); 103 ServiceRemoteProxy handler = new ServiceRemoteProxy(mixin, containerId, newInterceptors, uri); 104 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler); 105 } 106 107 return proxy; 109 } 110 111 112 public String toString() 113 { 114 return containerId.toString(); 115 } 116 } 117 | Popular Tags |