1 | /** |
2 | * |
3 | */ |
4 | package net.spy.memcached.internal; |
5 | |
6 | import java.util.concurrent.ExecutionException; |
7 | import java.util.concurrent.Future; |
8 | import java.util.concurrent.TimeUnit; |
9 | import java.util.concurrent.TimeoutException; |
10 | |
11 | /** |
12 | * A future that fires immediately. |
13 | */ |
14 | public class ImmediateFuture implements Future<Boolean> { |
15 | private final Boolean value; |
16 | private final ExecutionException exception; |
17 | |
18 | public ImmediateFuture(Boolean returnValue) { |
19 | value = returnValue; |
20 | exception = null; |
21 | } |
22 | |
23 | public ImmediateFuture(Exception e) { |
24 | value = null; |
25 | exception = new ExecutionException(e); |
26 | } |
27 | |
28 | public boolean cancel(boolean mayInterruptIfRunning) { |
29 | return false; |
30 | } |
31 | |
32 | public Boolean get() throws InterruptedException, ExecutionException { |
33 | if(exception != null) { |
34 | throw exception; |
35 | } |
36 | return value; |
37 | } |
38 | |
39 | public Boolean get(long timeout, TimeUnit unit) |
40 | throws InterruptedException, ExecutionException, |
41 | TimeoutException { |
42 | if(exception != null) { |
43 | throw exception; |
44 | } |
45 | return value; |
46 | } |
47 | |
48 | public boolean isCancelled() { |
49 | return false; |
50 | } |
51 | |
52 | public boolean isDone() { |
53 | return true; |
54 | } |
55 | |
56 | } |