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

COVERAGE SUMMARY FOR SOURCE FILE [BinaryMemcachedNodeImpl.java]

nameclass, %method, %block, %line, %
BinaryMemcachedNodeImpl.java100% (1/1)100% (5/5)94%  (170/180)98%  (36.2/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BinaryMemcachedNodeImpl100% (1/1)100% (5/5)94%  (170/180)98%  (36.2/37)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
optimizeSets (): void 100% (1/1)93%  (57/61)98%  (11.7/12)
optimizeGets (): void 100% (1/1)95%  (75/79)98%  (13.7/14)
BinaryMemcachedNodeImpl (SocketAddress, SocketChannel, int, BlockingQueue, Bl... 100% (1/1)100% (15/15)100% (4/4)
optimize (): void 100% (1/1)100% (17/17)100% (6/6)

1package net.spy.memcached.protocol.binary;
2 
3import java.net.SocketAddress;
4import java.nio.channels.SocketChannel;
5import java.util.concurrent.BlockingQueue;
6 
7import net.spy.memcached.ops.CASOperation;
8import net.spy.memcached.ops.GetOperation;
9import net.spy.memcached.ops.Operation;
10import net.spy.memcached.ops.OperationState;
11import net.spy.memcached.ops.StoreOperation;
12import net.spy.memcached.protocol.ProxyCallback;
13import net.spy.memcached.protocol.TCPMemcachedNodeImpl;
14 
15/**
16 * Implementation of MemcachedNode for speakers of the binary protocol.
17 */
18public class BinaryMemcachedNodeImpl extends TCPMemcachedNodeImpl {
19 
20        private final int MAX_SET_OPTIMIZATION_COUNT = 65535;
21        private final int MAX_SET_OPTIMIZATION_BYTES = 2 * 1024 * 1024;
22 
23        public BinaryMemcachedNodeImpl(SocketAddress sa, SocketChannel c,
24                        int bufSize, BlockingQueue<Operation> rq,
25                        BlockingQueue<Operation> wq, BlockingQueue<Operation> iq) {
26                super(sa, c, bufSize, rq, wq, iq);
27        }
28 
29        @Override
30        protected void optimize() {
31                Operation firstOp = writeQ.peek();
32                if(firstOp instanceof GetOperation) {
33                        optimizeGets();
34                } else if(firstOp instanceof CASOperation) {
35                        optimizeSets();
36                }
37        }
38 
39        private void optimizeGets() {
40                // make sure there are at least two get operations in a row before
41                // attempting to optimize them.
42                optimizedOp=writeQ.remove();
43                if(writeQ.peek() instanceof GetOperation) {
44                        OptimizedGetImpl og=new OptimizedGetImpl(
45                                        (GetOperation)optimizedOp);
46                        optimizedOp=og;
47 
48                        while(writeQ.peek() instanceof GetOperation) {
49                                GetOperation o=(GetOperation) writeQ.remove();
50                                if(!o.isCancelled()) {
51                                        og.addOperation(o);
52                                }
53                        }
54 
55                        // Initialize the new mega get
56                        optimizedOp.initialize();
57                        assert optimizedOp.getState() == OperationState.WRITING;
58                        ProxyCallback pcb=(ProxyCallback) og.getCallback();
59                        getLogger().debug("Set up %s with %s keys and %s callbacks",
60                                        this, pcb.numKeys(), pcb.numCallbacks());
61                }
62        }
63 
64        private void optimizeSets() {
65                // make sure there are at least two get operations in a row before
66                // attempting to optimize them.
67                optimizedOp=writeQ.remove();
68                if(writeQ.peek() instanceof CASOperation) {
69                        OptimizedSetImpl og=new OptimizedSetImpl(
70                                        (CASOperation)optimizedOp);
71                        optimizedOp=og;
72 
73                        while(writeQ.peek() instanceof StoreOperation
74                                        && og.size() < MAX_SET_OPTIMIZATION_COUNT
75                                        && og.bytes() < MAX_SET_OPTIMIZATION_BYTES) {
76                                CASOperation o=(CASOperation) writeQ.remove();
77                                if(!o.isCancelled()) {
78                                        og.addOperation(o);
79                                }
80                        }
81 
82                        // Initialize the new mega set
83                        optimizedOp.initialize();
84                        assert optimizedOp.getState() == OperationState.WRITING;
85                }
86        }
87}

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