KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > Future


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