|
59 | 59 | import net.spy.memcached.ops.CancelledOperationStatus; |
60 | 60 | import net.spy.memcached.ops.ConcatenationType; |
61 | 61 | import net.spy.memcached.ops.DeleteOperation; |
| 62 | +import net.spy.memcached.ops.GetAndTouchOperation; |
62 | 63 | import net.spy.memcached.ops.GetOperation; |
| 64 | +import net.spy.memcached.ops.GetsAndTouchOperation; |
63 | 65 | import net.spy.memcached.ops.GetsOperation; |
64 | 66 | import net.spy.memcached.ops.Mutator; |
65 | 67 | import net.spy.memcached.ops.Operation; |
@@ -986,6 +988,107 @@ public GetFuture<CASValue<Object>> asyncGets(final String key) { |
986 | 988 | return asyncGets(key, transcoder); |
987 | 989 | } |
988 | 990 |
|
| 991 | + /** |
| 992 | + * Get the given key to reset its expiration time asynchronously. |
| 993 | + * |
| 994 | + * @param key the key to fetch |
| 995 | + * @param exp the new expiration to set for the given key |
| 996 | + * @param tc the transcoder to serialize and unserialize value |
| 997 | + * @return a future that will hold the return value of the fetch |
| 998 | + * @throws IllegalStateException in the rare circumstance where queue is too |
| 999 | + * full to accept any more requests |
| 1000 | + */ |
| 1001 | + public <T> GetFuture<T> asyncGetAndTouch(final String key, final int exp, |
| 1002 | + final Transcoder<T> tc) { |
| 1003 | + final CountDownLatch latch = new CountDownLatch(1); |
| 1004 | + final GetFuture<T> future = new GetFuture<>(latch, operationTimeout); |
| 1005 | + |
| 1006 | + Operation op = opFact.getAndTouch(key, exp, |
| 1007 | + new GetAndTouchOperation.Callback() { |
| 1008 | + private GetResult<T> result = null; |
| 1009 | + |
| 1010 | + public void receivedStatus(OperationStatus status) { |
| 1011 | + future.set(result, status); |
| 1012 | + } |
| 1013 | + |
| 1014 | + public void gotData(String k, int flags, byte[] data) { |
| 1015 | + assert k.equals(key) : "Wrong key returned"; |
| 1016 | + result = new GetResultImpl<>(new CachedData(flags, data, tc.getMaxSize()), tc); |
| 1017 | + } |
| 1018 | + |
| 1019 | + public void complete() { |
| 1020 | + latch.countDown(); |
| 1021 | + } |
| 1022 | + }); |
| 1023 | + future.setOperation(op); |
| 1024 | + addOp(key, op); |
| 1025 | + return future; |
| 1026 | + } |
| 1027 | + |
| 1028 | + /** |
| 1029 | + * Get the given key to reset its expiration time asynchronously. |
| 1030 | + * |
| 1031 | + * @param key the key to fetch |
| 1032 | + * @param exp the new expiration to set for the given key |
| 1033 | + * @return a future that will hold the return value of the fetch |
| 1034 | + * @throws IllegalStateException in the rare circumstance where queue is too |
| 1035 | + * full to accept any more requests |
| 1036 | + */ |
| 1037 | + public GetFuture<Object> asyncGetAndTouch(final String key, final int exp) { |
| 1038 | + return asyncGetAndTouch(key, exp, transcoder); |
| 1039 | + } |
| 1040 | + |
| 1041 | + /** |
| 1042 | + * Gets (with CAS support) the given key to reset its expiration time asynchronously. |
| 1043 | + * |
| 1044 | + * @param key the key to fetch |
| 1045 | + * @param exp the new expiration to set for the given key |
| 1046 | + * @param tc the transcoder to serialize and unserialize value |
| 1047 | + * @return a future that will hold the return value of the fetch |
| 1048 | + * @throws IllegalStateException in the rare circumstance where queue is too |
| 1049 | + * full to accept any more requests |
| 1050 | + */ |
| 1051 | + public <T> GetFuture<CASValue<T>> asyncGetsAndTouch(final String key, final int exp, |
| 1052 | + final Transcoder<T> tc) { |
| 1053 | + final CountDownLatch latch = new CountDownLatch(1); |
| 1054 | + final GetFuture<CASValue<T>> rv = new GetFuture<>(latch, operationTimeout); |
| 1055 | + |
| 1056 | + Operation op = opFact.getsAndTouch(key, exp, |
| 1057 | + new GetsAndTouchOperation.Callback() { |
| 1058 | + private GetResult<CASValue<T>> val = null; |
| 1059 | + |
| 1060 | + public void receivedStatus(OperationStatus status) { |
| 1061 | + rv.set(val, status); |
| 1062 | + } |
| 1063 | + |
| 1064 | + public void gotData(String k, int flags, long cas, byte[] data) { |
| 1065 | + assert key.equals(k) : "Wrong key returned"; |
| 1066 | + assert cas > 0 : "CAS was less than zero: " + cas; |
| 1067 | + val = new GetsResultImpl<>(cas, new CachedData(flags, data, tc.getMaxSize()), tc); |
| 1068 | + } |
| 1069 | + |
| 1070 | + public void complete() { |
| 1071 | + latch.countDown(); |
| 1072 | + } |
| 1073 | + }); |
| 1074 | + rv.setOperation(op); |
| 1075 | + addOp(key, op); |
| 1076 | + return rv; |
| 1077 | + } |
| 1078 | + |
| 1079 | + /** |
| 1080 | + * Gets (with CAS support) the given key to reset its expiration time asynchronously. |
| 1081 | + * |
| 1082 | + * @param key the key to fetch |
| 1083 | + * @param exp the new expiration to set for the given key |
| 1084 | + * @return a future that will hold the return value of the fetch |
| 1085 | + * @throws IllegalStateException in the rare circumstance where queue is too |
| 1086 | + * full to accept any more requests |
| 1087 | + */ |
| 1088 | + public GetFuture<CASValue<Object>> asyncGetsAndTouch(final String key, final int exp) { |
| 1089 | + return asyncGetsAndTouch(key, exp, transcoder); |
| 1090 | + } |
| 1091 | + |
989 | 1092 | /** |
990 | 1093 | * Gets (with CAS support) with a single key. |
991 | 1094 | * |
|
0 commit comments