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

COVERAGE SUMMARY FOR SOURCE FILE [BaseOperationImpl.java]

nameclass, %method, %block, %line, %
BaseOperationImpl.java100% (2/2)95%  (18/19)83%  (179/216)85%  (45.2/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseOperationImpl100% (1/1)94%  (17/18)82%  (156/190)85%  (45.3/53)
handleRead (ByteBuffer): void 0%   (0/1)0%   (0/7)0%   (0/2)
handleError (OperationErrorType, String): void 100% (1/1)59%  (29/49)55%  (6/11)
setBuffer (ByteBuffer): void 100% (1/1)71%  (12/17)86%  (3.4/4)
<static initializer> 100% (1/1)83%  (10/12)92%  (1.8/2)
BaseOperationImpl (): void 100% (1/1)100% (21/21)100% (8/8)
cancel (): void 100% (1/1)100% (9/9)100% (4/4)
getBuffer (): ByteBuffer 100% (1/1)100% (3/3)100% (1/1)
getCallback (): OperationCallback 100% (1/1)100% (3/3)100% (1/1)
getException (): OperationException 100% (1/1)100% (3/3)100% (1/1)
getHandlingNode (): MemcachedNode 100% (1/1)100% (3/3)100% (1/1)
getState (): OperationState 100% (1/1)100% (3/3)100% (1/1)
hasErrored (): boolean 100% (1/1)100% (7/7)100% (1/1)
isCancelled (): boolean 100% (1/1)100% (3/3)100% (1/1)
setCallback (OperationCallback): void 100% (1/1)100% (4/4)100% (2/2)
setHandlingNode (MemcachedNode): void 100% (1/1)100% (4/4)100% (2/2)
transitionState (OperationState): void 100% (1/1)100% (33/33)100% (7/7)
wasCancelled (): void 100% (1/1)100% (5/5)100% (2/2)
writeComplete (): void 100% (1/1)100% (4/4)100% (2/2)
     
class BaseOperationImpl$1100% (1/1)100% (1/1)88%  (23/26)88%  (0.9/1)
<static initializer> 100% (1/1)88%  (23/26)88%  (0.9/1)

1package net.spy.memcached.protocol;
2 
3import java.io.IOException;
4import java.nio.ByteBuffer;
5 
6import net.spy.memcached.MemcachedNode;
7import net.spy.memcached.compat.SpyObject;
8import net.spy.memcached.ops.CancelledOperationStatus;
9import net.spy.memcached.ops.OperationCallback;
10import net.spy.memcached.ops.OperationErrorType;
11import net.spy.memcached.ops.OperationException;
12import net.spy.memcached.ops.OperationState;
13import net.spy.memcached.ops.OperationStatus;
14 
15/**
16 * Base class for protocol-specific operation implementations.
17 */
18public abstract class BaseOperationImpl extends SpyObject {
19 
20        /**
21         * Status object for cancelled operations.
22         */
23        public static final OperationStatus CANCELLED =
24                new CancelledOperationStatus();
25        private OperationState state = OperationState.WRITING;
26        private ByteBuffer cmd = null;
27        private boolean cancelled = false;
28        private OperationException exception = null;
29        protected OperationCallback callback = null;
30        private volatile MemcachedNode handlingNode = null;
31 
32        public BaseOperationImpl() {
33                super();
34        }
35 
36        /**
37         * Get the operation callback associated with this operation.
38         */
39        public final OperationCallback getCallback() {
40                return callback;
41        }
42 
43        /**
44         * Set the callback for this instance.
45         */
46        protected void setCallback(OperationCallback to) {
47                callback=to;
48        }
49 
50        public final boolean isCancelled() {
51                return cancelled;
52        }
53 
54        public final boolean hasErrored() {
55                return exception != null;
56        }
57 
58        public final OperationException getException() {
59                return exception;
60        }
61 
62        public final void cancel() {
63                cancelled=true;
64                wasCancelled();
65                callback.complete();
66        }
67 
68        /**
69         * This is called on each subclass whenever an operation was cancelled.
70         */
71        protected void wasCancelled() {
72                getLogger().debug("was cancelled.");
73        }
74 
75        public final OperationState getState() {
76                return state;
77        }
78 
79        public final ByteBuffer getBuffer() {
80                return cmd;
81        }
82 
83        /**
84         * Set the write buffer for this operation.
85         */
86        protected final void setBuffer(ByteBuffer to) {
87                assert to != null : "Trying to set buffer to null";
88                cmd=to;
89                cmd.mark();
90        }
91 
92        /**
93         * Transition the state of this operation to the given state.
94         */
95        protected final void transitionState(OperationState newState) {
96                getLogger().debug("Transitioned state from %s to %s", state, newState);
97                state=newState;
98                // Discard our buffer when we no longer need it.
99                if(state != OperationState.WRITING) {
100                        cmd=null;
101                }
102                if(state == OperationState.COMPLETE) {
103                        callback.complete();
104                }
105        }
106 
107        public final void writeComplete() {
108                transitionState(OperationState.READING);
109        }
110 
111        public abstract void initialize();
112 
113        public abstract void readFromBuffer(ByteBuffer data) throws IOException;
114 
115        protected void handleError(OperationErrorType eType, String line)
116                throws IOException {
117                getLogger().error("Error:  %s", line);
118                switch(eType) {
119                        case GENERAL:
120                                exception=new OperationException();
121                                break;
122                        case SERVER:
123                                exception=new OperationException(eType, line);
124                                break;
125                        case CLIENT:
126                                exception=new OperationException(eType, line);
127                                break;
128                        default: assert false;
129                }
130                transitionState(OperationState.COMPLETE);
131                throw exception;
132        }
133 
134        public void handleRead(ByteBuffer data) {
135                assert false;
136        }
137 
138        public MemcachedNode getHandlingNode() {
139                return handlingNode;
140        }
141 
142        public void setHandlingNode(MemcachedNode to) {
143                handlingNode = to;
144        }
145 
146}

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