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

COVERAGE SUMMARY FOR SOURCE FILE [DefaultConnectionFactory.java]

nameclass, %method, %block, %line, %
DefaultConnectionFactory.java100% (1/1)100% (22/22)91%  (129/141)97%  (33/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultConnectionFactory100% (1/1)100% (22/22)91%  (129/141)97%  (33/34)
createMemcachedNode (SocketAddress, SocketChannel, int): MemcachedNode 100% (1/1)74%  (35/47)83%  (5/6)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)
DefaultConnectionFactory (): void 100% (1/1)100% (5/5)100% (2/2)
DefaultConnectionFactory (int, int): void 100% (1/1)100% (6/6)100% (2/2)
DefaultConnectionFactory (int, int, HashAlgorithm): void 100% (1/1)100% (12/12)100% (5/5)
createConnection (List): MemcachedConnection 100% (1/1)100% (14/14)100% (1/1)
createLocator (List): NodeLocator 100% (1/1)100% (7/7)100% (1/1)
createOperationQueue (): BlockingQueue 100% (1/1)100% (6/6)100% (1/1)
createReadOperationQueue (): BlockingQueue 100% (1/1)100% (4/4)100% (1/1)
createWriteOperationQueue (): BlockingQueue 100% (1/1)100% (4/4)100% (1/1)
getDefaultTranscoder (): Transcoder 100% (1/1)100% (4/4)100% (1/1)
getFailureMode (): FailureMode 100% (1/1)100% (2/2)100% (1/1)
getHashAlg (): HashAlgorithm 100% (1/1)100% (3/3)100% (1/1)
getInitialObservers (): Collection 100% (1/1)100% (2/2)100% (1/1)
getMaxReconnectDelay (): long 100% (1/1)100% (2/2)100% (1/1)
getOpQueueLen (): int 100% (1/1)100% (3/3)100% (1/1)
getOperationFactory (): OperationFactory 100% (1/1)100% (4/4)100% (1/1)
getOperationTimeout (): long 100% (1/1)100% (2/2)100% (1/1)
getReadBufSize (): int 100% (1/1)100% (3/3)100% (1/1)
isDaemon (): boolean 100% (1/1)100% (2/2)100% (1/1)
shouldOptimize (): boolean 100% (1/1)100% (2/2)100% (1/1)
useNagleAlgorithm (): boolean 100% (1/1)100% (2/2)100% (1/1)

