1 22 package org.jboss.ejb3.service; 23 24 import java.lang.reflect.Method ; 25 import java.lang.reflect.Proxy ; 26 import java.io.ObjectInput ; 27 import java.io.IOException ; 28 import java.io.ObjectOutput ; 29 import org.jboss.aspects.asynch.AsynchMixin; 30 import org.jboss.aspects.asynch.AsynchProvider; 31 import org.jboss.aspects.asynch.FutureHolder; 32 import org.jboss.ejb3.Container; 33 import org.jboss.ejb3.JBossProxy; 34 import org.jboss.ejb3.LocalProxy; 35 import org.jboss.ejb3.ProxyUtils; 36 37 41 public class ServiceLocalProxy extends LocalProxy 42 { 43 AsynchProvider provider; 44 45 public ServiceLocalProxy() 46 { 47 } 48 49 public ServiceLocalProxy(Container container) 50 { 51 super(container); 52 } 53 54 public ServiceLocalProxy(AsynchProvider provider, Container container) 55 { 56 super(container); 57 this.provider = provider; 58 } 59 60 public Object invoke(Object proxy, Method method, Object [] args) 61 throws Throwable 62 { 63 if (method.getDeclaringClass() == AsynchProvider.class) 64 { 65 return provider.getFuture(); 66 } 67 68 Object ret = ProxyUtils.handleCallLocally((JBossProxy) proxy, this, method, args); 69 if (ret != null) 70 { 71 return ret; 72 } 73 74 ServiceContainer sc = (ServiceContainer) container; 75 return sc.localInvoke(method, args, (FutureHolder) provider); 76 } 77 78 public Object getAsynchronousProxy(Object proxy) 79 { 80 Class [] infs = proxy.getClass().getInterfaces(); 81 if (!ProxyUtils.isAsynchronous(infs)) 82 { 83 Class [] interfaces = ProxyUtils.addAsynchProviderInterface(infs); 84 AsynchMixin mixin = new AsynchMixin(); 85 ServiceLocalProxy handler = new ServiceLocalProxy(mixin, container); 86 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler); 87 } 88 89 return proxy; 91 } 92 93 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 95 { 96 super.readExternal(in); 97 provider = (AsynchProvider)in.readObject(); 98 } 99 100 public void writeExternal(ObjectOutput out) throws IOException 102 { 103 super.writeExternal(out); 104 out.writeObject(provider); 105 } 106 107 public String toString() 108 { 109 return container.getEjbName().toString(); 110 } 111 112 } 113 | Popular Tags |