01: package gnu.mapping;
02:
03: public class Future extends Thread {
04: public RunnableClosure closure;
05:
06: public Future(Procedure action, CallContext parentContext) {
07: closure = new RunnableClosure(action, parentContext);
08: }
09:
10: public Future(Procedure action, CallContext parentContext,
11: Environment penvironment) {
12: closure = new RunnableClosure(action, parentContext,
13: penvironment);
14: closure.environment.setName(getName());
15: }
16:
17: public Future(Procedure action, Environment penvironment,
18: InPort in, OutPort out, OutPort err) {
19: closure = new RunnableClosure(action, penvironment, in, out,
20: err);
21: }
22:
23: public Future(Procedure action) {
24: closure = new RunnableClosure(action);
25: }
26:
27: /** Get the CallContext we use for this Thread. */
28: public final CallContext getCallContext() {
29: return closure.getCallContext();
30: }
31:
32: public Environment getEnvironment() {
33: return closure.environment;
34: }
35:
36: public void run() {
37: closure.run();
38: }
39:
40: public Object waitForResult() throws Throwable {
41: try {
42: join();
43: } catch (InterruptedException ex) {
44: throw new RuntimeException(
45: "thread join [force] was interrupted");
46: }
47: Throwable ex = closure.exception;
48: if (ex != null)
49: throw ex;
50: return closure.result;
51: }
52:
53: public String toString() {
54: StringBuffer buf = new StringBuffer();
55: buf.append("#<future ");
56: buf.append(getName());
57: buf.append(">");
58: return buf.toString();
59: }
60: }
|