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

COVERAGE SUMMARY FOR SOURCE FILE [BulkGetFuture.java]

nameclass, %method, %block, %line, %
BulkGetFuture.java100% (1/1)100% (6/6)87%  (160/184)87%  (29.4/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BulkGetFuture100% (1/1)100% (6/6)87%  (160/184)87%  (29.4/34)
get (): Map 100% (1/1)42%  (5/12)33%  (1/3)
cancel (boolean): boolean 100% (1/1)79%  (38/48)80%  (6.4/8)
isDone (): boolean 100% (1/1)90%  (9/10)90%  (0.9/1)
get (long, TimeUnit): Map 100% (1/1)94%  (90/96)94%  (14.1/15)
BulkGetFuture (Map, Collection, CountDownLatch): void 100% (1/1)100% (15/15)100% (6/6)
isCancelled (): boolean 100% (1/1)100% (3/3)100% (1/1)

1package net.spy.memcached.internal;
2 
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.HashSet;
6import java.util.Map;
7import java.util.concurrent.CountDownLatch;
8import java.util.concurrent.ExecutionException;
9import java.util.concurrent.Future;
10import java.util.concurrent.TimeUnit;
11import java.util.concurrent.TimeoutException;
12 
13import net.spy.memcached.ops.Operation;
14import net.spy.memcached.ops.OperationState;
15 
16/**
17 * Future for handling results from bulk gets.
18 *
19 * Not intended for general use.
20 *
21 * @param <T> types of objects returned from the GET
22 */
23public class BulkGetFuture<T> implements Future<Map<String, T>> {
24        private final Map<String, Future<T>> rvMap;
25        private final Collection<Operation> ops;
26        private final CountDownLatch latch;
27        private boolean cancelled=false;
28 
29        public BulkGetFuture(Map<String, Future<T>> m,
30                        Collection<Operation> getOps, CountDownLatch l) {
31                super();
32                rvMap = m;
33                ops = getOps;
34                latch=l;
35        }
36 
37        public boolean cancel(boolean ign) {
38                boolean rv=false;
39                for(Operation op : ops) {
40                        rv |= op.getState() == OperationState.WRITING;
41                        op.cancel();
42                }
43                for (Future<T> v : rvMap.values()) {
44                        v.cancel(ign);
45                }
46                cancelled=true;
47                return rv;
48        }
49 
50        public Map<String, T> get()
51                throws InterruptedException, ExecutionException {
52                try {
53                        return get(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
54                } catch (TimeoutException e) {
55                        throw new RuntimeException("Timed out waiting forever", e);
56                }
57        }
58 
59        public Map<String, T> get(long timeout, TimeUnit unit)
60                throws InterruptedException,
61                ExecutionException, TimeoutException {
62                if(!latch.await(timeout, unit)) {
63                        Collection<Operation> timedoutOps = new HashSet<Operation>();
64                        for(Operation op : ops) {
65                                if(op.getState() != OperationState.COMPLETE) {
66                                        timedoutOps.add(op);
67                                }
68                        }
69                        throw new CheckedOperationTimeoutException("Operation timed out.",
70                                        timedoutOps);
71                }
72                for(Operation op : ops) {
73                        if(op.isCancelled()) {
74                                throw new ExecutionException(
75                                                new RuntimeException("Cancelled"));
76                        }
77                        if(op.hasErrored()) {
78                                throw new ExecutionException(op.getException());
79                        }
80                }
81                Map<String, T> m = new HashMap<String, T>();
82                for (Map.Entry<String, Future<T>> me : rvMap.entrySet()) {
83                        m.put(me.getKey(), me.getValue().get());
84                }
85                return m;
86        }
87 
88        public boolean isCancelled() {
89                return cancelled;
90        }
91 
92        public boolean isDone() {
93                return latch.getCount() == 0;
94        }
95}

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