3333import net .spy .memcached .compat .SpyObject ;
3434import net .spy .memcached .config .ClusterConfiguration ;
3535import net .spy .memcached .ConfigurationPoller ;
36+ import net .spy .memcached .config .ConfigEndpointSelectionStrategy ;
3637import net .spy .memcached .config .NodeEndPoint ;
3738import net .spy .memcached .internal .BulkFuture ;
3839import net .spy .memcached .internal .BulkGetFuture ;
@@ -191,12 +192,14 @@ public class MemcachedClient extends SpyObject implements MemcachedClientIF,
191192
192193 protected final ExecutorService executorService ;
193194
195+ protected final ConfigEndpointSelectionStrategy configEndpointSelectionStrategy ;
196+
194197 private NodeEndPoint configurationNode ;
195198 //Set default value to true to attempt config API first. The value is set to false if
196199 //OperationNotSupportedException is thrown.
197200 private boolean isConfigurationProtocolSupported = true ;
198201
199- //This is used to dynamic mode to track whether the client is initialized with set of cache nodes for the first time.
202+ // This is used in dynamic mode to track whether the client is initialized with a set of cache nodes for the first time.
200203 private boolean isConfigurationInitialized = false ;
201204
202205 private Transcoder <Object > configTranscoder = new SerializingTranscoder ();
@@ -290,6 +293,8 @@ private MemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs, boo
290293 authDescriptor = cf .getAuthDescriptor ();
291294 executorService = cf .getListenerExecutorService ();
292295
296+ configEndpointSelectionStrategy = cf .getConfigEndpointSelectionStrategy ();
297+
293298 if (clientMode == ClientMode .Dynamic ){
294299 initializeClientUsingConfigEndPoint (cf , addrs .get (0 ));
295300 } else {
@@ -352,14 +357,14 @@ private void initializeClientUsingConfigEndPoint(ConnectionFactory cf, InetSocke
352357 }
353358
354359 //Initialize and start the poller.
355- configPoller = new ConfigurationPoller (this , cf .getDynamicModePollingInterval (), cf .isDaemon ());
360+ configPoller = new ConfigurationPoller (this , cf .getDynamicModePollingInterval (), cf .isDaemon (), configEndpointSelectionStrategy );
356361 configPoller .subscribeForClusterConfiguration (mconn );
357362 }
358363
359364 private void setupConnection (ConnectionFactory cf , List <InetSocketAddress > addrs )
360365 throws IOException {
361366
362- mconn = cf . createConnection ( addrs );
367+ mconn = configEndpointSelectionStrategy . setupMemcachedConnection ( cf , addrs );
363368 assert mconn != null : "Connection factory failed to make a connection" ;
364369 }
365370
@@ -1291,7 +1296,7 @@ public void complete() {
12911296 }
12921297 });
12931298 rv .setOperation (op );
1294- mconn .enqueueOperation (sa , op );
1299+ configEndpointSelectionStrategy . getConfigConnection () .enqueueOperation (sa , op );
12951300
12961301 return rv ;
12971302 }
@@ -1996,7 +2001,7 @@ public void complete() {
19962001 }
19972002 });
19982003 rv .setOperation (op );
1999- mconn .enqueueOperation (addr , op );
2004+ configEndpointSelectionStrategy . getConfigConnection () .enqueueOperation (addr , op );
20002005 return rv ;
20012006 }
20022007
@@ -2046,7 +2051,7 @@ public void complete() {
20462051 }
20472052 });
20482053 rv .setOperation (op );
2049- mconn .enqueueOperation (addr , op );
2054+ configEndpointSelectionStrategy . getConfigConnection () .enqueueOperation (addr , op );
20502055 return rv ;
20512056 }
20522057
@@ -2073,7 +2078,7 @@ public void complete() {
20732078 }
20742079 });
20752080 rv .setOperation (op );
2076- mconn .enqueueOperation (addr , op );
2081+ configEndpointSelectionStrategy . getConfigConnection () .enqueueOperation (addr , op );
20772082 return rv ;
20782083 }
20792084
@@ -2988,6 +2993,7 @@ public boolean shutdown(long timeout, TimeUnit unit) {
29882993 mconn .setName (baseName + " - SHUTTING DOWN (telling client)" );
29892994 mconn .shutdown ();
29902995 mconn .setName (baseName + " - SHUTTING DOWN (informed client)" );
2996+ configEndpointSelectionStrategy .shutdownConfigConnection ();
29912997 tcService .shutdown ();
29922998 //terminate all pending Auth Threads
29932999 authMonitor .interruptAllPendingAuth ();
0 commit comments