1package net.spy.memcached;
2 
3import java.io.IOException;
4import java.net.InetSocketAddress;
5import java.net.SocketAddress;
6import java.nio.channels.SocketChannel;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.List;
10import java.util.concurrent.ArrayBlockingQueue;
11import java.util.concurrent.BlockingQueue;
12import java.util.concurrent.LinkedBlockingQueue;
13 
14import net.spy.memcached.compat.SpyObject;
15import net.spy.memcached.ops.Operation;
16import net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl;
17import net.spy.memcached.protocol.ascii.AsciiOperationFactory;
18import net.spy.memcached.protocol.binary.BinaryMemcachedNodeImpl;
19import net.spy.memcached.protocol.binary.BinaryOperationFactory;
20import net.spy.memcached.transcoders.SerializingTranscoder;
21import net.spy.memcached.transcoders.Transcoder;
22 
23/**
24 * Default implementation of ConnectionFactory.
25 *
26 * <p>
27 * This implementation creates connections where the operation queue is an
28 * ArrayBlockingQueue and the read and write queues are unbounded
29 * LinkedBlockingQueues.  The <code>Redistribute</code> FailureMode is used
30 * by default.
31 * </p>
32 */
33public class DefaultConnectionFactory extends SpyObject
34        implements ConnectionFactory {
35 
36        /**
37         * Default failure mode.
38         */
39        public static final FailureMode DEFAULT_FAILURE_MODE =
40                FailureMode.Redistribute;
41 
42        /**
43         * Default hash algorithm.
44         */
45        public static final HashAlgorithm DEFAULT_HASH = HashAlgorithm.NATIVE_HASH;
46 
47        /**
48         * Maximum length of the operation queue returned by this connection
49         * factory.
50         */
51        public static final int DEFAULT_OP_QUEUE_LEN=16384;
52 
53        /**
54         * The read buffer size for each server connection from this factory.
55         */
56        public static final int DEFAULT_READ_BUFFER_SIZE=16384;
57 
58    /**
59     * Default operation timeout in milliseconds.
60     */
61    public static final long DEFAULT_OPERATION_TIMEOUT = 1000;
62 
63    /**
64     * Maximum amount of time (in seconds) to wait between reconnect attempts.
65     */
66    public static final long DEFAULT_MAX_RECONNECT_DELAY = 30;
67 
68        private final int opQueueLen;
69        private final int readBufSize;
70        private final HashAlgorithm hashAlg;
71 
72        /**
73         * Construct a DefaultConnectionFactory with the given parameters.
74         *
75         * @param qLen the queue length.
76         * @param bufSize the buffer size
77         * @param hash the algorithm to use for hashing
78         */
79        public DefaultConnectionFactory(int qLen, int bufSize, HashAlgorithm hash) {
80                super();
81                opQueueLen=qLen;
82                readBufSize=bufSize;
83                hashAlg=hash;
84        }
85 
86        /**
87         * Create a DefaultConnectionFactory with the given maximum operation
88         * queue length, and the given read buffer size.
89         */
90        public DefaultConnectionFactory(int qLen, int bufSize) {
91                this(qLen, bufSize, DEFAULT_HASH);
92        }
93 
94        /**
95         * Create a DefaultConnectionFactory with the default parameters.
96         */
97        public DefaultConnectionFactory() {
98                this(DEFAULT_OP_QUEUE_LEN, DEFAULT_READ_BUFFER_SIZE);
99        }
100 
101        public MemcachedNode createMemcachedNode(SocketAddress sa,
102                        SocketChannel c, int bufSize) {
103 
104                OperationFactory of = getOperationFactory();
105                if(of instanceof AsciiOperationFactory) {
106                        return new AsciiMemcachedNodeImpl(sa, c, bufSize,
107                                createReadOperationQueue(),
108                                createWriteOperationQueue(),
109                                createOperationQueue());
110                } else if(of instanceof BinaryOperationFactory) {
111                        return new BinaryMemcachedNodeImpl(sa, c, bufSize,
112                                        createReadOperationQueue(),
113                                        createWriteOperationQueue(),
114                                        createOperationQueue());
115                } else {
116                        throw new IllegalStateException(
117                                "Unhandled operation factory type " + of);
118                }
119        }
120 
121        /* (non-Javadoc)
122         * @see net.spy.memcached.ConnectionFactory#createConnection(java.util.List)
123         */
124        public MemcachedConnection createConnection(List<InetSocketAddress> addrs)
125                throws IOException {
126                return new MemcachedConnection(getReadBufSize(), this, addrs,
127                        getInitialObservers(), getFailureMode(), getOperationFactory());
128        }
129 
130        /* (non-Javadoc)
131         * @see net.spy.memcached.ConnectionFactory#getFailureMode()
132         */
133        public FailureMode getFailureMode() {
134                return DEFAULT_FAILURE_MODE;
135        }
136 
137        /* (non-Javadoc)
138         * @see net.spy.memcached.ConnectionFactory#createOperationQueue()
139         */
140        public BlockingQueue<Operation> createOperationQueue() {
141                return new ArrayBlockingQueue<Operation>(getOpQueueLen());
142        }
143 
144        /* (non-Javadoc)
145         * @see net.spy.memcached.ConnectionFactory#createReadOperationQueue()
146         */
147        public BlockingQueue<Operation> createReadOperationQueue() {
148                return new LinkedBlockingQueue<Operation>();
149        }
150 
151        /* (non-Javadoc)
152         * @see net.spy.memcached.ConnectionFactory#createWriteOperationQueue()
153         */
154        public BlockingQueue<Operation> createWriteOperationQueue() {
155                return new LinkedBlockingQueue<Operation>();
156        }
157 
158        /* (non-Javadoc)
159         * @see net.spy.memcached.ConnectionFactory#createLocator(java.util.List)
160         */
161        public NodeLocator createLocator(List<MemcachedNode> nodes) {
162                return new ArrayModNodeLocator(nodes, getHashAlg());
163        }
164 
165        /**
166         * Get the op queue length set at construct time.
167         */
168        public int getOpQueueLen() {
169                return opQueueLen;
170        }
171 
172        /* (non-Javadoc)
173         * @see net.spy.memcached.ConnectionFactory#getReadBufSize()
174         */
175        public int getReadBufSize() {
176                return readBufSize;
177        }
178 
179        /* (non-Javadoc)
180         * @see net.spy.memcached.ConnectionFactory#getHashAlg()
181         */
182        public HashAlgorithm getHashAlg() {
183                return hashAlg;
184        }
185 
186        /* (non-Javadoc)
187         * @see net.spy.memcached.ConnectionFactory#getOperationFactory()
188         */
189        public OperationFactory getOperationFactory() {
190                return new AsciiOperationFactory();
191        }
192 
193        /* (non-Javadoc)
194         * @see net.spy.memcached.ConnectionFactory#getOperationTimeout()
195         */
196        public long getOperationTimeout() {
197                return DEFAULT_OPERATION_TIMEOUT;
198        }
199 
200        /* (non-Javadoc)
201         * @see net.spy.memcached.ConnectionFactory#isDaemon()
202         */
203        public boolean isDaemon() {
204                return false;
205        }
206 
207        /* (non-Javadoc)
208         * @see net.spy.memcached.ConnectionFactory#getInitialObservers()
209         */
210        public Collection<ConnectionObserver> getInitialObservers() {
211                return Collections.emptyList();
212        }
213 
214        /* (non-Javadoc)
215         * @see net.spy.memcached.ConnectionFactory#getDefaultTranscoder()
216         */
217        public Transcoder<Object> getDefaultTranscoder() {
218                return new SerializingTranscoder();
219        }
220 
221        /* (non-Javadoc)
222         * @see net.spy.memcached.ConnectionFactory#useNagleAlgorithm()
223         */
224        public boolean useNagleAlgorithm() {
225                return false;
226        }
227 
228        /* (non-Javadoc)
229         * @see net.spy.memcached.ConnectionFactory#shouldOptimize()
230         */
231        public boolean shouldOptimize() {
232                return true;
233        }
234 
235        /* (non-Javadoc)
236         * @see net.spy.memcached.ConnectionFactory#getMaxReconnectDelay()
237         */
238        public long getMaxReconnectDelay() {
239                return DEFAULT_MAX_RECONNECT_DELAY;
240        }
241 
242}

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