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

COVERAGE SUMMARY FOR SOURCE FILE [ConnectionFactoryBuilder.java]

nameclass, %method, %block, %line, %
ConnectionFactoryBuilder.java100% (5/5)92%  (54/59)86%  (416/483)91%  (65.5/72)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ConnectionFactoryBuilder100% (1/1)94%  (32/34)83%  (169/204)92%  (44.9/49)
access$1400 (ConnectionFactoryBuilder): long 0%   (0/1)0%   (0/3)0%   (0/1)
setMaxReconnectDelay (long): ConnectionFactoryBuilder 0%   (0/1)0%   (0/16)0%   (0/3)
setProtocol (ConnectionFactoryBuilder$Protocol): ConnectionFactoryBuilder 100% (1/1)58%  (19/33)86%  (6/7)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
ConnectionFactoryBuilder (): void 100% (1/1)100% (27/27)100% (10/10)
access$000 (ConnectionFactoryBuilder): OperationQueueFactory 100% (1/1)100% (3/3)100% (1/1)
access$100 (ConnectionFactoryBuilder): OperationQueueFactory 100% (1/1)100% (3/3)100% (1/1)
access$1000 (ConnectionFactoryBuilder): int 100% (1/1)100% (3/3)100% (1/1)
access$1100 (ConnectionFactoryBuilder): boolean 100% (1/1)100% (3/3)100% (1/1)
access$1200 (ConnectionFactoryBuilder): boolean 100% (1/1)100% (3/3)100% (1/1)
access$1300 (ConnectionFactoryBuilder): boolean 100% (1/1)100% (3/3)100% (1/1)
access$200 (ConnectionFactoryBuilder): OperationQueueFactory 100% (1/1)100% (3/3)100% (1/1)
access$300 (ConnectionFactoryBuilder): ConnectionFactoryBuilder$Locator 100% (1/1)100% (3/3)100% (1/1)
access$400 (ConnectionFactoryBuilder): Transcoder 100% (1/1)100% (3/3)100% (1/1)
access$500 (ConnectionFactoryBuilder): FailureMode 100% (1/1)100% (3/3)100% (1/1)
access$600 (ConnectionFactoryBuilder): HashAlgorithm 100% (1/1)100% (3/3)100% (1/1)
access$700 (ConnectionFactoryBuilder): Collection 100% (1/1)100% (3/3)100% (1/1)
access$800 (ConnectionFactoryBuilder): OperationFactory 100% (1/1)100% (3/3)100% (1/1)
access$900 (ConnectionFactoryBuilder): long 100% (1/1)100% (3/3)100% (1/1)
build (): ConnectionFactory 100% (1/1)100% (5/5)100% (1/1)
setDaemon (boolean): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setFailureMode (FailureMode): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setHashAlg (HashAlgorithm): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setInitialObservers (Collection): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setLocatorType (ConnectionFactoryBuilder$Locator): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setOpFact (OperationFactory): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setOpQueueFactory (OperationQueueFactory): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setOpTimeout (long): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setReadBufferSize (int): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setReadOpQueueFactory (OperationQueueFactory): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setShouldOptimize (boolean): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setTranscoder (Transcoder): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setUseNagleAlgorithm (boolean): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
setWriteOpQueueFactory (OperationQueueFactory): ConnectionFactoryBuilder 100% (1/1)100% (5/5)100% (2/2)
     
class ConnectionFactoryBuilder$Locator100% (1/1)75%  (3/4)87%  (33/38)95%  (2.9/3)
valueOf (String): ConnectionFactoryBuilder$Locator 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (24/24)100% (3/3)
ConnectionFactoryBuilder$Locator (String, int): void 100% (1/1)100% (5/5)100% (1/1)
values (): ConnectionFactoryBuilder$Locator [] 100% (1/1)100% (4/4)100% (1/1)
     
class ConnectionFactoryBuilder$Protocol100% (1/1)75%  (3/4)87%  (33/38)95%  (2.9/3)
valueOf (String): ConnectionFactoryBuilder$Protocol 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (24/24)100% (3/3)
ConnectionFactoryBuilder$Protocol (String, int): void 100% (1/1)100% (5/5)100% (1/1)
values (): ConnectionFactoryBuilder$Protocol [] 100% (1/1)100% (4/4)100% (1/1)
     
