Skip to content

Commit ad77a2a

Browse files
fabienrenaudsurybala
authored andcommitted
SPY-187: Expose a few more attributes of MemcachedClient
Motivation ---------- Extending MemcachedClient to access some of its protected attributes is not always desirable as it makes harder writing mocks for unit testing. Modifications ------------- MemcachedClient now exposes operationTimeout, mconn, tcService and executorService. Result ------ One does not have to extend MemcachedClient any more to write custom commands. Change-Id: I81932da64d4492512dcf1a11fe1161203fa70c5e Reviewed-on: http://review.couchbase.org/51546 Reviewed-by: Michael Nitschinger <[email protected]> Tested-by: Michael Nitschinger <[email protected]>
1 parent a77416e commit ad77a2a

File tree

4 files changed

+68
-33
lines changed

4 files changed

+68
-33
lines changed

src/main/java/net/spy/memcached/DefaultConnectionFactory.java

+16
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ public class DefaultConnectionFactory extends SpyObject implements
142142
*/
143143
private ExecutorService executorService;
144144

145+
/**
146+
*Construct a DefaultConnectionFactory with the given parameters.
147+
*
148+
* @param qLen the queue length.
149+
* @param bufSize the buffer size
150+
* @param hash the algorithm to use for hashing
151+
*/
152+
public DefaultConnectionFactory(int qLen, int bufSize, HashAlgorithm hash) {
153+
super();
154+
clientMode = ClientMode.Dynamic;
155+
opQueueLen = qLen;
156+
readBufSize = bufSize;
157+
hashAlg = hash;
158+
metrics = null;
159+
}
160+
145161
/**
146162
* Construct a DefaultConnectionFactory with the given parameters.
147163
*

src/main/java/net/spy/memcached/KetamaConnectionFactory.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public class KetamaConnectionFactory extends DefaultConnectionFactory {
6666
*/
6767
public KetamaConnectionFactory(ClientMode clientMode, int qLen, int bufSize,
6868
long opQueueMaxBlockTime) {
69-
super(clientMode, qLen, bufSize, DefaultHashAlgorithm.KETAMA_HASH);
69+
super(clientMode, qLen, bufSize, DefaultHashAlgorithm.KETAMA_HASH);
70+
this.ketamaNodeKeyFormat = KetamaNodeKeyFormatter.Format.SPYMEMCACHED;
71+
this.weights = new HashMap<InetSocketAddress, Integer>();
7072
}
7173

