| 1 | package net.spy.memcached.internal; |
| 2 | |
| 3 | import java.util.concurrent.CountDownLatch; |
| 4 | import java.util.concurrent.ExecutionException; |
| 5 | import java.util.concurrent.Future; |
| 6 | import java.util.concurrent.TimeUnit; |
| 7 | import java.util.concurrent.TimeoutException; |
| 8 | |
| 9 | import net.spy.memcached.ops.Operation; |
| 10 | |
| 11 | /** |
| 12 | * Future returned for GET operations. |
| 13 | * |
| 14 | * Not intended for general use. |
| 15 | * |
| 16 | * @param <T> Type of object returned from the get |
| 17 | */ |
| 18 | public class GetFuture<T> implements Future<T> { |
| 19 | |
| 20 | private final OperationFuture<Future<T>> rv; |
| 21 | |
| 22 | public GetFuture(CountDownLatch l, long opTimeout) { |
| 23 | this.rv = new OperationFuture<Future<T>>(l, opTimeout); |
| 24 | } |
| 25 | |
| 26 | public boolean cancel(boolean ign) { |
| 27 | return rv.cancel(ign); |
| 28 | } |
| 29 | |
| 30 | public T get() throws InterruptedException, ExecutionException { |
| 31 | Future<T> v = rv.get(); |
| 32 | return v == null ? null : v.get(); |
| 33 | } |
| 34 | |
| 35 | public T get(long duration, TimeUnit units) |
| 36 | throws InterruptedException, TimeoutException, ExecutionException { |
| 37 | Future<T> v = rv.get(duration, units); |
| 38 | return v == null ? null : v.get(); |
| 39 | } |
| 40 | |
| 41 | public void set(Future<T> d) { |
| 42 | rv.set(d); |
| 43 | } |
| 44 | |
| 45 | public void setOperation(Operation to) { |
| 46 | rv.setOperation(to); |
| 47 | } |
| 48 | |
| 49 | public boolean isCancelled() { |
| 50 | return rv.isCancelled(); |
| 51 | } |
| 52 | |
| 53 | public boolean isDone() { |
| 54 | return rv.isDone(); |
| 55 | } |
| 56 | } |