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
26 changes: 13 additions & 13 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
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.GetArgs;
import net.spy.memcached.v2.vo.GetOption;
import net.spy.memcached.v2.vo.SMGetElements;

public class AsyncArcusCommands<T> implements AsyncArcusCommandsIF<T> {
Expand Down Expand Up @@ -735,10 +735,10 @@ public ArcusFuture<Boolean> lopInsert(String key, int index, T value,
}

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

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

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

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

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

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

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

@Override
public ArcusFuture<T> mopGet(String key, String mKey, GetArgs args) {
public ArcusFuture<T> mopGet(String key, String mKey, GetOption option) {
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, args.isWithDelete(), args.isDropIfEmpty());
MapGet get = new MapGet(mKeys, option.isWithDelete(), option.isDropIfEmpty());
ArcusClient client = arcusClientSupplier.get();

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

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

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
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.GetArgs;
import net.spy.memcached.v2.vo.GetOption;
import net.spy.memcached.v2.vo.SMGetElements;

public interface AsyncArcusCommandsIF<T> {
Expand Down Expand Up @@ -260,22 +260,22 @@ ArcusFuture<Boolean> lopCreate(String key, ElementValueType type,
*
* @param key key of the list
* @param index index of the element to get
* @param args arguments for get operation
* @param option get option - {@link GetOption}
* @return the element value, {@code null} if the key or element is not found
*/
ArcusFuture<T> lopGet(String key, int index, GetArgs args);
ArcusFuture<T> lopGet(String key, int index, GetOption option);

/**
* 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 args arguments for get operation
* @param option get option - {@link GetOption}
* @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, GetArgs args);
ArcusFuture<List<T>> lopGet(String key, int from, int to, GetOption option);

/**
* Delete an element at the given index from a list.
Expand Down Expand Up @@ -342,11 +342,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 args arguments for get operation
* @param option get option - {@link GetOption}
* @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, GetArgs args);
ArcusFuture<Set<T>> sopGet(String key, int count, GetOption option);

/**
* Check whether an element exists in a set.
Expand Down Expand Up @@ -448,35 +448,35 @@ ArcusFuture<Boolean> mopCreate(String key, ElementValueType type,
* Get all elements from a map.
*
* @param key key of the map
* @param args arguments for get operation
* @param option get option - {@link GetOption}
* @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, GetArgs args);
ArcusFuture<Map<String, T>> mopGet(String key, GetOption option);

/**
* 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 args arguments for get operation
* @param option get option - {@link GetOption}
* @return the element value,
* {@code null} if the key or MKey is not found
*/
ArcusFuture<T> mopGet(String key, String mKey, GetArgs args);
ArcusFuture<T> mopGet(String key, String mKey, GetOption option);

/**
* Get elements with the MKeys from a map.
*
* @param key key of the map
* @param mKeys list of MKeys to get
* @param args arguments for get operation
* @param option get option - {@link GetOption}
* @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, GetArgs args);
ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetOption option);

/**
* Delete all elements from a map.
Expand Down
42 changes: 0 additions & 42 deletions src/main/java/net/spy/memcached/v2/vo/GetArgs.java

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/net/spy/memcached/v2/vo/GetOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.spy.memcached.v2.vo;

public enum GetOption {
/**
* Retrieves elements without deleting them.
*/
NONE(false, false),

/**
* Retrieves elements and deletes them from the collection.
*/
DELETE(true, false),

/**
* Retrieves elements, deletes them, and drops the collection if it becomes empty.
*/
DROP(true, true);

private final boolean withDelete;
private final boolean dropIfEmpty;

GetOption(boolean withDelete, boolean dropIfEmpty) {
this.withDelete = withDelete;
this.dropIfEmpty = dropIfEmpty;
}

public boolean isWithDelete() {
return withDelete;
}

public boolean isDropIfEmpty() {
return dropIfEmpty;
}
}
34 changes: 17 additions & 17 deletions src/test/java/net/spy/memcached/v2/AdminAsyncArcusCommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ void flushNonPrefix() throws ExecutionException, InterruptedException, TimeoutEx

// when
async.flush("")
// then
.thenCompose(result -> {
assertTrue(result);
return async.get(prefixKey);
})
.thenCompose(result -> {
assertNotNull(result);
assertEquals(VALUE, result);
return async.get(nonPrefixKey);
})
.thenAccept(Assertions::assertNull)
.toCompletableFuture()
.get(300L, TimeUnit.MILLISECONDS);
// then
.thenCompose(result -> {
assertTrue(result);
return async.get(prefixKey);
})
.thenCompose(result -> {
assertNotNull(result);
assertEquals(VALUE, result);
return async.get(nonPrefixKey);
})
.thenAccept(Assertions::assertNull)
.toCompletableFuture()
.get(300L, TimeUnit.MILLISECONDS);
}

@Test
Expand All @@ -166,10 +166,10 @@ void statsAllArgs() throws ExecutionException, InterruptedException, TimeoutExce
for (StatsArg arg : StatsArg.values()) {
// when
async.stats(arg)
// then
.thenAccept(Assertions::assertNotNull)
.toCompletableFuture()
.get(300L, TimeUnit.MILLISECONDS);
// then
.thenAccept(Assertions::assertNotNull)
.toCompletableFuture()
.get(300L, TimeUnit.MILLISECONDS);
}
}

Expand Down
Loading
Loading