Skip to content

Commit 446ffce

Browse files
committed
INTERNAL: Integration get and mget api
1 parent c9473d9 commit 446ffce

File tree

13 files changed

+105
-126
lines changed

13 files changed

+105
-126
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ public void gotData(String k, int flags, byte[] data) {
908908
public void complete() {
909909
latch.countDown();
910910
}
911-
});
911+
}, false);
912912
future.setOperation(op);
913913
addOp(key, op);
914914
return future;
@@ -960,7 +960,7 @@ public void gotData(String k, int flags, long cas, byte[] data) {
960960
public void complete() {
961961
latch.countDown();
962962
}
963-
});
963+
}, false);
964964
rv.setOperation(op);
965965
addOp(key, op);
966966
return rv;
@@ -1103,10 +1103,9 @@ public void complete() {
11031103

11041104
Operation op;
11051105
if (node == null) {
1106-
op = opFact.mget(keyList, cb);
1106+
op = opFact.get(keyList, cb, true);
11071107
} else {
1108-
op = node.enabledMGetOp() ? opFact.mget(keyList, cb)
1109-
: opFact.get(keyList, cb);
1108+
op = opFact.get(keyList, cb, node.enabledMGetOp());
11101109
}
11111110
conn.addOperation(node, op);
11121111
ops.add(op);
@@ -1240,10 +1239,9 @@ public void complete() {
12401239

12411240
Operation op;
12421241
if (node == null) {
1243-
op = opFact.mgets(keyList, cb);
1242+
op = opFact.gets(keyList, cb, true);
12441243
} else {
1245-
op = node.enabledMGetsOp() ? opFact.mgets(keyList, cb)
1246-
: opFact.gets(keyList, cb);
1244+
op = opFact.gets(keyList, cb, node.enabledMGetOp());
12471245
}
12481246
conn.addOperation(node, op);
12491247
ops.add(op);

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,55 +120,41 @@ public interface OperationFactory {
120120
*
121121
* @param key the key to get
122122
* @param callback the callback that will contain the results
123+
* @param isMget true if this is a multi-key get
123124
* @return a new GetOperation
124125
*/
125-
GetOperation get(String key, GetOperation.Callback callback);
126+
GetOperation get(String key, GetOperation.Callback callback, boolean isMget);
126127

127128
/**
128129
* Create a gets operation.
129130
*
130131
* @param key the key to get
131132
* @param callback the callback that will contain the results
133+
* @param isMget true if this is a multi-key get
132134
* @return a new GetsOperation
133135
*/
134-
GetsOperation gets(String key, GetsOperation.Callback callback);
136+
GetsOperation gets(String key, GetsOperation.Callback callback, boolean isMget);
135137

136138

137139
/**
138140
* Create a get operation.
139141
*
140142
* @param keys the collection of keys to get
141143
* @param cb the callback that will contain the results
144+
* @param isMget true if this is a multi-key get
142145
* @return a new GetOperation
143146
*/
144-
GetOperation get(Collection<String> keys, GetOperation.Callback cb);
147+
GetOperation get(Collection<String> keys, GetOperation.Callback cb, boolean isMget);
145148

146149
/**
147150
* Create a gets operation.
148151
*
149152
* @param keys the collection of keys to get
150153
* @param cb the callback that will contain the results
154+
* @param isMget true if this is a multi-key get
151155
* @return a new GetsOperation
152156
*/
153-
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb);
154-
155-
/**
156-
* Create a mget operation.
157-
*
158-
* @param keys the collection of keys to get
159-
* @param cb the callback that will contain the results
160-
* @return a new GetOperation
161-
*/
162-
GetOperation mget(Collection<String> keys, GetOperation.Callback cb);
163-
164-
/**
165-
* Create a mgets operation.
166-
*
167-
* @param keys the collection of keys to get
168-
* @param cb the callback that will contain the results
169-
* @return a new GetOperation
170-
*/
171-
GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb);
157+
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMget);
172158

