Skip to content

Commit bda88de

Browse files
committed
FEATURE: Support long type expiration time in v2 APIs
1 parent e6f3d23 commit bda88de

51 files changed

Lines changed: 1084 additions & 481 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/net/spy/memcached/ArcusClient.java

Lines changed: 36 additions & 43 deletions
Large diffs are not rendered by default.

src/main/java/net/spy/memcached/OperationFactory.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import javax.security.sasl.SaslClient;
2323

24-
import net.spy.memcached.collection.Attributes;
2524
import net.spy.memcached.collection.BTreeFindPosition;
2625
import net.spy.memcached.collection.BTreeFindPositionWithGet;
2726
import net.spy.memcached.collection.BTreeGetBulk;
@@ -39,6 +38,7 @@
3938
import net.spy.memcached.collection.CollectionPipedInsert;
4039
import net.spy.memcached.collection.CollectionPipedUpdate;
4140
import net.spy.memcached.collection.CollectionUpdate;
41+
import net.spy.memcached.collection.SetAttributes;
4242
import net.spy.memcached.collection.SetPipedExist;
4343
import net.spy.memcached.ops.BTreeFindPositionOperation;
4444
import net.spy.memcached.ops.BTreeFindPositionWithGetOperation;
@@ -156,35 +156,35 @@ public interface OperationFactory {
156156
* Get the key and resets its timeout.
157157
*
158158
* @param key the key to get a value for and reset its timeout
159-
* @param expiration the new expiration for the key
159+
* @param exp the new expiration for the key
160160
* @param cb the callback that will contain the result
161161
* @return a new GetAndTouchOperation
162162
*/
163-
GetOperation getAndTouch(String key, int expiration, GetOperation.Callback cb);
163+
GetOperation getAndTouch(String key, long exp, GetOperation.Callback cb);
164164

165165
/**
166166
* Gets (with CAS support) the key and resets its timeout.
167167
*
168168
* @param key the key to get a value for and reset its timeout
169-
* @param expiration the new expiration for the key
169+
* @param exp the new expiration for the key
170170
* @param cb the callback that will contain the result
171171
* @return a new GetsAndTouchOperation
172172
*/
173-
GetsOperation getsAndTouch(String key, int expiration, GetsOperation.Callback cb);
173+
GetsOperation getsAndTouch(String key, long exp, GetsOperation.Callback cb);
174174

175175
/**
176176
* Create a mutator operation.
177177
*
178178
* @param m the mutator type
179-
* @param key the mutatee key
179+
* @param key the mutate key
180180
* @param by the amount to increment or decrement
181181
* @param def the default value
182182
* @param exp expiration in case we need to default (0 if no default)
183183
* @param cb the status callback
184184
* @return the new mutator operation
185185
*/
186186
MutatorOperation mutate(Mutator m, String key, int by,
187-
long def, int exp, OperationCallback cb);
187+
long def, long exp, OperationCallback cb);
188188

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

212212
/**
213213
* Create a touch operation.
214214
*
215215
* @param key the key to touch
216-
* @param expiration the new expiration time
216+
* @param exp the new expiration time
217217
* @param cb the status callback
218218
* @return the new touch operation
219219
*/
220-
TouchOperation touch(String key, int expiration, OperationCallback cb);
220+
TouchOperation touch(String key, long exp, OperationCallback cb);
221221

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

249249
/**
250250
* Create a new version operation.
@@ -274,8 +274,7 @@ CASOperation cas(StoreType t, String key, long casId, int flags,
274274
* @param cb the status callback
275275
* @return a new SetAttrOperation
276276
*/
277-
SetAttrOperation setAttr(String key, Attributes attrs,
278-
OperationCallback cb);
277+
SetAttrOperation setAttr(String key, SetAttributes attrs, OperationCallback cb);
279278

