KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > FutureAdapter


1 package hudson.remoting;
2
3 import java.util.concurrent.ExecutionException JavaDoc;
4 import java.util.concurrent.TimeUnit JavaDoc;
5 import java.util.concurrent.TimeoutException JavaDoc;
6
7 /**
8  * {@link Future} that converts the return type.
9  *
10  * @author Kohsuke Kawaguchi
11  */

12 abstract class FutureAdapter<X,Y> implements Future<X> {
13     protected final Future<Y> core;
14
15     protected FutureAdapter(Future<Y> core) {
16         this.core = core;
17     }
18
19     public boolean cancel(boolean mayInterruptIfRunning) {
20         return core.cancel(mayInterruptIfRunning);
21     }
22
23     public boolean isCancelled() {
24         return core.isCancelled();
25     }
26
27     public boolean isDone() {
28         return core.isDone();
29     }
30
31     public X get() throws InterruptedException JavaDoc, ExecutionException JavaDoc {
32         return adapt(core.get());
33     }
34
35     public X get(long timeout, TimeUnit JavaDoc unit) throws InterruptedException JavaDoc, ExecutionException JavaDoc, TimeoutException JavaDoc {
36         return adapt(core.get(timeout, unit));
37     }
38
39     protected abstract X adapt(Y y) throws ExecutionException JavaDoc;
40 }
41
Popular Tags