173159
/**
174160
* Create a mutator operation.

src/main/java/net/spy/memcached/ops/BaseOperationFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public Collection<Operation> clone(KeyedOperation op) {
5252
GetOperation.Callback getCb = new MultiGetOperationCallback(
5353
op.getCallback(), op.getKeys().size());
5454
for (String k : op.getKeys()) {
55-
rv.add(get(k, getCb));
55+
rv.add(get(k, getCb, false));
5656
}
5757
} else if (op instanceof GetsOperation) {
5858
GetsOperation.Callback getsCb = new MultiGetsOperationCallback(
5959
op.getCallback(), op.getKeys().size());
6060
for (String k : op.getKeys()) {
61-
rv.add(gets(k, getsCb));
61+
rv.add(gets(k, getsCb, false));
6262
}
6363
} else if (op instanceof CASOperation) {
6464
CASOperation cop = (CASOperation) op;
@@ -136,11 +136,11 @@ public Operation cloneMultiOperation(KeyedOperation op, MemcachedNode node,
136136
assert !op.hasErrored() : "Attempted to clone an errored op";
137137

138138
if (op instanceof GetOperation) {
139-
// If MemcachedNode supports this clone feature, it should support mget operation too.
140-
return mget(redirectKeys, (GetOperation.Callback) mcb);
139+
// If MemcachedNode supports this clone feature, it should support get keys operation too.
140+
return get(redirectKeys, (GetOperation.Callback) mcb, false);
141141
} else if (op instanceof GetsOperation) {
142-
// If MemcachedNode supports this clone feature, it should support mgets operation too.
143-
return mgets(redirectKeys, (GetsOperation.Callback) mcb);
142+
// If MemcachedNode supports this clone feature, it should support gets keys operation too.
143+
return gets(redirectKeys, (GetsOperation.Callback) mcb, false);
144144
} else if (op instanceof CollectionBulkInsertOperation) {
145145
final CollectionBulkInsert<?> insert = ((CollectionBulkInsertOperation) op).getInsert();
146146
return collectionBulkInsert(insert.clone(node, redirectKeys), mcb);

src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
import net.spy.memcached.ops.StoreType;
8282
import net.spy.memcached.ops.VersionOperation;
8383

84+
import static net.spy.memcached.protocol.ascii.GetOperationImpl.generateGetOp;
85+
import static net.spy.memcached.protocol.ascii.GetsOperationImpl.generateGetsOp;
86+
8487
/**
8588
* Operation factory for the ascii protocol.
8689
*/
@@ -94,28 +97,20 @@ public FlushOperation flush(int delay, OperationCallback cb) {
9497
return new FlushOperationImpl(delay, cb);
9598
}
9699

97-
public GetOperation get(String key, GetOperation.Callback cb) {
98-
return new GetOperationImpl(key, cb);
99-
}
100-
101-
public GetOperation get(Collection<String> keys, GetOperation.Callback cb) {
102-
return new GetOperationImpl(keys, cb);
103-
}
104-
105-
public GetsOperation gets(String key, GetsOperation.Callback cb) {
106-
return new GetsOperationImpl(key, cb);
100+
public GetOperation get(String key, GetOperation.Callback cb, boolean isMget) {
101+
return generateGetOp(key, cb, isMget);
107102
}
108103

109-
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb) {
110-
return new GetsOperationImpl(keys, cb);
104+
public GetOperation get(Collection<String> keys, GetOperation.Callback cb, boolean isMget) {
105+
return generateGetOp(keys, cb, isMget);
111106
}
112107

113-
public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
114-
return new MGetOperationImpl(keys, cb);
108+
public GetsOperation gets(String key, GetsOperation.Callback cb, boolean isMget) {
109+
return generateGetsOp(key, cb, isMget);
115110
}
116111

117-
public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
118-
return new MGetsOperationImpl(keys, cb);
112+
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMget) {
113+
return generateGetsOp(keys, cb, isMget);
119114
}
120115

