1 22 package org.jboss.aspects.asynch; 23 24 import org.jboss.aop.InstanceAdvisor; 25 import org.jboss.aop.util.PayloadKey; 26 27 import java.io.Externalizable ; 28 import java.io.IOException ; 29 import java.io.ObjectInput ; 30 import java.io.ObjectOutput ; 31 32 38 public class AsynchProxyMixin implements AsynchProvider, Externalizable 39 { 40 private static final long serialVersionUID = -6895953696792282031L; 41 42 public static final String CURRENT_FUTURE = "CURRENT_FUTURE"; 43 private transient ThreadLocal currentFuture; 44 45 private InstanceAdvisor advisor; 46 47 public void setAdvisor(InstanceAdvisor advisor) 48 { 49 this.advisor = advisor; 50 } 51 52 53 public void setFuture(Future future) 54 { 55 try 56 { 57 Future oldFuture = getFuture(); 58 if (oldFuture != null) oldFuture.release(); 59 } 60 catch (Exception e) 61 { 62 } 64 currentFuture.set(future); 65 } 66 67 public Future getFuture() 68 { 69 Future future = (Future) currentFuture.get(); 70 currentFuture.set(null); 71 return future; 72 } 73 74 public void writeExternal(ObjectOutput out) throws IOException 75 { 76 out.writeObject(advisor); 77 } 78 79 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 80 { 81 advisor = (InstanceAdvisor) in.readObject(); 82 currentFuture = new ThreadLocal (); 83 advisor.getMetaData().addMetaData(CURRENT_FUTURE, CURRENT_FUTURE, currentFuture, PayloadKey.TRANSIENT); 84 } 85 } 86 | Popular Tags |