class ConnectionFactoryBuilder$1100% (1/1)94%  (15/16)89%  (148/166)89%  (17/19)
getMaxReconnectDelay (): long 0%   (0/1)0%   (0/4)0%   (0/1)
createLocator (List): NodeLocator 100% (1/1)60%  (21/35)75%  (3/4)
ConnectionFactoryBuilder$1 (ConnectionFactoryBuilder): void 100% (1/1)100% (6/6)100% (1/1)
createOperationQueue (): BlockingQueue 100% (1/1)100% (12/12)100% (1/1)
createReadOperationQueue (): BlockingQueue 100% (1/1)100% (12/12)100% (1/1)
createWriteOperationQueue (): BlockingQueue 100% (1/1)100% (12/12)100% (1/1)
getDefaultTranscoder (): Transcoder 100% (1/1)100% (11/11)100% (1/1)
getFailureMode (): FailureMode 100% (1/1)100% (11/11)100% (1/1)
getHashAlg (): HashAlgorithm 100% (1/1)100% (11/11)100% (1/1)
getInitialObservers (): Collection 100% (1/1)100% (4/4)100% (1/1)
getOperationFactory (): OperationFactory 100% (1/1)100% (11/11)100% (1/1)
getOperationTimeout (): long 100% (1/1)100% (13/13)100% (1/1)
getReadBufSize (): int 100% (1/1)100% (12/12)100% (1/1)
isDaemon (): boolean 100% (1/1)100% (4/4)100% (1/1)
shouldOptimize (): boolean 100% (1/1)100% (4/4)100% (1/1)
useNagleAlgorithm (): boolean 100% (1/1)100% (4/4)100% (1/1)
     
class ConnectionFactoryBuilder$2100% (1/1)100% (1/1)89%  (33/37)88%  (1.8/2)
<static initializer> 100% (1/1)89%  (33/37)88%  (1.8/2)

