| 11 | import java.util.concurrent.TimeoutException; |
| 12 | |
| 13 | public class FutureCallback<Req, Res> extends AbstractWatchableCallback<Req, Res> implements Future<Res> { |
| 14 | private boolean completed = false; |
| 15 | private Res result; |
| 16 | private Exception ex; |
| 17 | |
| 18 | public void onCompleted(Req request, Res result) { |
| 19 | synchronized(this) { |
| 20 | if (this.completed) { |
| 21 | throw new IllegalStateException("completed() must not be invoked twice."); |
| 22 | } |
| 23 | |
| 24 | this.completed = true; |
| 25 | this.result = result; |
| 26 | this.notifyAll(); |
| 27 | } |
| 28 | |
| 29 | Iterator it = this.callbacks.iterator(); |
| 30 | |
| 31 | while(it.hasNext()) { |
| 32 | FcCallback<Req, Res> callback = (FcCallback)it.next(); |
| 33 | callback.onCompleted(request, result); |
| 34 | } |
| 35 | |
| 36 | } |
| 37 | |
| 38 | public void onFailed(Req request, Exception ex) { |
| 39 | synchronized(this) { |
| 40 | if (this.completed) { |
| 41 | throw new IllegalStateException("completed() must not be invoked twice."); |
| 42 | } |
| 43 | |
| 44 | this.completed = true; |
| 45 | this.ex = ex; |
| 46 | this.notifyAll(); |
| 47 | } |
| 48 | |
| 49 | Iterator it = this.callbacks.iterator(); |
| 50 | |
| 51 | while(it.hasNext()) { |
| 52 | FcCallback<Req, Res> callback = (FcCallback)it.next(); |
| 53 | callback.onFailed(request, ex); |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | |
| 58 | public boolean cancel(boolean mayInterruptIfRunning) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | public boolean isCancelled() { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | public boolean isDone() { |
| 67 | synchronized(this) { |
| 68 | return this.completed; |
| 69 | } |
| 70 | } |
nothing calls this directly
no outgoing calls
no test coverage detected