1 22 package org.jboss.ejb3.stateful; 23 24 import java.lang.reflect.Method ; 25 import java.lang.reflect.Proxy ; 26 import java.io.Externalizable ; 27 import java.io.ObjectInput ; 28 import java.io.IOException ; 29 import java.io.ObjectOutput ; 30 import org.jboss.aspects.asynch.AsynchMixin; 31 import org.jboss.aspects.asynch.AsynchProvider; 32 import org.jboss.aspects.asynch.FutureHolder; 33 import org.jboss.ejb3.Container; 34 import org.jboss.ejb3.LocalProxy; 35 import org.jboss.ejb3.ProxyUtils; 36 import org.jboss.util.id.GUID; 37 38 44 public class StatefulLocalProxy extends LocalProxy implements Externalizable 45 { 46 protected Object id; 47 AsynchProvider provider; 48 49 50 51 public StatefulLocalProxy(Container container, Object id) 52 { 53 super(container); 54 this.id = id; 55 } 56 57 public StatefulLocalProxy(AsynchProvider provider, Container container, Object id) 58 { 59 super(container); 60 this.provider = provider; 61 this.id = id; 62 } 63 64 public StatefulLocalProxy() 65 { 66 } 67 68 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 70 { 71 super.readExternal(in); 72 id = in.readObject(); 73 } 74 75 public void writeExternal(ObjectOutput out) throws IOException 77 { 78 super.writeExternal(out); 79 out.writeObject(id); 80 } 81 82 public Object invoke(Object proxy, Method method, Object [] args) 83 throws Throwable 84 { 85 if (method.getDeclaringClass() == AsynchProvider.class) 86 { 87 return provider.getFuture(); 88 } 89 90 StatefulContainer sfsb = (StatefulContainer) container; 92 Object ret = ProxyUtils.handleCallLocally(proxy, this, method, args); 93 if (ret != null) 94 { 95 return ret; 96 } 97 98 return sfsb.localInvoke(id, method, args, (FutureHolder) provider); 99 } 100 101 public Object getAsynchronousProxy(Object proxy) 102 { 103 Class [] infs = proxy.getClass().getInterfaces(); 104 if (!ProxyUtils.isAsynchronous(infs)) 105 { 106 Class [] interfaces = ProxyUtils.addAsynchProviderInterface(infs); 107 AsynchMixin mixin = new AsynchMixin(); 108 StatefulLocalProxy handler = new StatefulLocalProxy(mixin, container, id); 109 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler); 110 } 111 112 return proxy; 114 } 115 116 public String toString() 117 { 118 if (id != null) 119 { 120 return container.getEjbName().toString() + ":" + id.toString(); 121 } 122 else 123 { 124 GUID guid = new GUID(); 126 return container.getEjbName().toString() + ":" + guid.toString(); 127 } 128 } 129 130 } 131 | Popular Tags |