diff --git a/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java b/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java index abb8fee8a..109e7c118 100644 --- a/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java +++ b/src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java @@ -280,13 +280,6 @@ public ArcusFuture> multiReplace(Map items, int return multiStore(StoreType.replace, items, exp); } - /** - * @param type store type - * @param items map of key to value to store - * @param exp expiration time - * @return ArcusFuture with Map of key to Boolean result. If an operation fails exceptionally, - * the corresponding value in the map will be null. - */ private ArcusFuture> multiStore(StoreType type, Map items, int exp) { @@ -297,7 +290,6 @@ private ArcusFuture> multiStore(StoreType type, keyToFuture.put(key, future); }); - /* Combine multiple CompletableFutures into a single ArcusFuture. */ return new ArcusMultiFuture<>(keyToFuture.values(), () -> { Map results = new HashMap<>(); keyToFuture.forEach((key, future) -> { @@ -396,6 +388,9 @@ public void complete() { } public ArcusFuture> multiGet(List keys) { + keyValidator.validateKey(keys); + keyValidator.checkDupKey(keys); + ArcusClient client = arcusClientSupplier.get(); Collection>> arrangedKeys = client.groupingKeys(keys, MemcachedClient.GET_BULK_CHUNK_SIZE, APIType.GET); @@ -411,11 +406,6 @@ public ArcusFuture> multiGet(List keys) { futures.add(future); } - /* - * Combine all futures. If any future fails exceptionally, - * the corresponding keys will have null values in the result map. - * If cache miss occurs, the corresponding key will not be present in the result map. - */ return new ArcusMultiFuture<>(futures, () -> { Map results = new HashMap<>(); @@ -558,6 +548,9 @@ public void complete() { } public ArcusFuture>> multiGets(List keys) { + keyValidator.validateKey(keys); + keyValidator.checkDupKey(keys); + ArcusClient client = arcusClientSupplier.get(); Collection>> arrangedKeys = client.groupingKeys(keys, MemcachedClient.GET_BULK_CHUNK_SIZE, APIType.GETS); @@ -687,8 +680,9 @@ public void complete() { } public ArcusFuture> multiDelete(List keys) { - Map> keyToFuture = new HashMap<>(keys.size()); + keyValidator.checkDupKey(keys); + Map> keyToFuture = new HashMap<>(keys.size()); for (String key : keys) { CompletableFuture future = delete(key).toCompletableFuture(); keyToFuture.put(key, future); @@ -1101,12 +1095,12 @@ private static BTreeGet createBTreeGet(BKey from, BKey to, BopGetArgs args) { public ArcusFuture>> bopMultiGet(List keys, BKey from, BKey to, BopGetArgs args) { + keyValidator.validateKey(keys); + keyValidator.checkDupKey(keys); verifyBKeyRange(from, to); verifyPositiveCountArg(args, ArcusClient.MAX_GETBULK_ELEMENT_COUNT); ArcusClient client = arcusClientSupplier.get(); - keyValidator.validateKey(keys); - keyValidator.checkDupKey(keys); Collection>> arrangedKeys = client.groupingKeys(keys, ArcusClient.BOPGET_BULK_CHUNK_SIZE, APIType.BOP_GET); @@ -1448,13 +1442,12 @@ public void complete() { public ArcusFuture> bopSortMergeGet(List keys, BKey from, BKey to, boolean unique, BopGetArgs args) { + keyValidator.validateKey(keys); + keyValidator.checkDupKey(keys); verifyBKeyRange(from, to); verifyPositiveCountArg(args, ArcusClient.MAX_SMGET_COUNT); ArcusClient client = arcusClientSupplier.get(); - keyValidator.validateKey(keys); - keyValidator.checkDupKey(keys); - Collection>> arrangedKeys = client.groupingKeys(keys, ArcusClient.SMGET_CHUNK_SIZE, APIType.BOP_SMGET); @@ -1968,6 +1961,10 @@ public ArcusFuture sopDelete(String key, T value, boolean dropIfEmpty) public ArcusFuture mopCreate(String key, ElementValueType type, CollectionAttributes attributes) { + if (attributes == null) { + throw new IllegalArgumentException("CollectionAttributes cannot be null"); + } + MapCreate create = new MapCreate(TranscoderUtils.examineFlags(type), attributes.getExpireTime(), attributes.getMaxCount(), attributes.getReadable(), false); @@ -1980,6 +1977,8 @@ public ArcusFuture mopInsert(String key, String mKey, T value) { public ArcusFuture mopInsert(String key, String mKey, T value, CollectionAttributes attributes) { + keyValidator.validateMKey(mKey); + MapInsert insert = new MapInsert<>(value, null, attributes); return collectionInsert(key, mKey, insert); } @@ -1990,11 +1989,15 @@ public ArcusFuture mopUpsert(String key, String mKey, T value) { public ArcusFuture mopUpsert(String key, String mKey, T value, CollectionAttributes attributes) { + keyValidator.validateMKey(mKey); + MapUpsert upsert = new MapUpsert<>(value, attributes); return collectionInsert(key, mKey, upsert); } public ArcusFuture mopUpdate(String key, String mKey, T value) { + keyValidator.validateMKey(mKey); + MapUpdate update = new MapUpdate<>(value, false); return collectionUpdate(key, mKey, update); } @@ -2004,6 +2007,8 @@ public ArcusFuture> mopGet(String key, GetArgs args) { } public ArcusFuture mopGet(String key, String mKey, GetArgs args) { + keyValidator.validateMKey(mKey); + AbstractArcusResult result = new AbstractArcusResult<>(new AtomicReference<>()); ArcusFutureImpl future = new ArcusFutureImpl<>(result); List mKeys = Collections.singletonList(mKey); @@ -2050,6 +2055,14 @@ public void complete() { } public ArcusFuture> mopGet(String key, List mKeys, GetArgs args) { + if (mKeys == null) { + throw new IllegalArgumentException("mKeys cannot be null"); + } + + if (!mKeys.isEmpty()) { + keyValidator.validateMKey(mKeys); + } + AbstractArcusResult> result = new AbstractArcusResult<>(new AtomicReference<>(new HashMap<>())); ArcusFutureImpl> future = new ArcusFutureImpl<>(result); @@ -2104,6 +2117,14 @@ public ArcusFuture mopDelete(String key, String mKey, boolean dropIfEmp } public ArcusFuture mopDelete(String key, List mKeys, boolean dropIfEmpty) { + if (mKeys == null) { + throw new IllegalArgumentException("mKeys cannot be null"); + } + + if (!mKeys.isEmpty()) { + keyValidator.validateMKey(mKeys); + } + MapDelete delete = new MapDelete(mKeys, dropIfEmpty, false); return collectionDelete(key, delete); }