Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 36 additions & 42 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@
import net.spy.memcached.v2.vo.BTreeUpdateElement;
import net.spy.memcached.v2.vo.BopDeleteArgs;
import net.spy.memcached.v2.vo.BopGetArgs;
import net.spy.memcached.v2.vo.GetOption;
import net.spy.memcached.v2.vo.BopMultiGetArgs;
import net.spy.memcached.v2.vo.BopRangeGetArgs;
import net.spy.memcached.v2.vo.BopSMGetArgs;
import net.spy.memcached.v2.vo.GetMode;

public class AsyncArcusCommands<T> implements AsyncArcusCommandsIF<T> {

Expand Down Expand Up @@ -735,10 +738,10 @@ public ArcusFuture<Boolean> lopInsert(String key, int index, T value,
}

@Override
public ArcusFuture<T> lopGet(String key, int index, GetOption option) {
public ArcusFuture<T> lopGet(String key, int index, GetMode mode) {
AbstractArcusResult<T> result = new AbstractArcusResult<>(new AtomicReference<>());
ArcusFutureImpl<T> future = new ArcusFutureImpl<>(result);
ListGet get = new ListGet(index, option.isWithDelete(), option.isDropIfEmpty());
ListGet get = new ListGet(index, mode.isWithDelete(), mode.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down Expand Up @@ -781,11 +784,11 @@ public void gotData(String subKey, int flags, byte[] data, byte[] eFlag) {
}

@Override
public ArcusFuture<List<T>> lopGet(String key, int from, int to, GetOption option) {
public ArcusFuture<List<T>> lopGet(String key, int from, int to, GetMode mode) {
AbstractArcusResult<List<T>> result =
new AbstractArcusResult<>(new AtomicReference<>(new ArrayList<>()));
ArcusFutureImpl<List<T>> future = new ArcusFutureImpl<>(result);
ListGet get = new ListGet(from, to, option.isWithDelete(), option.isDropIfEmpty());
ListGet get = new ListGet(from, to, mode.isWithDelete(), mode.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down Expand Up @@ -864,11 +867,11 @@ public ArcusFuture<Boolean> sopInsert(String key, T value, CollectionAttributes
}

@Override
public ArcusFuture<Set<T>> sopGet(String key, int count, GetOption option) {
public ArcusFuture<Set<T>> sopGet(String key, int count, GetMode mode) {
AbstractArcusResult<Set<T>> result
= new AbstractArcusResult<>(new AtomicReference<>(new HashSet<>()));
ArcusFutureImpl<Set<T>> future = new ArcusFutureImpl<>(result);
SetGet get = new SetGet(count, option.isWithDelete(), option.isDropIfEmpty());
SetGet get = new SetGet(count, mode.isWithDelete(), mode.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down Expand Up @@ -1009,18 +1012,18 @@ public ArcusFuture<Boolean> mopUpdate(String key, String mKey, T value) {
}

@Override
public ArcusFuture<Map<String, T>> mopGet(String key, GetOption option) {
return mopGet(key, new ArrayList<>(), option);
public ArcusFuture<Map<String, T>> mopGet(String key, GetMode mode) {
return mopGet(key, new ArrayList<>(), mode);
}

@Override
public ArcusFuture<T> mopGet(String key, String mKey, GetOption option) {
public ArcusFuture<T> mopGet(String key, String mKey, GetMode mode) {
keyValidator.validateMKey(mKey);

AbstractArcusResult<T> result = new AbstractArcusResult<>(new AtomicReference<>());
ArcusFutureImpl<T> future = new ArcusFutureImpl<>(result);
List<String> mKeys = Collections.singletonList(mKey);
MapGet get = new MapGet(mKeys, option.isWithDelete(), option.isDropIfEmpty());
MapGet get = new MapGet(mKeys, mode.isWithDelete(), mode.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down Expand Up @@ -1063,7 +1066,7 @@ public void complete() {
}

@Override
public ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetOption option) {
public ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetMode mode) {
if (mKeys == null) {
throw new IllegalArgumentException("mKeys cannot be null");
}
Expand All @@ -1075,7 +1078,7 @@ public ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetOpt
AbstractArcusResult<Map<String, T>> result =
new AbstractArcusResult<>(new AtomicReference<>(new HashMap<>()));
ArcusFutureImpl<Map<String, T>> future = new ArcusFutureImpl<>(result);
MapGet get = new MapGet(mKeys, option.isWithDelete(), option.isDropIfEmpty());
MapGet get = new MapGet(mKeys, mode.isWithDelete(), mode.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down Expand Up @@ -1353,7 +1356,8 @@ public void gotData(String bKey, int flags, byte[] data, byte[] eFlag) {
}

@Override
public ArcusFuture<BTreeGetResult<T>> bopGet(String key, BKey from, BKey to, BopGetArgs args) {
public ArcusFuture<BTreeGetResult<T>> bopGet(String key, BKey from, BKey to,
BopRangeGetArgs args) {
verifyBKeyTypesMatch(from, to);

AbstractArcusResult<BTreeGetResult<T>> result =
Expand Down Expand Up @@ -1405,34 +1409,33 @@ public void gotData(String bKey, int flags, byte[] data, byte[] eFlag) {

private static BTreeGet createBTreeGet(BKey bKey, BopGetArgs args) {
if (bKey.getType() == BKey.BKeyType.LONG) {
return new BTreeGet((long) bKey.getData(), args.getElementFlagFilter(),
return new BTreeGet((long) bKey.getData(), args.getEFlagFilter(),
args.isWithDelete(), args.isDropIfEmpty());
}

return new BTreeGet((byte[]) bKey.getData(), args.getElementFlagFilter(),
return new BTreeGet((byte[]) bKey.getData(), args.getEFlagFilter(),
args.isWithDelete(), args.isDropIfEmpty());
}

private static BTreeGet createBTreeGet(BKey from, BKey to, BopGetArgs args) {
private static BTreeGet createBTreeGet(BKey from, BKey to, BopRangeGetArgs args) {
if (from.getType() == BKey.BKeyType.LONG) {
return new BTreeGet((long) from.getData(), (long) to.getData(),
args.getElementFlagFilter(), args.getOffset(), args.getCount(),
args.getEFlagFilter(), args.getOffset(), args.getCount(),
args.isWithDelete(), args.isDropIfEmpty());
}

return new BTreeGet((byte[]) from.getData(), (byte[]) to.getData(),
args.getElementFlagFilter(), args.getOffset(), args.getCount(),
args.getEFlagFilter(), args.getOffset(), args.getCount(),
args.isWithDelete(), args.isDropIfEmpty());
}

@Override
public ArcusFuture<Map<String, BTreeGetResult<T>>> bopMultiGet(List<String> keys,
BKey from, BKey to,
BopGetArgs args) {
BopMultiGetArgs args) {
keyValidator.validateKey(keys);
keyValidator.checkDupKey(keys);
verifyBKeyTypesMatch(from, to);
verifyPositiveCountArg(args, ArcusClient.MAX_GETBULK_ELEMENT_COUNT);

ArcusClient client = arcusClientSupplier.get();
Collection<Map.Entry<MemcachedNode, List<String>>> arrangedKeys =
Expand Down Expand Up @@ -1542,25 +1545,24 @@ public void gotElement(String key, int flags, Object bKey, byte[] eFlag, byte[]
}

private BTreeGetBulk<T> createBTreeGetBulk(MemcachedNode node, List<String> keys,
BKey from, BKey to, BopGetArgs args) {
BKey from, BKey to, BopMultiGetArgs args) {
if (from.getType() == BKey.BKeyType.LONG) {
return new BTreeGetBulkWithLongTypeBkey<>(node, keys,
(long) from.getData(), (long) to.getData(), args.getElementFlagFilter(),
(long) from.getData(), (long) to.getData(), args.getEFlagFilter(),
args.getOffset(), args.getCount());
}

return new BTreeGetBulkWithByteTypeBkey<>(node, keys,
(byte[]) from.getData(), (byte[]) to.getData(), args.getElementFlagFilter(),
(byte[]) from.getData(), (byte[]) to.getData(), args.getEFlagFilter(),
args.getOffset(), args.getCount());
}

@Override
public ArcusFuture<BTreeSMGetResult<T>> bopSortMergeGet(List<String> keys, BKey from, BKey to,
boolean unique, BopGetArgs args) {
BopSMGetArgs args) {
keyValidator.validateKey(keys);
keyValidator.checkDupKey(keys);
verifyBKeyTypesMatch(from, to);
verifyPositiveCountArg(args, ArcusClient.MAX_SMGET_COUNT);

ArcusClient client = arcusClientSupplier.get();
Collection<Map.Entry<MemcachedNode, List<String>>> arrangedKeys =
Expand All @@ -1569,7 +1571,7 @@ public ArcusFuture<BTreeSMGetResult<T>> bopSortMergeGet(List<String> keys, BKey
List<CompletableFuture<BTreeSMGetResult<T>>> smGetFutures = new ArrayList<>();

for (Map.Entry<MemcachedNode, List<String>> entry : arrangedKeys) {
BTreeSMGet<T> smGet = createBTreeSMGet(from, to, args, unique, entry);
BTreeSMGet<T> smGet = createBTreeSMGet(from, to, args, entry);
CompletableFuture<BTreeSMGetResult<T>> future =
bopSortMergeGetPerNode(client, smGet).toCompletableFuture();
smGetFutures.add(future);
Expand All @@ -1585,8 +1587,8 @@ public ArcusFuture<BTreeSMGetResult<T>> bopSortMergeGet(List<String> keys, BKey
results.add(future.join());
}
}
return BTreeSMGetResult.mergeSMGetElements(results, from.compareTo(to) <= 0, unique,
args.getCount());
return BTreeSMGetResult.mergeSMGetElements(results, from.compareTo(to) <= 0,
args.isUnique(), args.getCount());
});
}

Expand Down Expand Up @@ -1656,18 +1658,17 @@ public void gotTrimmedKey(String key, Object bKey) {
return future;
}

private BTreeSMGet<T> createBTreeSMGet(BKey from, BKey to, BopGetArgs args,
boolean unique,
private BTreeSMGet<T> createBTreeSMGet(BKey from, BKey to, BopSMGetArgs args,
Map.Entry<MemcachedNode, List<String>> entry) {
if (from.getType() == BKey.BKeyType.LONG) {
return new BTreeSMGetWithLongTypeBkey<>(entry.getKey(), entry.getValue(),
(long) from.getData(), (long) to.getData(), args.getElementFlagFilter(),
args.getCount(), unique);
(long) from.getData(), (long) to.getData(),
args.getEFlagFilter(), args.getCount(), args.isUnique());
}

return new BTreeSMGetWithByteTypeBkey<>(entry.getKey(), entry.getValue(),
(byte[]) from.getData(), (byte[]) to.getData(), args.getElementFlagFilter(),
args.getCount(), unique);
(byte[]) from.getData(), (byte[]) to.getData(),
args.getEFlagFilter(), args.getCount(), args.isUnique());
}

@Override
Expand Down Expand Up @@ -1933,13 +1934,6 @@ private static void verifyBKeyTypesMatch(BKey from, BKey to) {
}
}

private static void verifyPositiveCountArg(BopGetArgs args, int maxCount) {
int count = args.getCount();
if (count <= 0 || count > maxCount) {
throw new IllegalArgumentException("Count should be between 1 to " + maxCount);
}
}

private ArcusFuture<Boolean> collectionCreate(String key, CollectionCreate collectionCreate) {
AbstractArcusResult<Boolean> result = new AbstractArcusResult<>(new AtomicReference<>());
ArcusFutureImpl<Boolean> future = new ArcusFutureImpl<>(result);
Expand Down
44 changes: 23 additions & 21 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
import net.spy.memcached.v2.vo.BTreeUpdateElement;
import net.spy.memcached.v2.vo.BopDeleteArgs;
import net.spy.memcached.v2.vo.BopGetArgs;
import net.spy.memcached.v2.vo.GetOption;
import net.spy.memcached.v2.vo.BopMultiGetArgs;
import net.spy.memcached.v2.vo.BopRangeGetArgs;
import net.spy.memcached.v2.vo.BopSMGetArgs;
import net.spy.memcached.v2.vo.GetMode;

public interface AsyncArcusCommandsIF<T> {

Expand Down Expand Up @@ -260,22 +263,22 @@ ArcusFuture<Boolean> lopCreate(String key, ElementValueType type,
*
* @param key key of the list
* @param index index of the element to get
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return the element value, {@code null} if the key or element is not found
*/
ArcusFuture<T> lopGet(String key, int index, GetOption option);
ArcusFuture<T> lopGet(String key, int index, GetMode mode);

/**
* Get elements in an index range from a list.
*
* @param key key of the list
* @param from index range start (inclusive)
* @param to index range end (inclusive)
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return list of element values in order, an empty list if no elements are found in the range,
* {@code null} if the key is not found
*/
ArcusFuture<List<T>> lopGet(String key, int from, int to, GetOption option);
ArcusFuture<List<T>> lopGet(String key, int from, int to, GetMode mode);

/**
* Delete an element at the given index from a list.
Expand Down Expand Up @@ -342,11 +345,11 @@ ArcusFuture<Boolean> sopCreate(String key, ElementValueType type,
*
* @param key key of the set
* @param count number of elements to retrieve randomly (0 means all elements, max 1000)
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return set of element values, an empty set if no elements are found,
* {@code null} if the key is not found
*/
ArcusFuture<Set<T>> sopGet(String key, int count, GetOption option);
ArcusFuture<Set<T>> sopGet(String key, int count, GetMode mode);

/**
* Check whether an element exists in a set.
Expand Down Expand Up @@ -448,35 +451,35 @@ ArcusFuture<Boolean> mopCreate(String key, ElementValueType type,
* Get all elements from a map.
*
* @param key key of the map
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return map of MKey to value,
* empty map if no elements exist,
* {@code null} if the key is not found
*/
ArcusFuture<Map<String, T>> mopGet(String key, GetOption option);
ArcusFuture<Map<String, T>> mopGet(String key, GetMode mode);

/**
* Get an element with the given MKey from a map.
*
* @param key key of the map
* @param mKey MKey of the element to get
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return the element value,
* {@code null} if the key or MKey is not found
*/
ArcusFuture<T> mopGet(String key, String mKey, GetOption option);
ArcusFuture<T> mopGet(String key, String mKey, GetMode mode);

/**
* Get elements with the MKeys from a map.
*
* @param key key of the map
* @param mKeys list of MKeys to get
* @param option get option - {@link GetOption}
* @param mode get mode - {@link net.spy.memcached.v2.vo.GetMode}
* @return map of MKey to value for found elements,
* empty map if no MKeys are found,
* {@code null} if the key is not found
*/
ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetOption option);
ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetMode mode);

/**
* Delete all elements from a map.
Expand Down Expand Up @@ -694,7 +697,7 @@ ArcusFuture<Map.Entry<Boolean, BTreeElement<T>>> bopUpsertAndGetTrimmed(
* empty {@code BTreeGetResult} if no elements are found in the range but key exists,
* {@code null} if key is not found
*/
ArcusFuture<BTreeGetResult<T>> bopGet(String key, BKey from, BKey to, BopGetArgs args);
ArcusFuture<BTreeGetResult<T>> bopGet(String key, BKey from, BKey to, BopRangeGetArgs args);

/**
* Get elements from multiple btree items.
Expand All @@ -708,21 +711,20 @@ ArcusFuture<Map.Entry<Boolean, BTreeElement<T>>> bopUpsertAndGetTrimmed(
* no {@code Map.Entry} in the map if the key is not found
*/
ArcusFuture<Map<String, BTreeGetResult<T>>> bopMultiGet(
List<String> keys, BKey from, BKey to, BopGetArgs args);
List<String> keys, BKey from, BKey to, BopMultiGetArgs args);

/**
* Get sort-merged elements from multiple btree items.
*
* @param keys list of keys to get
* @param from BKey range start
* @param to BKey range end
* @param unique whether to return unique elements only
* @param args arguments for get operation
* @param keys list of keys to get
* @param from BKey range start
* @param to BKey range end
* @param args arguments for get operation {@link BopSMGetArgs}
* @return {@code BTreeSMGetResult} containing sort-merged elements,
* empty {@code BTreeSMGetResult} if no matching elements exist
*/
ArcusFuture<BTreeSMGetResult<T>> bopSortMergeGet(
List<String> keys, BKey from, BKey to, boolean unique, BopGetArgs args);
List<String> keys, BKey from, BKey to, BopSMGetArgs args);

/**
* Get the position of an element with the given bKey in a btree item.
Expand Down
Loading
Loading