1 | package net.spy.memcached; |
2 | |
3 | import java.util.List; |
4 | |
5 | /** |
6 | * ConnectionFactory instance that sets up a ketama compatible connection. |
7 | * |
8 | * <p> |
9 | * This implementation piggy-backs on the functionality of the |
10 | * <code>DefaultConnectionFactory</code> in terms of connections and queue |
11 | * handling. Where it differs is that it uses both the <code> |
12 | * KetamaNodeLocator</code> and the <code>HashAlgorithm.KETAMA_HASH</code> |
13 | * to provide consistent node hashing. |
14 | * </p> |
15 | * |
16 | * @see <a href="http://www.last.fm/user/RJ/journal/2007/04/10/392555/">RJ's blog post</a> |
17 | */ |
18 | public class KetamaConnectionFactory extends DefaultConnectionFactory { |
19 | /** |
20 | * Create a KetamaConnectionFactory with the given maximum operation |
21 | * queue length, and the given read buffer size. |
22 | */ |
23 | public KetamaConnectionFactory(int qLen, int bufSize) { |
24 | super(qLen, bufSize, HashAlgorithm.KETAMA_HASH); |
25 | } |
26 | |
27 | /** |
28 | * Create a KetamaConnectionFactory with the default parameters. |
29 | */ |
30 | public KetamaConnectionFactory() { |
31 | this(DEFAULT_OP_QUEUE_LEN, DEFAULT_READ_BUFFER_SIZE); |
32 | } |
33 | |
34 | /* (non-Javadoc) |
35 | * @see net.spy.memcached.ConnectionFactory#createLocator(java.util.List) |
36 | */ |
37 | @Override |
38 | public NodeLocator createLocator(List<MemcachedNode> nodes) { |
39 | return new KetamaNodeLocator(nodes, getHashAlg()); |
40 | } |
41 | } |