Skip to content
Open
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
145 changes: 145 additions & 0 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -73,6 +74,12 @@
import net.spy.memcached.collection.SetExist;
import net.spy.memcached.collection.SetGet;
import net.spy.memcached.collection.SetInsert;
import net.spy.memcached.collection.MapCreate;
import net.spy.memcached.collection.MapDelete;
import net.spy.memcached.collection.MapGet;
import net.spy.memcached.collection.MapInsert;
import net.spy.memcached.collection.MapUpdate;
import net.spy.memcached.collection.MapUpsert;
import net.spy.memcached.internal.result.GetsResultImpl;
import net.spy.memcached.ops.APIType;
import net.spy.memcached.ops.BTreeFindPositionOperation;
Expand Down Expand Up @@ -1980,4 +1987,142 @@ public ArcusFuture<Boolean> sopDelete(String key, T value, boolean dropIfEmpty)
SetDelete<T> delete = new SetDelete<>(value, dropIfEmpty, false, tcForCollection);
return collectionDelete(key, delete);
}

public ArcusFuture<Boolean> mopCreate(String key, ElementValueType type,
CollectionAttributes attributes) {
MapCreate create = new MapCreate(TranscoderUtils.examineFlags(type),
attributes.getExpireTime(), attributes.getMaxCount(),
attributes.getReadable(), false);
return collectionCreate(key, create);
}

public ArcusFuture<Boolean> mopInsert(String key, String mKey, T value) {
return mopInsert(key, mKey, value, null);
}

public ArcusFuture<Boolean> mopInsert(String key, String mKey, T value,
CollectionAttributes attributes) {
MapInsert<T> insert = new MapInsert<>(value, null, attributes);
return collectionInsert(key, mKey, insert);
}

public ArcusFuture<Boolean> mopUpsert(String key, String mKey, T value) {
return mopUpsert(key, mKey, value, null);
}

public ArcusFuture<Boolean> mopUpsert(String key, String mKey, T value,
CollectionAttributes attributes) {
MapUpsert<T> upsert = new MapUpsert<>(value, attributes);
return collectionInsert(key, mKey, upsert);
}

public ArcusFuture<Boolean> mopUpdate(String key, String mKey, T value) {
MapUpdate<T> update = new MapUpdate<>(value, false);
return collectionUpdate(key, mKey, update);
}

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

public ArcusFuture<T> mopGet(String key, String mKey, GetArgs args) {
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());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
@Override
public void gotData(String mKey, int flags, byte[] data, byte[] eFlag) {
CachedData cachedData = new CachedData(flags, data, tcForCollection.getMaxSize());
result.set(tcForCollection.decode(cachedData));
}

@Override
public void receivedStatus(OperationStatus status) {
switch (status.getStatusCode()) {
case SUCCESS:
break;
case ERR_NOT_FOUND_ELEMENT:
case ERR_NOT_FOUND:
result.set(null);
break;
case CANCELLED:
future.internalCancel();
break;
default:
/* TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */
result.addError(key, status);
}
}

@Override
public void complete() {
future.complete();
}
};
Operation op = client.getOpFact().collectionGet(key, get, cb);
future.setOp(op);
client.addOp(key, op);

return future;
}

public ArcusFuture<Map<String, T>> mopGet(String key, List<String> mKeys, GetArgs args) {
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());
ArcusClient client = arcusClientSupplier.get();

CollectionGetOperation.Callback cb = new CollectionGetOperation.Callback() {
@Override
public void gotData(String mKey, int flags, byte[] data, byte[] eFlag) {
CachedData cachedData = new CachedData(flags, data, tcForCollection.getMaxSize());
result.get().put(mKey, tcForCollection.decode(cachedData));
}

@Override
public void receivedStatus(OperationStatus status) {
switch (status.getStatusCode()) {
case SUCCESS:
case ERR_NOT_FOUND_ELEMENT:
break;
case ERR_NOT_FOUND:
result.set(null);
break;
case CANCELLED:
future.internalCancel();
break;
default:
/* TYPE_MISMATCH / UNREADABLE / NOT_SUPPORTED or unknown statement */
result.addError(key, status);
}
}

@Override
public void complete() {
future.complete();
}
};
Operation op = client.getOpFact().collectionGet(key, get, cb);
future.setOp(op);
client.addOp(key, op);

return future;
}

public ArcusFuture<Boolean> mopDelete(String key, boolean dropIfEmpty) {
return mopDelete(key, new ArrayList<>(), dropIfEmpty);
}

public ArcusFuture<Boolean> mopDelete(String key, String mKey, boolean dropIfEmpty) {
return mopDelete(key, Collections.singletonList(mKey), dropIfEmpty);
}

