Skip to content

Commit a19e850

Browse files
committed
Allowing configuration of the SockIOPool, and acquisition of new config objects by the client.
1 parent 9fcc438 commit a19e850

File tree

3 files changed

+138
-253
lines changed

3 files changed

+138
-253
lines changed

src/main/java/edu/usc/cs550/rejig/client/MemcachedClient.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package edu.usc.cs550.rejig.client;
1919

20+
import edu.usc.cs550.rejig.client.configreader.RejigConfigReader;
2021
import edu.usc.cs550.rejig.interfaces.Fragment;
2122
import edu.usc.cs550.rejig.interfaces.RejigConfig;
2223

@@ -156,6 +157,7 @@
156157
* @author Kevin Burton <[email protected]>
157158
* @author Robert Watts <[email protected]>
158159
* @author Vin Chawla <[email protected]>
160+
* @author Likhit Dharmapuri <[email protected]>
159161
* @version 1.5
160162
*/
161163
public class MemcachedClient {
@@ -216,6 +218,9 @@ public class MemcachedClient {
216218
// pool instance
217219
private AtomicReference<SockIOPool> currentPool;
218220

221+
// sockiopool initialization options.
222+
SockIOPool.SockIOPoolOptions poolOptions;
223+
219224
// which pool to use
220225
private String poolNamePrefix;
221226

@@ -225,11 +230,18 @@ public class MemcachedClient {
225230
// optional error handler
226231
private ErrorHandler errorHandler;
227232

233+
// config reader
234+
RejigConfigReader configReader;
235+
228236
/**
229237
* Creates a new instance of MemCachedClient.
238+
* @param reader The reader to use to accquire and update the RejigConfig object used to create the SockIOPool.
239+
* @param options The options on the SockIOPool maintained by this client.
230240
*/
231-
public MemcachedClient() {
241+
public MemcachedClient( RejigConfigReader reader, SockIOPool.SockIOPoolOptions options ) {
232242
this.poolNamePrefix = "default";
243+
this.configReader = reader;
244+
this.poolOptions = options;
233245
init();
234246
}
235247

@@ -239,9 +251,13 @@ public MemcachedClient() {
239251
* to the name of the SockIOPool created.
240252
*
241253
* @param poolNamePrefix prefix to name of SockIOPool
254+
* @param reader The reader to use to accquire and update the RejigConfig object used to create the SockIOPool.
255+
* @param options The options on the SockIOPool maintained by this client.
242256
*/
243-
public MemcachedClient( String poolNamePrefix ) {
257+
public MemcachedClient( String poolNamePrefix, RejigConfigReader reader, SockIOPool.SockIOPoolOptions options ) {
244258
this.poolNamePrefix = poolNamePrefix;
259+
this.configReader = reader;
260+
this.poolOptions = options;
245261
init();
246262
}
247263

@@ -278,11 +294,15 @@ public MemcachedClient( ClassLoader classLoader, ErrorHandler errorHandler ) {
278294
* @param classLoader ClassLoader object.
279295
* @param errorHandler ErrorHandler object.
280296
* @param poolNamePrefix SockIOPool name's prefix.
297+
* @param reader The reader to use to accquire and update the RejigConfig object used to create the SockIOPool.
298+
* @param options The options on the SockIOPool maintained by this client.
281299
*/
282-
public MemcachedClient( ClassLoader classLoader, ErrorHandler errorHandler, String poolNamePrefix ) {
300+
public MemcachedClient( ClassLoader classLoader, ErrorHandler errorHandler, String poolNamePrefix, RejigConfigReader reader, SockIOPool.SockIOPoolOptions options ) {
283301
this.classLoader = classLoader;
284302
this.errorHandler = errorHandler;
285303
this.poolNamePrefix = poolNamePrefix;
304+
this.configReader = reader;
305+
this.poolOptions = options;
286306
init();
287307
}
288308

@@ -297,6 +317,8 @@ private void init() {
297317
this.compressEnable = true;
298318
this.compressThreshold = COMPRESS_THRESH;
299319
this.defaultEncoding = "UTF-8";
320+
RejigConfig config = this.configReader.getConfig();
321+
currentPool.set(createSockIOPool(config));
300322
}
301323

302324
/**
@@ -305,9 +327,10 @@ private void init() {
305327
*/
306328
private SockIOPool createSockIOPool(RejigConfig config) {
307329
String poolName = String.format("%s-%d", this.poolNamePrefix, config.getId());
308-
SockIOPool pool = SockIOPool.getInstance(poolName);
309-
pool.setRejigConfig(config);
310-
pool.initialize();
330+
SockIOPool pool = SockIOPool.getInstance(poolName)
331+
.setRejigConfig(config)
332+
.setPoolOptions(poolOptions)
333+
.initialize();
311334
return pool;
312335
}
313336

@@ -2195,7 +2218,7 @@ private void handleRefreshAndRetry(SockIOPool pool, SockIOPool.SockIO sock) thro
21952218
RejigConfig new_config = null;
21962219
String line = sock.readLine();
21972220
if ( END.equals(line) ) {
2198-
// Get new config from rejig coordinator.
2221+
new_config = configReader.getConfig();
21992222
}
22002223
else if ( line.startsWith( VALUE ) ) {
22012224
String[] info = line.split(" ");
@@ -2385,7 +2408,7 @@ public void doMulti( boolean asString, Map<String, StringBuilder> sockKeys, Stri
23852408
// 2) we time out
23862409
long startTime = System.currentTimeMillis();
23872410

2388-
long timeout = pool.getMaxBusy();
2411+
long timeout = pool.getPoolOptions().maxBusyTime;
23892412
timeRemaining = timeout;
23902413

23912414
while ( numConns > 0 && timeRemaining > 0 ) {

0 commit comments

Comments
 (0)