EMMA Coverage Report (generated Tue Oct 27 11:32:50 PDT 2009)
[all classes][net.spy.memcached.internal]

COVERAGE SUMMARY FOR SOURCE FILE [OperationFuture.java]

nameclass, %method, %block, %line, %
OperationFuture.java100% (1/1)100% (10/10)78%  (124/158)85%  (24.7/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OperationFuture100% (1/1)100% (10/10)78%  (124/158)85%  (24.7/29)
get (): Object 100% (1/1)46%  (6/13)33%  (1/3)
isDone (): boolean 100% (1/1)48%  (14/29)48%  (1/2)
isCancelled (): boolean 100% (1/1)64%  (9/14)75%  (1.5/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
cancel (boolean): boolean 100% (1/1)77%  (17/22)83%  (2.5/3)
OperationFuture (CountDownLatch, AtomicReference, long): void 100% (1/1)100% (12/12)100% (5/5)
OperationFuture (CountDownLatch, long): void 100% (1/1)100% (9/9)100% (2/2)
get (long, TimeUnit): Object 100% (1/1)100% (42/42)100% (7/7)
set (Object): void 100% (1/1)100% (5/5)100% (2/2)
setOperation (Operation): void 100% (1/1)100% (4/4)100% (2/2)

1package net.spy.memcached.internal;
2 
3import java.util.concurrent.CountDownLatch;
4import java.util.concurrent.ExecutionException;
5import java.util.concurrent.Future;
6import java.util.concurrent.TimeUnit;
7import java.util.concurrent.TimeoutException;
8import java.util.concurrent.atomic.AtomicReference;
9 
10import net.spy.memcached.ops.Operation;
11import net.spy.memcached.ops.OperationState;
12 
13/**
14 * Managed future for operations.
15 *
16 * Not intended for general use.
17 *
18 * @param <T> Type of object returned from this future.
19 */
20public class OperationFuture<T> implements Future<T> {
21 
22        private final CountDownLatch latch;
23        private final AtomicReference<T> objRef;
24        private final long timeout;
25        private Operation op;
26 
27        public OperationFuture(CountDownLatch l, long opTimeout) {
28                this(l, new AtomicReference<T>(null), opTimeout);
29        }
30 
31        public OperationFuture(CountDownLatch l, AtomicReference<T> oref,
32                long opTimeout) {
33                super();
34                latch=l;
35                objRef=oref;
36                timeout = opTimeout;
37        }
38 
39        public boolean cancel(boolean ign) {
40                assert op != null : "No operation";
41                op.cancel();
42                // This isn't exactly correct, but it's close enough.  If we're in
43                // a writing state, we *probably* haven't started.
44                return op.getState() == OperationState.WRITING;
45        }
46 
47        public T get() throws InterruptedException, ExecutionException {
48                try {
49                        return get(timeout, TimeUnit.MILLISECONDS);
50                } catch (TimeoutException e) {
51                        throw new RuntimeException(
52                                "Timed out waiting for operation", e);
53                }
54        }
55 
56        public T get(long duration, TimeUnit units)
57                throws InterruptedException, TimeoutException, ExecutionException {
58                if(!latch.await(duration, units)) {
59                        throw new CheckedOperationTimeoutException(
60                                        "Timed out waiting for operation", op);
61                }
62                if(op != null && op.hasErrored()) {
63                        throw new ExecutionException(op.getException());
64                }
65                if(isCancelled()) {
66                        throw new ExecutionException(new RuntimeException("Cancelled"));
67                }
68 
69                return objRef.get();
70        }
71 
72        public void set(T o) {
73                objRef.set(o);
74        }
75 
76        public void setOperation(Operation to) {
77                op=to;
78        }
79 
80        public boolean isCancelled() {
81                assert op != null : "No operation";
82                return op.isCancelled();
83        }
84 
85        public boolean isDone() {
86                assert op != null : "No operation";
87                return latch.getCount() == 0 ||
88                        op.isCancelled() || op.getState() == OperationState.COMPLETE;
89        }
90 
91}

[all classes][net.spy.memcached.internal]
EMMA 2.0.5312 (C) Vladimir Roubtsov