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
75 changes: 32 additions & 43 deletions src/main/java/net/spy/memcached/ArcusClient.java

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/main/java/net/spy/memcached/OperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import javax.security.sasl.SaslClient;

import net.spy.memcached.collection.Attributes;
import net.spy.memcached.collection.BTreeFindPosition;
import net.spy.memcached.collection.BTreeFindPositionWithGet;
import net.spy.memcached.collection.BTreeGetBulk;
Expand All @@ -39,6 +38,7 @@
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.collection.CollectionPipedUpdate;
import net.spy.memcached.collection.CollectionUpdate;
import net.spy.memcached.collection.SetAttributes;
import net.spy.memcached.collection.SetPipedExist;
import net.spy.memcached.ops.BTreeFindPositionOperation;
import net.spy.memcached.ops.BTreeFindPositionWithGetOperation;
Expand Down Expand Up @@ -135,19 +135,19 @@ public interface OperationFactory {
/**
* Create a get operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mget command
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mget command
* @return a new GetOperation
*/
GetOperation get(Collection<String> keys, GetOperation.Callback cb, boolean isMGet);

/**
* Create a gets operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mgets command
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mgets command
* @return a new GetsOperation
*/
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet);
Expand All @@ -156,35 +156,35 @@ public interface OperationFactory {
* Get the key and resets its timeout.
*
* @param key the key to get a value for and reset its timeout
* @param expiration the new expiration for the key
* @param cb the callback that will contain the result
* @param exp the new expiration for the key
* @param cb the callback that will contain the result
* @return a new GetAndTouchOperation
*/
GetOperation getAndTouch(String key, int expiration, GetOperation.Callback cb);
GetOperation getAndTouch(String key, long exp, GetOperation.Callback cb);

/**
* Gets (with CAS support) the key and resets its timeout.
*
* @param key the key to get a value for and reset its timeout
* @param expiration the new expiration for the key
* @param cb the callback that will contain the result
* @param exp the new expiration for the key
* @param cb the callback that will contain the result
* @return a new GetsAndTouchOperation
*/
GetsOperation getsAndTouch(String key, int expiration, GetsOperation.Callback cb);
GetsOperation getsAndTouch(String key, long exp, GetsOperation.Callback cb);

/**
* Create a mutator operation.
*
* @param m the mutator type
* @param key the mutatee key
* @param key the mutate key
* @param by the amount to increment or decrement
* @param def the default value
* @param exp expiration in case we need to default (0 if no default)
* @param cb the status callback
* @return the new mutator operation
*/
MutatorOperation mutate(Mutator m, String key, int by,
long def, int exp, OperationCallback cb);
long def, long exp, OperationCallback cb);

/**
* Get a new StatsOperation.
Expand All @@ -206,18 +206,18 @@ MutatorOperation mutate(Mutator m, String key, int by,
* @param cb the status callback
* @return the new store operation
*/
StoreOperation store(StoreType storeType, String key, int flags, int exp,
StoreOperation store(StoreType storeType, String key, int flags, long exp,
byte[] data, OperationCallback cb);

/**
* Create a touch operation.
*
* @param key the key to touch
* @param expiration the new expiration time
* @param cb the status callback
* @param key the key to touch
* @param exp the new expiration time
Comment thread
f1v3-dev marked this conversation as resolved.
* @param cb the status callback
* @return the new touch operation
*/
TouchOperation touch(String key, int expiration, OperationCallback cb);
TouchOperation touch(String key, long exp, OperationCallback cb);

/**
* Get a concatenation operation.
Expand All @@ -244,7 +244,7 @@ ConcatenationOperation cat(ConcatenationType catType, long casId,
* @return the new store operation
*/
CASOperation cas(StoreType t, String key, long casId, int flags,
int exp, byte[] data, OperationCallback cb);
long exp, byte[] data, OperationCallback cb);

/**
* Create a new version operation.
Expand Down Expand Up @@ -274,8 +274,7 @@ CASOperation cas(StoreType t, String key, long casId, int flags,
* @param cb the status callback
* @return a new SetAttrOperation
*/
SetAttrOperation setAttr(String key, Attributes attrs,
OperationCallback cb);
SetAttrOperation setAttr(String key, SetAttributes attrs, OperationCallback cb);