121116
public MutatorOperation mutate(Mutator m, String key, int by,

src/main/java/net/spy/memcached/protocol/ascii/GetOperationImpl.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,32 @@
1515
class GetOperationImpl extends BaseGetOpImpl implements GetOperation {
1616

1717
private static final String CMD = "get";
18+
private static final String CMD_MGET = "mget";
1819

19-
public GetOperationImpl(String key, GetOperation.Callback c) {
20-
super(CMD, c, Collections.singleton(key));
20+
public GetOperationImpl(String key, GetOperation.Callback c, String command) {
21+
super(command, c, Collections.singleton(key));
2122
setAPIType(APIType.GET);
2223
}
2324

24-
public GetOperationImpl(Collection<String> k, GetOperation.Callback c) {
25-
super(CMD, c, new HashSet<>(k));
25+
public GetOperationImpl(Collection<String> k, GetOperation.Callback c, String command) {
26+
super(command, c, new HashSet<>(k));
2627
setAPIType(APIType.GET);
2728
}
2829

30+
public static GetOperationImpl generateGetOp(String key, GetOperation.Callback c,
31+
boolean isMget) {
32+
if (isMget) {
33+
return new GetOperationImpl(key, c, CMD_MGET);
34+
}
35+
return new GetOperationImpl(key, c, CMD);
36+
}
37+
38+
public static GetOperationImpl generateGetOp(Collection<String> keys, GetOperation.Callback c,
39+
boolean isMget) {
40+
if (isMget) {
41+
return new GetOperationImpl(keys, c, CMD_MGET);
42+
}
43+
return new GetOperationImpl(keys, c, CMD);
44+
}
45+
2946
}

src/main/java/net/spy/memcached/protocol/ascii/GetsOperationImpl.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,32 @@
1313
class GetsOperationImpl extends BaseGetOpImpl implements GetsOperation {
1414

1515
private static final String CMD = "gets";
16+
private static final String CMD_MGETS = "mgets";
1617

17-
public GetsOperationImpl(String key, GetsOperation.Callback cb) {
18-
super(CMD, cb, Collections.singleton(key));
18+
public GetsOperationImpl(String key, GetsOperation.Callback cb, String command) {
19+
super(command, cb, Collections.singleton(key));
1920
setAPIType(APIType.GETS);
2021
}
2122

22-
public GetsOperationImpl(Collection<String> keys, GetsOperation.Callback cb) {
23-
super(CMD, cb, new HashSet<>(keys));
23+
public GetsOperationImpl(Collection<String> keys, GetsOperation.Callback cb, String command) {
24+
super(command, cb, new HashSet<>(keys));
2425
setAPIType(APIType.GETS);
2526
}
2627

28+
public static GetsOperationImpl generateGetsOp(String key, GetsOperation.Callback c,
29+
boolean isMget) {
30+
if (isMget) {
31+
return new GetsOperationImpl(key, c, CMD_MGETS);
32+
}
33+
return new GetsOperationImpl(key, c, CMD);
34+
}
35+
36+
public static GetsOperationImpl generateGetsOp(Collection<String> keys, GetsOperation.Callback c,
37+
boolean isMget) {
38+
if (isMget) {
39+
return new GetsOperationImpl(keys, c, CMD_MGETS);
40+
}
41+
return new GetsOperationImpl(keys, c, CMD);
42+
}
43+
2744
}

src/main/java/net/spy/memcached/protocol/ascii/MGetOperationImpl.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/net/spy/memcached/protocol/ascii/MGetsOperationImpl.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/net/spy/memcached/protocol/ascii/OptimizedGetImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
*/
1111
final class OptimizedGetImpl extends GetOperationImpl {
1212

13+
private static final String CMD = "get";
1314
private final ProxyCallback pcb;
1415

1516
/**
1617
* Construct an optimized get starting with the given get operation.
1718
*/
1819
public OptimizedGetImpl(GetOperation firstGet) {
19-
super(new HashSet<>(), new ProxyCallback());
20+
super(new HashSet<>(), new ProxyCallback(), CMD);
2021
pcb = (ProxyCallback) getCallback();
2122
addOperation(firstGet);
2223
}

src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,39 @@ public FlushOperation flush(int delay, OperationCallback cb) {
9696
return new FlushOperationImpl(cb);
9797
}
9898

99-
public GetOperation get(String key, Callback callback) {
99+
public GetOperation get(String key, Callback callback, boolean isMget) {
100+
if (isMget) {
101+
throw new RuntimeException(
102+
"mget is not supported in binary protocol yet.");
103+
}
100104
return new GetOperationImpl(key, callback);
101105
}
102106

103-
public GetOperation get(Collection<String> value, Callback cb) {
104-
return new MultiGetOperationImpl(value, cb);
107+
public GetOperation get(Collection<String> keys, Callback cb, boolean isMget) {
108+
if (isMget) {
109+
throw new RuntimeException(
110+
"mget is not supported in binary protocol yet.");
111+
}
112+
return new MultiGetOperationImpl(keys, cb);
105113
}
106114

107-
public GetsOperation gets(String key, GetsOperation.Callback cb) {
108-
return new GetOperationImpl(key, cb);
115+
public GetsOperation gets(String key, GetsOperation.Callback callback, boolean isMget) {
116+
if (isMget) {
117+
throw new RuntimeException(
118+
"mgets is not supported in binary protocol yet.");
119+
}
120+
return new GetOperationImpl(key, callback);
109121
}
110122

111-
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback callback) {
123+
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMget) {
124+
if (isMget) {
125+
throw new RuntimeException(
126+
"mgets is not supported in binary protocol yet.");
127+
}
112128
throw new RuntimeException(
113129
"gets is not supported in binary protocol yet.");
114130
}
115131

116-
public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
117-
throw new RuntimeException(
118-
"mget is not supported in binary protocol yet.");
119-
}
120-
121-
public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
122-
throw new RuntimeException(
123-
"mgets is not supported in binary protocol yet.");
124-
}
125-
126132
public MutatorOperation mutate(Mutator m, String key, int by,
127133
long def, int exp, OperationCallback cb) {
128134
return new MutatorOperationImpl(m, key, by, def, exp, cb);

0 commit comments

Comments
 (0)