7274
public KetamaConnectionFactory(int qLen, int bufSize,

src/main/java/net/spy/memcached/MemcachedClient.java

+44-28
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,6 @@
3434

3535
package net.spy.memcached;
3636

37-
import java.io.IOException;
38-
import java.net.InetSocketAddress;
39-
import java.net.SocketAddress;
40-
import java.text.MessageFormat;
41-
import java.util.ArrayList;
42-
import java.util.Arrays;
43-
import java.util.Collection;
44-
import java.util.Collections;
45-
import java.util.HashMap;
46-
import java.util.Iterator;
47-
import java.util.List;
48-
import java.util.Map;
49-
import java.util.Set;
50-
import java.util.concurrent.CancellationException;
51-
import java.util.concurrent.ConcurrentHashMap;
52-
import java.util.concurrent.ConcurrentLinkedQueue;
53-
import java.util.concurrent.ConcurrentMap;
54-
import java.util.concurrent.CountDownLatch;
55-
import java.util.concurrent.ExecutionException;
56-
import java.util.concurrent.ExecutorService;
57-
import java.util.concurrent.Future;
58-
import java.util.concurrent.TimeUnit;
59-
import java.util.concurrent.TimeoutException;
60-
import java.util.concurrent.atomic.AtomicInteger;
61-
import java.util.concurrent.atomic.AtomicLong;
62-
import java.util.concurrent.atomic.AtomicReference;
63-
6437
import net.spy.memcached.auth.AuthDescriptor;
6538
import net.spy.memcached.auth.AuthThreadMonitor;
6639
import net.spy.memcached.compat.SpyObject;
@@ -95,13 +68,39 @@
9568
import net.spy.memcached.ops.StoreOperation;
9669
import net.spy.memcached.ops.StoreType;
9770
import net.spy.memcached.ops.TimedOutOperationStatus;
98-
import net.spy.memcached.protocol.ascii.AsciiOperationFactory;
9971
import net.spy.memcached.protocol.binary.BinaryOperationFactory;
10072
import net.spy.memcached.transcoders.SerializingTranscoder;
10173
import net.spy.memcached.transcoders.TranscodeService;
10274
import net.spy.memcached.transcoders.Transcoder;
10375
import net.spy.memcached.util.StringUtils;
10476

77+
import java.io.IOException;
78+
import java.net.InetSocketAddress;
79+
import java.net.SocketAddress;
80+
import java.text.MessageFormat;
81+
import java.util.ArrayList;
82+
import java.util.Arrays;
83+
import java.util.Collection;
84+
import java.util.Collections;
85+
import java.util.HashMap;
86+
import java.util.Iterator;
87+
import java.util.List;
88+
import java.util.Map;
89+
import java.util.Set;
90+
import java.util.concurrent.CancellationException;
91+
import java.util.concurrent.ConcurrentHashMap;
92+
import java.util.concurrent.ConcurrentLinkedQueue;
93+
import java.util.concurrent.ConcurrentMap;
94+
import java.util.concurrent.CountDownLatch;
95+
import java.util.concurrent.ExecutionException;
96+
import java.util.concurrent.ExecutorService;
97+
import java.util.concurrent.Future;
98+
import java.util.concurrent.TimeUnit;
99+
import java.util.concurrent.TimeoutException;
100+
import java.util.concurrent.atomic.AtomicInteger;
101+
import java.util.concurrent.atomic.AtomicLong;
102+
import java.util.concurrent.atomic.AtomicReference;
103+
105104
/**
106105
* Client to a memcached server.
107106
*
@@ -3062,8 +3061,25 @@ void setIsConfigurtionInitialized(boolean isConfigurationInitialized){
30623061
this.isConfigurationInitialized = isConfigurationInitialized;
30633062
}
30643063

3064+
public long getOperationTimeout() {
3065+
return operationTimeout;
3066+
}
3067+
3068+
public MemcachedConnection getConnection() {
3069+
return mconn;
3070+
}
3071+
3072+
public TranscodeService getTranscoderService() {
3073+
return tcService;
3074+
}
3075+
3076+
public ExecutorService getExecutorService() {
3077+
return executorService;
3078+
}
3079+
30653080
@Override
30663081
public String toString() {
30673082
return connFactory.toString();
30683083
}
30693084
}
3085+

src/main/java/net/spy/memcached/MemcachedClientIF.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
package net.spy.memcached;
2525

26+
import net.spy.memcached.internal.BulkFuture;
27+
import net.spy.memcached.internal.OperationFuture;
28+
import net.spy.memcached.transcoders.Transcoder;
29+
2630
import java.net.SocketAddress;
2731
import java.util.Collection;
2832
import java.util.Iterator;
@@ -32,10 +36,6 @@
3236
import java.util.concurrent.Future;
3337
import java.util.concurrent.TimeUnit;
3438

35-
import net.spy.memcached.internal.BulkFuture;
36-
import net.spy.memcached.internal.OperationFuture;
37-
import net.spy.memcached.transcoders.Transcoder;
38-
3939
/**
4040
* This interface is provided as a helper for testing clients of the
4141
* MemcachedClient.
@@ -240,4 +240,5 @@ CountDownLatch broadcastOp(final BroadcastOpFactory of,
240240
* @return the union of all SASL mechanisms supported by the servers.
241241
*/
242242
Set<String> listSaslMechanisms();
243+
243244
}

0 commit comments

Comments
 (0)