Skip to content

Commit ffde235

Browse files
brido4125jhpark816
authored andcommitted
FIX: Infinity waiting with get method in BulkGetFuture.
1 parent 7b0a314 commit ffde235

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ public void complete() {
11611161
ops.add(op);
11621162
}
11631163
}
1164-
return new BulkGetFuture<T>(rvMap, ops, latch);
1164+
return new BulkGetFuture<T>(rvMap, ops, latch, operationTimeout);
11651165
}
11661166

11671167
/**
@@ -1298,7 +1298,7 @@ public void complete() {
12981298
ops.add(op);
12991299
}
13001300
}
1301-
return new BulkGetFuture<CASValue<T>>(m, ops, latch);
1301+
return new BulkGetFuture<CASValue<T>>(m, ops, latch, operationTimeout);
13021302
}
13031303

13041304
/**

src/main/java/net/spy/memcached/internal/BulkGetFuture.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@ public class BulkGetFuture<T> implements BulkFuture<Map<String, T>> {
4343
private final Map<String, Future<T>> rvMap;
4444
private final Collection<Operation> ops;
4545
private final CountDownLatch latch;
46-
private boolean timeout = false;
46+
private final long timeout;
47+
private boolean isTimeout = false;
4748

48-
public BulkGetFuture(Map<String, Future<T>> m,
49-
Collection<Operation> getOps, CountDownLatch l) {
49+
public BulkGetFuture(Map<String, Future<T>> rvMap, Collection<Operation> ops,
50+
CountDownLatch latch, Long timeout) {
5051
super();
51-
rvMap = m;
52-
ops = getOps;
53-
latch = l;
52+
this.rvMap = rvMap;
53+
this.ops = ops;
54+
this.latch = latch;
55+
this.timeout = timeout;
5456
}
5557

5658
public BulkGetFuture(BulkGetFuture<T> other) {
5759
super();
5860
rvMap = other.rvMap;
5961
ops = other.ops;
6062
latch = other.latch;
63+
timeout = other.timeout;
6164
}
6265

6366
@Override
@@ -72,7 +75,7 @@ public boolean cancel(boolean ign) {
7275
@Override
7376
public Map<String, T> get() throws InterruptedException, ExecutionException {
7477
try {
75-
return get(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
78+
return get(timeout, TimeUnit.MILLISECONDS);
7679
} catch (TimeoutException e) {
7780
throw new OperationTimeoutException(e);
7881
}
@@ -84,7 +87,7 @@ public Map<String, T> getSome(long duration, TimeUnit units)
8487
Collection<Operation> timedoutOps = new HashSet<Operation>();
8588
Map<String, T> ret = internalGet(duration, units, timedoutOps);
8689
if (timedoutOps.size() > 0) {
87-
timeout = true;
90+
isTimeout = true;
8891
LoggerFactory.getLogger(getClass()).warn(
8992
new CheckedOperationTimeoutException(duration, units, timedoutOps).getMessage());
9093
}
@@ -104,7 +107,7 @@ public Map<String, T> get(long duration, TimeUnit units)
104107
Collection<Operation> timedoutOps = new HashSet<Operation>();
105108
Map<String, T> ret = internalGet(duration, units, timedoutOps);
106109
if (timedoutOps.size() > 0) {
107-
this.timeout = true;
110+
isTimeout = true;
108111
throw new CheckedOperationTimeoutException(duration, units, timedoutOps);
109112
}
110113
return ret;
@@ -177,6 +180,6 @@ private Map<String, T> internalGet(long to, TimeUnit unit,
177180
* @see net.spy.memcached.internal.BulkFuture#isTimeout()
178181
*/
179182
public boolean isTimeout() {
180-
return timeout;
183+
return isTimeout;
181184
}
182185
}

0 commit comments

Comments
 (0)