Skip to content

Commit ea8a14f

Browse files
author
Jovan Attisha 🥃
committed
Propagate TimeoutExceptions from OperationFutures as OperationTimeoutExceptions
fixes awslabs#48
1 parent ed02a25 commit ea8a14f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,10 @@ public <T> CASResponse cas(String key, long casId, int exp, T value,
923923
} catch (InterruptedException e) {
924924
throw new RuntimeException("Interrupted waiting for value", e);
925925
} catch (ExecutionException e) {
926-
if(e.getCause() instanceof CancellationException) {
926+
if (e.getCause() instanceof CancellationException) {
927927
throw (CancellationException) e.getCause();
928+
} else if (e.getCause() instanceof TimeoutException) {
929+
throw new OperationTimeoutException("Timeout waiting for value", e);
928930
} else {
929931
throw new RuntimeException("Exception waiting for value", e);
930932
}
@@ -1386,8 +1388,10 @@ public <T> CASValue<T> gets(String key, Transcoder<T> tc) {
13861388
} catch (InterruptedException e) {
13871389
throw new RuntimeException("Interrupted waiting for value", e);
13881390
} catch (ExecutionException e) {
1389-
if(e.getCause() instanceof CancellationException) {
1391+
if (e.getCause() instanceof CancellationException) {
13901392
throw (CancellationException) e.getCause();
1393+
} else if (e.getCause() instanceof TimeoutException) {
1394+
throw new OperationTimeoutException("Timeout waiting for value", e);
13911395
} else {
13921396
throw new RuntimeException("Exception waiting for value", e);
13931397
}
@@ -1479,8 +1483,10 @@ public <T> T get(String key, Transcoder<T> tc) {
14791483
} catch (InterruptedException e) {
14801484
throw new RuntimeException("Interrupted waiting for value", e);
14811485
} catch (ExecutionException e) {
1482-
if(e.getCause() instanceof CancellationException) {
1486+
if (e.getCause() instanceof CancellationException) {
14831487
throw (CancellationException) e.getCause();
1488+
} else if (e.getCause() instanceof TimeoutException) {
1489+
throw new OperationTimeoutException("Timeout waiting for value", e);
14841490
} else {
14851491
throw new RuntimeException("Exception waiting for value", e);
14861492
}
@@ -1807,8 +1813,10 @@ public <T> Map<String, T> getBulk(Iterator<String> keyIter,
18071813
} catch (InterruptedException e) {
18081814
throw new RuntimeException("Interrupted getting bulk values", e);
18091815
} catch (ExecutionException e) {
1810-
if(e.getCause() instanceof CancellationException) {
1816+
if (e.getCause() instanceof CancellationException) {
18111817
throw (CancellationException) e.getCause();
1818+
} else if (e.getCause() instanceof TimeoutException) {
1819+
throw new OperationTimeoutException("Timeout waiting for bulk values", e);
18121820
} else {
18131821
throw new RuntimeException("Exception waiting for bulk values", e);
18141822
}
@@ -2389,8 +2397,10 @@ private long mutateWithDefault(Mutator t, String key, long by, long def,
23892397
} catch (InterruptedException e) {
23902398
throw new RuntimeException("Interrupted waiting for store", e);
23912399
} catch (ExecutionException e) {
2392-
if(e.getCause() instanceof CancellationException) {
2400+
if (e.getCause() instanceof CancellationException) {
23932401
throw (CancellationException) e.getCause();
2402+
} else if (e.getCause() instanceof TimeoutException) {
2403+
throw new OperationTimeoutException("Timeout waiting for store", e);
23942404
} else {
23952405
throw new RuntimeException("Failed waiting for store", e);
23962406
}

0 commit comments

Comments
 (0)