1package net.spy.memcached;
2 
3import java.util.Collection;
4import java.util.Collections;
5import java.util.List;
6import java.util.concurrent.BlockingQueue;
7 
8import net.spy.memcached.ops.Operation;
9import net.spy.memcached.ops.OperationQueueFactory;
10import net.spy.memcached.protocol.ascii.AsciiOperationFactory;
11import net.spy.memcached.protocol.binary.BinaryOperationFactory;
12import net.spy.memcached.transcoders.Transcoder;
13 
14/**
15 * Builder for more easily configuring a ConnectionFactory.
16 */
17public class ConnectionFactoryBuilder {
18 
19        private OperationQueueFactory opQueueFactory;
20        private OperationQueueFactory readQueueFactory;
21        private OperationQueueFactory writeQueueFactory;
22 
23        private Transcoder<Object> transcoder;
24 
25        private FailureMode failureMode;
26 
27        private Collection<ConnectionObserver> initialObservers
28                = Collections.emptyList();
29 
30        private OperationFactory opFact;
31 
32        private Locator locator = Locator.ARRAY_MOD;
33        private long opTimeout = -1;
34        private boolean isDaemon = true;
35        private boolean shouldOptimize = true;
36        private boolean useNagle = false;
37        private long maxReconnectDelay =
38                DefaultConnectionFactory.DEFAULT_MAX_RECONNECT_DELAY;
39 
40        private int readBufSize = -1;
41        private HashAlgorithm hashAlg;
42 
43        /**
44         * Set the operation queue factory.
45         */
46        public ConnectionFactoryBuilder setOpQueueFactory(OperationQueueFactory q) {
47                opQueueFactory = q;
48                return this;
49        }
50 
51        /**
52         * Set the read queue factory.
53         */
54        public ConnectionFactoryBuilder setReadOpQueueFactory(OperationQueueFactory q) {
55                readQueueFactory = q;
56                return this;
57        }
58 
59        /**
60         * Set the write queue factory.
61         */
62        public ConnectionFactoryBuilder setWriteOpQueueFactory(OperationQueueFactory q) {
63                writeQueueFactory = q;
64                return this;
65        }
66 
67        /**
68         * Set the default transcoder.
69         */
70        public ConnectionFactoryBuilder setTranscoder(Transcoder<Object> t) {
71                transcoder = t;
72                return this;
73        }
74 
75        /**
76         * Set the failure mode.
77         */
78        public ConnectionFactoryBuilder setFailureMode(FailureMode fm) {
79                failureMode = fm;
80                return this;
81        }
82 
83        /**
84         * Set the initial connection observers (will observe initial connection).
85         */
86        public ConnectionFactoryBuilder setInitialObservers(
87                        Collection<ConnectionObserver> obs) {
88                initialObservers = obs;
89                return this;
90        }
91 
92        /**
93         * Set the operation factory.
94         *
95         * Note that the operation factory is used to also imply the type of
96         * nodes to create.
97         *
98         * @see MemcachedNode
99         */
100        public ConnectionFactoryBuilder setOpFact(OperationFactory f) {
101                opFact = f;
102                return this;
103        }
104 
105        /**
106         * Set the default operation timeout in milliseconds.
107         */
108        public ConnectionFactoryBuilder setOpTimeout(long t) {
109                opTimeout = t;
110                return this;
111        }
112 
113        /**
114         * Set the daemon state of the IO thread (defaults to true).
115         */
116        public ConnectionFactoryBuilder setDaemon(boolean d) {
117                isDaemon = d;
118                return this;
119        }
120 
121        /**
122         * Set to false if the default operation optimization is not desirable.
123         */
124        public ConnectionFactoryBuilder setShouldOptimize(boolean o) {
125                shouldOptimize = o;
126                return this;
127        }
128 
129        /**
130         * Set the read buffer size.
131         */
132        public ConnectionFactoryBuilder setReadBufferSize(int to) {
133                readBufSize = to;
134                return this;
135        }
136 
137        /**
138         * Set the hash algorithm.
139         */
140        public ConnectionFactoryBuilder setHashAlg(HashAlgorithm to) {
141                hashAlg = to;
142                return this;
143        }
144 
145        /**
146         * Set to true if you'd like to enable the Nagle algorithm.
147         */
148        public ConnectionFactoryBuilder setUseNagleAlgorithm(boolean to) {
149                useNagle = to;
150                return this;
151        }
152 
153        /**
154         * Convenience method to specify the protocol to use.
155         */
156        public ConnectionFactoryBuilder setProtocol(Protocol prot) {
157                switch(prot) {
158                        case TEXT:
159                                opFact = new AsciiOperationFactory();
160                                break;
161                        case BINARY:
162                                opFact = new BinaryOperationFactory();
163                                break;
164                        default: assert false : "Unhandled protocol: " + prot;
165                }
166                return this;
167        }
168 
169        /**
170         * Set the locator type.
171         */
172        public ConnectionFactoryBuilder setLocatorType(Locator l) {
173                locator = l;
174                return this;
175        }
176 
177        /**
178         * Set the maximum reconnect delay.
179         */
180        public ConnectionFactoryBuilder setMaxReconnectDelay(long to) {
181                assert to > 0 : "Reconnect delay must be a positive number";
182                maxReconnectDelay = to;
183                return this;
184        }
185 
186        /**
187         * Get the ConnectionFactory set up with the provided parameters.
188         */
189        public ConnectionFactory build() {
190                return new DefaultConnectionFactory() {
191 
192                        @Override
193                        public BlockingQueue<Operation> createOperationQueue() {
194                                return opQueueFactory == null ?
195                                                super.createOperationQueue() : opQueueFactory.create();
196                        }
197 
198                        @Override
199                        public BlockingQueue<Operation> createReadOperationQueue() {
200                                return readQueueFactory == null ?
201                                                super.createReadOperationQueue()
202                                                : readQueueFactory.create();
203                        }
204 
205                        @Override
206                        public BlockingQueue<Operation> createWriteOperationQueue() {
207                                return writeQueueFactory == null ?
208                                                super.createReadOperationQueue()
209                                                : writeQueueFactory.create();
210                        }
211 
212                        @Override
213                        public NodeLocator createLocator(List<MemcachedNode> nodes) {
214                                switch(locator) {
215                                        case ARRAY_MOD:
216                                                return new ArrayModNodeLocator(nodes, getHashAlg());
217                                        case CONSISTENT:
218                                                return new KetamaNodeLocator(nodes, getHashAlg());
219                                        default: throw new IllegalStateException(
220                                                        "Unhandled locator type: " + locator);
221                                }
222                        }
223 
224                        @Override
225                        public Transcoder<Object> getDefaultTranscoder() {
226                                return transcoder == null ?
227                                                super.getDefaultTranscoder() : transcoder;
228                        }
229 
230                        @Override
231                        public FailureMode getFailureMode() {
232                                return failureMode == null ?
233                                                super.getFailureMode() : failureMode;
234                        }
235 
236                        @Override
237                        public HashAlgorithm getHashAlg() {
238                                return hashAlg == null ? super.getHashAlg() : hashAlg;
239                        }
240 
241                        @Override
242                        public Collection<ConnectionObserver> getInitialObservers() {
243                                return initialObservers;
244                        }
245 
246                        @Override
247                        public OperationFactory getOperationFactory() {
248                                return opFact == null ? super.getOperationFactory() : opFact;
249                        }
250 
251                        @Override
252                        public long getOperationTimeout() {
253                                return opTimeout == -1 ?
254                                                super.getOperationTimeout() : opTimeout;
255                        }
256 
257                        @Override
258                        public int getReadBufSize() {
259                                return readBufSize == -1 ?
260                                                super.getReadBufSize() : readBufSize;
261                        }
262 
263                        @Override
264                        public boolean isDaemon() {
265                                return isDaemon;
266                        }
267 
268                        @Override
269                        public boolean shouldOptimize() {
270                                return shouldOptimize;
271                        }
272 
273                        @Override
274                        public boolean useNagleAlgorithm() {
275                                return useNagle;
276                        }
277 
278                        @Override
279                        public long getMaxReconnectDelay() {
280                                return maxReconnectDelay;
281                        }
282 
283                };
284 
285        }
286 
287        /**
288         * Type of protocol to use for connections.
289         */
290        public static enum Protocol {
291                /**
292                 * Use the text (ascii) protocol.
293                 */
294                TEXT,
295                /**
296                 * Use the binary protocol.
297                 */
298                BINARY
299        }
300 
301        /**
302         * Type of node locator to use.
303         */
304        public static enum Locator {
305                /**
306                 * Array modulus - the classic node location algorithm.
307                 */
308                ARRAY_MOD,
309                /**
310                 * Consistent hash algorithm.
311                 *
312                 * This uses ketema's distribution algorithm, but may be used with any
313                 * hash algorithm.
314                 */
315                CONSISTENT
316        }
317}

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