|
1 | 1 | /**
|
2 | 2 | * Copyright (C) 2006-2009 Dustin Sallings
|
3 |
| - * Copyright (C) 2009-2011 Couchbase, Inc. |
| 3 | + * Copyright (C) 2009-2013 Couchbase, Inc. |
4 | 4 | *
|
5 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 | 6 | * of this software and associated documentation files (the "Software"), to deal
|
|
41 | 41 | import java.util.concurrent.ConcurrentMap;
|
42 | 42 | import java.util.concurrent.CountDownLatch;
|
43 | 43 | import java.util.concurrent.ExecutionException;
|
| 44 | +import java.util.concurrent.ExecutorService; |
44 | 45 | import java.util.concurrent.Future;
|
45 | 46 | import java.util.concurrent.TimeUnit;
|
46 | 47 | import java.util.concurrent.TimeoutException;
|
@@ -154,6 +155,8 @@ public class MemcachedClient extends SpyObject implements MemcachedClientIF,
|
154 | 155 |
|
155 | 156 | protected final AuthThreadMonitor authMonitor = new AuthThreadMonitor();
|
156 | 157 |
|
| 158 | + protected final ExecutorService executorService; |
| 159 | + |
157 | 160 | /**
|
158 | 161 | * Get a memcache client operating on the specified memcached locations.
|
159 | 162 | *
|
@@ -205,6 +208,7 @@ public MemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs)
|
205 | 208 | assert mconn != null : "Connection factory failed to make a connection";
|
206 | 209 | operationTimeout = cf.getOperationTimeout();
|
207 | 210 | authDescriptor = cf.getAuthDescriptor();
|
| 211 | + executorService = cf.getListenerExecutorService(); |
208 | 212 | if (authDescriptor != null) {
|
209 | 213 | addObserver(this);
|
210 | 214 | }
|
@@ -292,7 +296,8 @@ private <T> OperationFuture<Boolean> asyncStore(StoreType storeType,
|
292 | 296 | CachedData co = tc.encode(value);
|
293 | 297 | final CountDownLatch latch = new CountDownLatch(1);
|
294 | 298 | final OperationFuture<Boolean> rv =
|
295 |
| - new OperationFuture<Boolean>(key, latch, operationTimeout); |
| 299 | + new OperationFuture<Boolean>(key, latch, operationTimeout, |
| 300 | + executorService); |
296 | 301 | Operation op = opFact.store(storeType, key, co.getFlags(), exp,
|
297 | 302 | co.getData(), new StoreOperation.Callback() {
|
298 | 303 | public void receivedStatus(OperationStatus val) {
|
@@ -321,7 +326,7 @@ private <T> OperationFuture<Boolean> asyncCat(ConcatenationType catType,
|
321 | 326 | CachedData co = tc.encode(value);
|
322 | 327 | final CountDownLatch latch = new CountDownLatch(1);
|
323 | 328 | final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key,
|
324 |
| - latch, operationTimeout); |
| 329 | + latch, operationTimeout, executorService); |
325 | 330 | Operation op = opFact.cat(catType, cas, key, co.getData(),
|
326 | 331 | new OperationCallback() {
|
327 | 332 | public void receivedStatus(OperationStatus val) {
|
@@ -367,7 +372,8 @@ public <T> OperationFuture<Boolean> touch(final String key, final int exp,
|
367 | 372 | final Transcoder<T> tc) {
|
368 | 373 | final CountDownLatch latch = new CountDownLatch(1);
|
369 | 374 | final OperationFuture<Boolean> rv =
|
370 |
| - new OperationFuture<Boolean>(key, latch, operationTimeout); |
| 375 | + new OperationFuture<Boolean>(key, latch, operationTimeout, |
| 376 | + executorService); |
371 | 377 |
|
372 | 378 | Operation op = opFact.touch(key, exp, new OperationCallback() {
|
373 | 379 | public void receivedStatus(OperationStatus status) {
|
@@ -587,7 +593,8 @@ public <T> OperationFuture<Boolean> prepend(String key, T val,
|
587 | 593 | CachedData co = tc.encode(value);
|
588 | 594 | final CountDownLatch latch = new CountDownLatch(1);
|
589 | 595 | final OperationFuture<CASResponse> rv =
|
590 |
| - new OperationFuture<CASResponse>(key, latch, operationTimeout); |
| 596 | + new OperationFuture<CASResponse>(key, latch, operationTimeout, |
| 597 | + executorService); |
591 | 598 | Operation op = opFact.cas(StoreType.set, key, casId, co.getFlags(), exp,
|
592 | 599 | co.getData(), new StoreOperation.Callback() {
|
593 | 600 | public void receivedStatus(OperationStatus val) {
|
@@ -947,7 +954,8 @@ public OperationFuture<Boolean> replace(String key, int exp, Object o) {
|
947 | 954 | public <T> GetFuture<T> asyncGet(final String key, final Transcoder<T> tc) {
|
948 | 955 |
|
949 | 956 | final CountDownLatch latch = new CountDownLatch(1);
|
950 |
| - final GetFuture<T> rv = new GetFuture<T>(latch, operationTimeout, key); |
| 957 | + final GetFuture<T> rv = new GetFuture<T>(latch, operationTimeout, key, |
| 958 | + executorService); |
951 | 959 | Operation op = opFact.get(key, new GetOperation.Callback() {
|
952 | 960 | private Future<T> val = null;
|
953 | 961 |
|
@@ -997,7 +1005,8 @@ public <T> OperationFuture<CASValue<T>> asyncGets(final String key,
|
997 | 1005 |
|
998 | 1006 | final CountDownLatch latch = new CountDownLatch(1);
|
999 | 1007 | final OperationFuture<CASValue<T>> rv =
|
1000 |
| - new OperationFuture<CASValue<T>>(key, latch, operationTimeout); |
| 1008 | + new OperationFuture<CASValue<T>>(key, latch, operationTimeout, |
| 1009 | + executorService); |
1001 | 1010 |
|
1002 | 1011 | Operation op = opFact.gets(key, new GetsOperation.Callback() {
|
1003 | 1012 | private CASValue<T> val = null;
|
@@ -1228,7 +1237,7 @@ public <T> BulkFuture<Map<String, T>> asyncGetBulk(Iterator<String> keyIter,
|
1228 | 1237 |
|
1229 | 1238 | final CountDownLatch latch = new CountDownLatch(chunks.size());
|
1230 | 1239 | final Collection<Operation> ops = new ArrayList<Operation>(chunks.size());
|
1231 |
| - final BulkGetFuture<T> rv = new BulkGetFuture<T>(m, ops, latch); |
| 1240 | + final BulkGetFuture<T> rv = new BulkGetFuture<T>(m, ops, latch, executorService); |
1232 | 1241 |
|
1233 | 1242 | GetOperation.Callback cb = new GetOperation.Callback() {
|
1234 | 1243 | @SuppressWarnings("synthetic-access")
|
@@ -1396,7 +1405,7 @@ public <T> OperationFuture<CASValue<T>> asyncGetAndTouch(final String key,
|
1396 | 1405 | final int exp, final Transcoder<T> tc) {
|
1397 | 1406 | final CountDownLatch latch = new CountDownLatch(1);
|
1398 | 1407 | final OperationFuture<CASValue<T>> rv = new OperationFuture<CASValue<T>>(
|
1399 |
| - key, latch, operationTimeout); |
| 1408 | + key, latch, operationTimeout, executorService); |
1400 | 1409 |
|
1401 | 1410 | Operation op = opFact.getAndTouch(key, exp,
|
1402 | 1411 | new GetAndTouchOperation.Callback() {
|
@@ -1843,7 +1852,7 @@ private OperationFuture<Long> asyncMutate(Mutator m, String key, long by,
|
1843 | 1852 | long def, int exp) {
|
1844 | 1853 | final CountDownLatch latch = new CountDownLatch(1);
|
1845 | 1854 | final OperationFuture<Long> rv =
|
1846 |
| - new OperationFuture<Long>(key, latch, operationTimeout); |
| 1855 | + new OperationFuture<Long>(key, latch, operationTimeout, executorService); |
1847 | 1856 | Operation op = opFact.mutate(m, key, by, def, exp,
|
1848 | 1857 | new OperationCallback() {
|
1849 | 1858 | public void receivedStatus(OperationStatus s) {
|
@@ -2023,7 +2032,7 @@ public OperationFuture<Boolean> delete(String key) {
|
2023 | 2032 | public OperationFuture<Boolean> delete(String key, long cas) {
|
2024 | 2033 | final CountDownLatch latch = new CountDownLatch(1);
|
2025 | 2034 | final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key,
|
2026 |
| - latch, operationTimeout); |
| 2035 | + latch, operationTimeout, executorService); |
2027 | 2036 |
|
2028 | 2037 | DeleteOperation.Callback callback = new DeleteOperation.Callback() {
|
2029 | 2038 | public void receivedStatus(OperationStatus s) {
|
@@ -2082,7 +2091,7 @@ public void complete() {
|
2082 | 2091 | });
|
2083 | 2092 |
|
2084 | 2093 | return new OperationFuture<Boolean>(null, blatch, flushResult,
|
2085 |
| - operationTimeout) { |
| 2094 | + operationTimeout, executorService) { |
2086 | 2095 | @Override
|
2087 | 2096 | public boolean cancel(boolean ign) {
|
2088 | 2097 | boolean rv = false;
|
|
0 commit comments