public ArcusFuture<Boolean> mopDelete(String key, List<String> mKeys, boolean dropIfEmpty) {
MapDelete delete = new MapDelete(mKeys, dropIfEmpty, false);
return collectionDelete(key, delete);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mopDelete ์—ฐ์‚ฐ์ฒ˜๋Ÿผ
mopGet ์—ฐ์‚ฐ๋„ ๋‹ค๋ฅธ mopGet ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋˜์ง€ ์•Š๋Š” ์ง€ ?

mkeys ์ธ์ž๊ฐ€ ์—†๋Š” ๋ฉ”์†Œ๋“œ์—์„œ
new ArrayList<>()๋ฅผ mkeys ์ธ์ž๋กœ ํ•˜์—ฌ mopGet ํ˜ธ์ถœํ•˜๋ฉด ๋˜์ง€ ์•Š๋Š” ์ง€?

1๊ฐœ์˜ mkey ์ธ์ž์ธ ๊ฒฝ์šฐ๋Š” ๋ฆฌํ„ด ๊ฐ’์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ์ธ ๋ฐ,
์ด ๊ฒฝ์šฐ์—๋Š” ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ๋˜๋Š” ์ง€?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. ๋ชจ๋“  Map ์กฐํšŒ (mkeys ์ธ์ž๊ฐ€ ์—†๋Š” ๋ฉ”์„œ๋“œ)

mopDelete์™€ ๋™์ผํ•œ ํŒจํ„ด์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์–ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณ€๊ฒฝํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

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

2. ๋‹จ๊ฑด ์กฐํšŒ (1๊ฐœ์˜ mKey)

๋ฆฌํ„ด ๊ฐ’์ด ๋‹ค๋ฅผ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์‘๋‹ต(ERR_NOT_FOUND_ELEMENT)์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๊ฐ€ ๋‹ค๊ฑด ์กฐํšŒ(List<String> mKeys)์™€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋„๋กœ ๊ตฌํ˜„์„ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์‘๋‹ต ์ƒํƒœ ๋‹จ๊ฑด (ArcusFuture<T>) ๋‹ค๊ฑด (ArcusFuture<Map<String, T>>)
SUCCESS T Map<String, T>
ERR_NOT_FOUND_ELEMENT null {} (๋นˆ ๋งต)
ERR_NOT_FOUND null null

}
137 changes: 137 additions & 0 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,141 @@ ArcusFuture<Boolean> sopCreate(String key, ElementValueType type,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> sopDelete(String key, T value, boolean dropIfEmpty);

/**
* Create an empty map with the given attributes.
*
* @param key key of the map to create
* @param type element value type
* @param attributes initial attributes of the map
* @return {@code true} if created, {@code false} if the key already exists.
*/
ArcusFuture<Boolean> mopCreate(String key, ElementValueType type,
CollectionAttributes attributes);

/**
* Insert an element with the given MKey into a map.
*
* @param key key of the map
* @param mKey MKey of the element to insert
* @param value the value to insert
* @return {@code true} if the element was inserted, {@code false} if the MKey already exists,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopInsert(String key, String mKey, T value);

/**
* Insert an element with the given MKey into a map.
* If the map does not exist, it is created with the given attributes.
*
* @param key key of the map
* @param mKey MKey of the element to insert
* @param value the value to insert
* @param attributes attributes to use when creating the map
* @return {@code true} if the element was inserted, {@code false} if the MKey already exists,
* {@code null} if the key is not found.
*
*/
ArcusFuture<Boolean> mopInsert(String key, String mKey, T value, CollectionAttributes attributes);

/**
* Upsert an element with the given MKey in a map.
* If an element with the given MKey exists, it is replaced, otherwise a new element is inserted.
*
* @param key key of the map
* @param mKey MKey of the element to upsert
* @param value the value to insert or replace with
* @return {@code true} if the element was inserted or replaced,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopUpsert(String key, String mKey, T value);

/**
* Upsert an element with the given MKey in a map.
* If an element with the given MKey exists, it is replaced, otherwise a new element is inserted.
* If the map does not exist, it is created with the given attributes.
*
* @param key key of the map
* @param mKey MKey of the element to upsert
* @param value the value to insert or replace with
* @param attributes attributes to use when creating the map
* @return {@code true} if the element was inserted or replaced,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopUpsert(String key, String mKey, T value, CollectionAttributes attributes);

/**
* Update the value of an element with the given MKey in a map.
*
* @param key key of the map
* @param mKey MKey of the element to update
* @param value the new value
* @return {@code true} if the element was updated, {@code null} if the key is not found,
* {@code false} if the MKey is not found.
*/
ArcusFuture<Boolean> mopUpdate(String key, String mKey, T value);

/**
* Get all elements from a map.
*
* @param key key of the map
* @param args arguments for get operation
* @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);

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

/**
* 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
* @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);

/**
* Delete all elements from a map.
*
* @param key key of the map
* @param dropIfEmpty whether to drop the map if it becomes empty after delection
* @return {@code true} if the elements were deleted, {@code false} if no elements exist,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopDelete(String key, boolean dropIfEmpty);

/**
* Delete an element with the given MKey from a map.
*
* @param key key of the map
* @param mKey MKey of the element to delete
* @param dropIfEmpty whether to drop the map if it becomes empty after delection
* @return {@code true} if the element was deleted, {@code false} if the MKey is not found,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopDelete(String key, String mKey, boolean dropIfEmpty);

/**
* Delete elements with the given MKeys from a map.
*
* @param key key of the map
* @param mKeys MKey of the element to delete
* @param dropIfEmpty whether to drop the map if it becomes empty after delection
* @return {@code true} if the element was deleted, {@code false} if the MKey is not found,
* {@code null} if the key is not found.
*/
ArcusFuture<Boolean> mopDelete(String key, List<String> mKeys, boolean dropIfEmpty);

}
Loading
Loading