Skip to content

Commit 9f9ddd5

Browse files
extract duplicate logic into a private helper function
1 parent 9745869 commit 9f9ddd5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,11 @@ private MemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs, boo
255255
String hostName = addrs.get(0).getHostName();
256256
//All config endpoints has ".cfg." subdomain in the DNS name.
257257
if(hostName != null && hostName.contains(".cfg.")){
258-
if (cf == null) {
259-
cf = new DefaultConnectionFactory(ClientMode.Dynamic);
260-
} else {
261-
cf.setClientMode(ClientMode.Dynamic);
262-
}
258+
cf = updateClientMode(cf, ClientMode.Dynamic);
263259
}
264260
}
265261
//Fallback to static mode
266-
if (cf == null) {
267-
cf = new DefaultConnectionFactory(ClientMode.Static);
268-
} else {
269-
cf.setClientMode(ClientMode.Static);
270-
}
262+
cf = updateClientMode(cf, ClientMode.Static);
271263
}
272264

273265
if (cf == null) {
@@ -302,7 +294,16 @@ private MemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs, boo
302294
addObserver(this);
303295
}
304296
}
305-
297+
298+
private ConnectionFactory updateClientMode(ConnectionFactory f, ClientMode mode) {
299+
if (f == null) {
300+
f = new DefaultConnectionFactory(mode);
301+
} else {
302+
f.setClientMode(mode);
303+
}
304+
return f;
305+
}
306+
306307
/**
307308
* Establish a connection to the configuration endpoint and get the list of cache node endpoints. Then initialize the
308309
* memcached client with the cache node endpoints list.

0 commit comments

Comments
 (0)