/**
* Get item attributes
Expand All @@ -289,11 +288,11 @@ SetAttrOperation setAttr(String key, Attributes attrs,
/**
* Insert operation for collection items.
*
* @param key collection item's key
* @param subkey element key (list index, b+tree bkey)
* @param key collection item's key
* @param subkey element key (list index, b+tree bkey)
* @param collectionInsert operation parameters (value, eflags, attributes, and so on)
* @param data the serialized value
* @param cb the status callback
* @param data the serialized value
* @param cb the status callback
* @return a new CollectionInsertOperation
*/
CollectionInsertOperation collectionInsert(String key, String subkey,
Expand Down Expand Up @@ -374,6 +373,7 @@ CollectionExistOperation collectionExist(String key, String subkey,

Operation cloneMultiOperation(KeyedOperation op, MemcachedNode node,
List<String> redirectKeys, MultiOperationCallback mcb);

/**
* Create operation for collection items.
*
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/spy/memcached/collection/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import net.spy.memcached.compat.SpyObject;

public class Attributes extends SpyObject {
public class Attributes extends SpyObject implements SetAttributes {
public static final Integer DEFAULT_FLAGS = 0;
public static final Integer DEFAULT_EXPIRETIME = 0;

Expand All @@ -35,7 +35,8 @@ public Attributes(Integer expireTime) {
this.expireTime = expireTime;
}

protected String stringify() {
@Override
public String stringify() {
if (str != null) {
return str;
}
Expand Down Expand Up @@ -64,6 +65,7 @@ public String toString() {
return (str == null) ? stringify() : str;
}

@Override
public int getLength() {
return (str == null) ? stringify().length() : str.length();
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/spy/memcached/collection/BTreeCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class BTreeCreate extends CollectionCreate {

private static final String COMMAND = "bop create";

public BTreeCreate(int flags, Integer expTime, Long maxCount,
CollectionOverflowAction overflowAction, Boolean readable, boolean noreply) {
super(CollectionType.btree, flags, expTime, maxCount, overflowAction, readable, noreply);
public BTreeCreate(int flags, CreateAttributes attributes, boolean noreply) {
super(CollectionType.btree, flags, attributes, noreply);
}

public String getCommand() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/spy/memcached/collection/BTreeInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class BTreeInsert<T> extends CollectionInsert<T> {

private static final String COMMAND = "bop insert";

public BTreeInsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) {
super(CollectionType.btree, value, eFlag, requestMode, attr);
public BTreeInsert(T value, byte[] eFlag, RequestMode requestMode,
CreateAttributes attributes) {
super(CollectionType.btree, value, eFlag, requestMode, attributes);
}

public String getCommand() {
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/net/spy/memcached/collection/BTreeInsertAndGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ public class BTreeInsertAndGet<T> extends CollectionGet {
private BKeyObject bKey;

public BTreeInsertAndGet(long bkey, byte[] eFlag, T value, boolean updateIfExist,
CollectionAttributes attributesForCreate) {
if (updateIfExist) {
this.collection = new BTreeUpsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
} else {
this.collection = new BTreeInsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
}
this.updateIfExist = updateIfExist;
this.bKey = new BKeyObject(bkey);
this.eHeadCount = 2;
this.eFlagIndex = 1;
CreateAttributes attributes) {
this(new BKeyObject(bkey), eFlag, value, updateIfExist, attributes);
}

public BTreeInsertAndGet(byte[] bkey, byte[] eFlag, T value, boolean updateIfExist,
CollectionAttributes attributesForCreate) {
CreateAttributes attributes) {
this(new BKeyObject(bkey), eFlag, value, updateIfExist, attributes);
}

private BTreeInsertAndGet(BKeyObject bKey, byte[] eFlag, T value, boolean updateIfExist,
CreateAttributes attributes) {
if (updateIfExist) {
this.collection = new BTreeUpsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
this.collection = new BTreeUpsert<>(
value, eFlag, RequestMode.GET_TRIM, attributes
);
} else {
this.collection = new BTreeInsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
this.collection = new BTreeInsert<>(
value, eFlag, RequestMode.GET_TRIM, attributes
);
}
this.updateIfExist = updateIfExist;
this.bKey = new BKeyObject(bkey);
this.bKey = bKey;
this.eHeadCount = 2;
this.eFlagIndex = 1;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/spy/memcached/collection/BTreeUpsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class BTreeUpsert<T> extends CollectionInsert<T> {

private static final String COMMAND = "bop upsert";

public BTreeUpsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) {
super(CollectionType.btree, value, eFlag, requestMode, attr);
public BTreeUpsert(T value, byte[] eFlag, RequestMode requestMode,
CreateAttributes attributes) {
super(CollectionType.btree, value, eFlag, requestMode, attributes);
}

public String getCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public CollectionAttributes(Integer expireTime,
this.overflowAction = overflowAction;
}

protected String stringify() {
@Override
public String stringify() {
StringBuilder b = new StringBuilder();

if (flags != null) {
Expand Down Expand Up @@ -81,14 +82,11 @@ protected String stringify() {
}

@Override
public String toString() {
return (stringCache == null) ? stringify() : stringCache;
}

public int getLength() {
return (stringCache == null) ? stringify().length() : stringCache.length();
}

@Override
public void setAttribute(String attribute) {
String[] splited = attribute.split("=");
assert splited.length == 2 : "An attribute should be given in \"name=value\" format.";
Expand All @@ -97,13 +95,7 @@ public void setAttribute(String attribute) {
String value = splited[1];

try {
if ("flags".equals(name)) {
flags = Integer.parseInt(value);
} else if ("expiretime".equals(name)) {
expireTime = Integer.parseInt(value);
} else if ("type".equals(name)) {
type = CollectionType.find(value);
} else if ("count".equals(name)) {
if ("count".equals(name)) {
count = Long.parseLong(value);
} else if ("maxcount".equals(name)) {
maxCount = Long.parseLong(value);
Expand Down Expand Up @@ -138,6 +130,9 @@ public void setAttribute(String attribute) {
}
} else if ("trimmed".equals(name)) {
trimmed = Long.parseLong(value);
} else {
// flags, expiretime, type are handled by the base class.
super.setAttribute(attribute);
}
} catch (Exception e) {
getLogger().info(e, e);
Expand Down
Loading
Loading