280279
/**
281280
* Get item attributes

src/main/java/net/spy/memcached/collection/Attributes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import net.spy.memcached.compat.SpyObject;
2020

21-
public class Attributes extends SpyObject {
21+
public class Attributes extends SpyObject implements SetAttributes {
2222
public static final Integer DEFAULT_FLAGS = 0;
2323
public static final Integer DEFAULT_EXPIRETIME = 0;
2424

@@ -35,7 +35,8 @@ public Attributes(Integer expireTime) {
3535
this.expireTime = expireTime;
3636
}
3737

38-
protected String stringify() {
38+
@Override
39+
public String stringify() {
3940
if (str != null) {
4041
return str;
4142
}
@@ -64,6 +65,7 @@ public String toString() {
6465
return (str == null) ? stringify() : str;
6566
}
6667

68+
@Override
6769
public int getLength() {
6870
return (str == null) ? stringify().length() : str.length();
6971
}

src/main/java/net/spy/memcached/collection/BTreeCreate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public class BTreeCreate extends CollectionCreate {
2020

2121
private static final String COMMAND = "bop create";
2222

23-
public BTreeCreate(int flags, Integer expTime, Long maxCount,
24-
CollectionOverflowAction overflowAction, Boolean readable, boolean noreply) {
25-
super(CollectionType.btree, flags, expTime, maxCount, overflowAction, readable, noreply);
23+
public BTreeCreate(int flags, CreateAttributes option, boolean noreply) {
24+
super(CollectionType.btree, flags, option, noreply);
2625
}
2726

2827
public String getCommand() {

src/main/java/net/spy/memcached/collection/BTreeInsert.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public class BTreeInsert<T> extends CollectionInsert<T> {
2020

2121
private static final String COMMAND = "bop insert";
2222

23-
public BTreeInsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) {
24-
super(CollectionType.btree, value, eFlag, requestMode, attr);
23+
public BTreeInsert(T value, byte[] eFlag, RequestMode requestMode,
24+
CreateAttributes createAttributes) {
25+
super(CollectionType.btree, value, eFlag, requestMode, createAttributes);
2526
}
2627

2728
public String getCommand() {

src/main/java/net/spy/memcached/collection/BTreeInsertAndGet.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,28 @@ public class BTreeInsertAndGet<T> extends CollectionGet {
4040
private BKeyObject bKey;
4141

4242
public BTreeInsertAndGet(long bkey, byte[] eFlag, T value, boolean updateIfExist,
43-
CollectionAttributes attributesForCreate) {
44-
if (updateIfExist) {
45-
this.collection = new BTreeUpsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
46-
} else {
47-
this.collection = new BTreeInsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
48-
}
49-
this.updateIfExist = updateIfExist;
50-
this.bKey = new BKeyObject(bkey);
51-
this.eHeadCount = 2;
52-
this.eFlagIndex = 1;
43+
CreateAttributes createAttributes) {
44+
this(new BKeyObject(bkey), eFlag, value, updateIfExist, createAttributes);
5345
}
5446

5547
public BTreeInsertAndGet(byte[] bkey, byte[] eFlag, T value, boolean updateIfExist,
56-
CollectionAttributes attributesForCreate) {
48+
CreateAttributes createAttributes) {
49+
this(new BKeyObject(bkey), eFlag, value, updateIfExist, createAttributes);
50+
}
51+
52+
private BTreeInsertAndGet(BKeyObject bKey, byte[] eFlag, T value, boolean updateIfExist,
53+
CreateAttributes createOptionForCreate) {
5754
if (updateIfExist) {
58-
this.collection = new BTreeUpsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
55+
this.collection = new BTreeUpsert<>(
56+
value, eFlag, RequestMode.GET_TRIM, createOptionForCreate
57+
);
5958
} else {
60-
this.collection = new BTreeInsert<>(value, eFlag, RequestMode.GET_TRIM, attributesForCreate);
59+
this.collection = new BTreeInsert<>(
60+
value, eFlag, RequestMode.GET_TRIM, createOptionForCreate
61+
);
6162
}
6263
this.updateIfExist = updateIfExist;
63-
this.bKey = new BKeyObject(bkey);
64+
this.bKey = bKey;
6465
this.eHeadCount = 2;
6566
this.eFlagIndex = 1;
6667
}

src/main/java/net/spy/memcached/collection/BTreeUpsert.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public class BTreeUpsert<T> extends CollectionInsert<T> {
2020

2121
private static final String COMMAND = "bop upsert";
2222

23-
public BTreeUpsert(T value, byte[] eFlag, RequestMode requestMode, CollectionAttributes attr) {
24-
super(CollectionType.btree, value, eFlag, requestMode, attr);
23+
public BTreeUpsert(T value, byte[] eFlag, RequestMode requestMode,
24+
CreateAttributes createAttributes) {
25+
super(CollectionType.btree, value, eFlag, requestMode, createAttributes);
2526
}
2627

2728
public String getCommand() {

src/main/java/net/spy/memcached/collection/CollectionAttributes.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public CollectionAttributes(Integer expireTime,
4848
this.overflowAction = overflowAction;
4949
}
5050

51-
protected String stringify() {
51+
@Override
52+
public String stringify() {
5253
StringBuilder b = new StringBuilder();
5354

5455
if (flags != null) {
@@ -81,14 +82,11 @@ protected String stringify() {
8182
}
8283

8384
@Override
84-
public String toString() {
85-
return (stringCache == null) ? stringify() : stringCache;
86-
}
87-
8885
public int getLength() {
8986
return (stringCache == null) ? stringify().length() : stringCache.length();
9087
}
9188

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

9997
try {
100-
if ("flags".equals(name)) {
101-
flags = Integer.parseInt(value);
102-
} else if ("expiretime".equals(name)) {
103-
expireTime = Integer.parseInt(value);
104-
} else if ("type".equals(name)) {
105-
type = CollectionType.find(value);
106-
} else if ("count".equals(name)) {
98+
if ("count".equals(name)) {
10799
count = Long.parseLong(value);
108100
} else if ("maxcount".equals(name)) {
109101
maxCount = Long.parseLong(value);
@@ -138,6 +130,9 @@ public void setAttribute(String attribute) {
138130
}
139131
} else if ("trimmed".equals(name)) {
140132
trimmed = Long.parseLong(value);
133+
} else {
134+
// flags, expiretime, type are handled by the base class.
135+
super.setAttribute(attribute);
141136
}
142137
} catch (Exception e) {
143138
getLogger().info(e, e);

0 commit comments

Comments
 (0)