Skip to content

Commit 7918946

Browse files
fabienrenaudMichael Nitschinger
authored andcommitted
Change MemcachedNodeROImpl and BaseGetOpImpl classes to public.
Motivation ---------- Implementing a custom NodeLocator requires to override the getReadonlyCopy method which in turn requires to use some MemcachedNode implementation. MemcachedNodeROImpl should be reusable outside of its package for that purpose. In addition, memcached being an open source project, its implementation can be changed or extended and commands such as GET may be used differently in these custom versions. The abstract BaseGetOpImpl should be flexible enough to be adapted to different but similar GET commands. Modifications ------------- The MemcachedNodeROImpl class accessor changes from package-private to public. The BaseGetOpImpl class accessor changes from package-private to public. The initialization method and constructors of BaseGetOpImpl changed to abstract the string appended to the <GET key> command. Result ------ Writing a custom NodeLocator outside of the net.spy.memcached package and supporting variants of GET commands is now easy. Change-Id: I49b3efc741ab4fe5780bf74ad5f99b839c9ceb7d Reviewed-on: http://review.couchbase.org/44565 Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com> Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
1 parent 95833c9 commit 7918946

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import net.spy.memcached.ops.Operation;
3434

35-
class MemcachedNodeROImpl implements MemcachedNode {
35+
public class MemcachedNodeROImpl implements MemcachedNode {
3636

3737
private final MemcachedNode root;
3838

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
/**
4242
* Base class for get and gets handlers.
4343
*/
44-
abstract class BaseGetOpImpl extends OperationImpl {
44+
public abstract class BaseGetOpImpl extends OperationImpl {
4545

4646
private static final OperationStatus END = new OperationStatus(true, "END",
4747
StatusCode.SUCCESS);
@@ -54,7 +54,7 @@ abstract class BaseGetOpImpl extends OperationImpl {
5454
private final Collection<String> keys;
5555
private String currentKey = null;
5656
protected final int exp;
57-
private final boolean hasExp;
57+
private final byte[] expBytes;
5858
private long casValue = 0;
5959
private int currentFlags = 0;
6060
private byte[] data = null;
@@ -67,7 +67,7 @@ public BaseGetOpImpl(String c, OperationCallback cb, Collection<String> k) {
6767
cmd = c;
6868
keys = k;
6969
exp = 0;
70-
hasExp = false;
70+
expBytes = null;
7171
hasValue = false;
7272
}
7373

@@ -76,7 +76,7 @@ public BaseGetOpImpl(String c, int e, OperationCallback cb, String k) {
7676
cmd = c;
7777
keys = Collections.singleton(k);
7878
exp = e;
79-
hasExp = true;
79+
expBytes = String.valueOf(e).getBytes();
8080
hasValue = false;
8181
}
8282

@@ -200,25 +200,33 @@ public final void initialize() {
200200
size += k.length;
201201
size++;
202202
}
203-
byte[] e = String.valueOf(exp).getBytes();
204-
if (hasExp) {
205-
size += e.length + 1;
206-
}
203+
size += afterKeyBytesSize();
207204
ByteBuffer b = ByteBuffer.allocate(size);
208205
b.put(cmd.getBytes());
209206
for (byte[] k : keyBytes) {
210207
b.put((byte) ' ');
211208
b.put(k);
212209
}
213-
if (hasExp) {
214-
b.put((byte) ' ');
215-
b.put(e);
216-
}
210+
afterKeyBytes(b);
217211
b.put(RN_BYTES);
218212
b.flip();
219213
setBuffer(b);
220214
}
221215

216+
protected int afterKeyBytesSize() {
217+
if (expBytes == null) {
218+
return 0;
219+
}
220+
return expBytes.length + 1;
221+
}
222+
223+
protected void afterKeyBytes(final ByteBuffer b) {
224+
if (expBytes != null) {
225+
b.put((byte) ' ');
226+
b.put(expBytes);
227+
}
228+
}
229+
222230
@Override
223231
protected final void wasCancelled() {
224232
getCallback().receivedStatus(CANCELLED);

0 commit comments

Comments
 (0)