01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: /**
33: * Comment
34: *
35: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
36: * @version $Revision: 57186 $
37: */
38: public class AsynchProxyMixin implements AsynchProvider, Externalizable {
39: private static final long serialVersionUID = -6895953696792282031L;
40:
41: public static final String CURRENT_FUTURE = "CURRENT_FUTURE";
42: private transient ThreadLocal currentFuture;
43:
44: private InstanceAdvisor advisor;
45:
46: public void setAdvisor(InstanceAdvisor advisor) {
47: this .advisor = advisor;
48: }
49:
50: public void setFuture(Future future) {
51: try {
52: Future oldFuture = getFuture();
53: if (oldFuture != null)
54: oldFuture.release();
55: } catch (Exception e) {
56: // eat it.
57: }
58: currentFuture.set(future);
59: }
60:
61: public Future getFuture() {
62: Future future = (Future) currentFuture.get();
63: currentFuture.set(null);
64: return future;
65: }
66:
67: public void writeExternal(ObjectOutput out) throws IOException {
68: out.writeObject(advisor);
69: }
70:
71: public void readExternal(ObjectInput in) throws IOException,
72: ClassNotFoundException {
73: advisor = (InstanceAdvisor) in.readObject();
74: currentFuture = new ThreadLocal();
75: advisor.getMetaData().addMetaData(CURRENT_FUTURE,
76: CURRENT_FUTURE, currentFuture, PayloadKey.TRANSIENT);
77: }
78: }
|