Skip to content

Commit 5f01535

Browse files
Mike WiederholdMichael Wiederhold
authored andcommitted
Issue 96: ClassPathException fix
The issue here was that we were combinding multiple types of get operations in the same class, but each operation would have a different Callback type. When we would go to optimize get operations it would optimize get, getl, gat, and gets operations and since they have different callback types we would throw an exception. Each operation now has its own class. Change-Id: I4ca0da4f9638f7fe3a69bbe55dfb3edf30ae13cc Reviewed-on: http://review.couchbase.org/7877 Reviewed-by: Matt Ingenthron <[email protected]> Tested-by: Matt Ingenthron <[email protected]>
1 parent e50ec2d commit 5f01535

File tree

5 files changed

+114
-48
lines changed

5 files changed

+114
-48
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public FlushOperation flush(int delay, OperationCallback cb) {
5252

5353
public GetAndTouchOperation getAndTouch(String key, int expiration,
5454
GetAndTouchOperation.Callback cb) {
55-
return new GetOperationImpl(key, expiration, cb);
55+
return new GetAndTouchOperationImpl(key, expiration, cb);
5656
}
5757

5858
public GetOperation get(String key, Callback callback) {
@@ -64,11 +64,11 @@ public GetOperation get(Collection<String> value, Callback cb) {
6464
}
6565

6666
public GetlOperation getl(String key, int exp, GetlOperation.Callback cb) {
67-
return new GetOperationImpl(key, exp, cb);
67+
return new GetlOperationImpl(key, exp, cb);
6868
}
6969

7070
public GetsOperation gets(String key, GetsOperation.Callback cb) {
71-
return new GetOperationImpl(key, cb);
71+
return new GetsOperationImpl(key, cb);
7272
}
7373

7474
public MutatorOperation mutate(Mutator m, String key, int by,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.spy.memcached.protocol.binary;
2+
3+
import net.spy.memcached.ops.GetAndTouchOperation;
4+
5+
public class GetAndTouchOperationImpl extends SingleKeyOperationImpl
6+
implements GetAndTouchOperation {
7+
8+
static final int GAT_CMD=0x1d;
9+
10+
/**
11+
* Length of the extra header stuff for a GET response.
12+
*/
13+
static final int EXTRA_HDR_LEN=4;
14+
15+
private final int exp;
16+
17+
public GetAndTouchOperationImpl(String k, int e, GetAndTouchOperation.Callback cb) {
18+
super(GAT_CMD, generateOpaque(), k, cb);
19+
exp=e;
20+
}
21+
22+
@Override
23+
public void initialize() {
24+
prepareBuffer(key, 0, EMPTY_BYTES, exp);
25+
}
26+
27+
@Override
28+
protected void decodePayload(byte[] pl) {
29+
final int flags=decodeInt(pl, 0);
30+
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
31+
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
32+
GetAndTouchOperation.Callback gcb=(GetAndTouchOperation.Callback)getCallback();
33+
gcb.gotData(key, flags, responseCas, data);
34+
getCallback().receivedStatus(STATUS_OK);
35+
}
36+
37+
}

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package net.spy.memcached.protocol.binary;
22

3-
import net.spy.memcached.ops.GetAndTouchOperation;
43
import net.spy.memcached.ops.GetOperation;
5-
import net.spy.memcached.ops.GetlOperation;
6-
import net.spy.memcached.ops.GetsOperation;
7-
import net.spy.memcached.ops.OperationCallback;
84

95
class GetOperationImpl extends SingleKeyOperationImpl
10-
implements GetOperation, GetsOperation, GetlOperation, GetAndTouchOperation {
6+
implements GetOperation {
117

128
static final int GET_CMD=0x00;
139
static final int GETL_CMD=0x94;
@@ -18,59 +14,22 @@ class GetOperationImpl extends SingleKeyOperationImpl
1814
*/
1915
static final int EXTRA_HDR_LEN=4;
2016

21-
private final int exp;
22-
2317
public GetOperationImpl(String k, GetOperation.Callback cb) {
2418
super(GET_CMD, generateOpaque(), k, cb);
25-
exp=0;
26-
}
27-
28-
public GetOperationImpl(String k, GetsOperation.Callback cb) {
29-
super(GET_CMD, generateOpaque(), k, cb);
30-
exp=0;
31-
}
32-
33-
public GetOperationImpl(String k, int e, GetlOperation.Callback cb) {
34-
super(GETL_CMD, generateOpaque(), k, cb);
35-
exp=e;
36-
}
37-
38-
public GetOperationImpl(String k, int e, GetAndTouchOperation.Callback cb) {
39-
super(GAT_CMD, generateOpaque(), k, cb);
40-
exp=e;
4119
}
4220

4321
@Override
4422
public void initialize() {
45-
if (exp > 0) {
46-
prepareBuffer(key, 0, EMPTY_BYTES, exp);
47-
} else {
48-
prepareBuffer(key, 0, EMPTY_BYTES);
49-
}
23+
prepareBuffer(key, 0, EMPTY_BYTES);
5024
}
5125

5226
@Override
5327
protected void decodePayload(byte[] pl) {
5428
final int flags=decodeInt(pl, 0);
5529
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
5630
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
57-
// Assume we're processing a get unless the cast fails.
58-
OperationCallback cb = getCallback();
59-
if (cb instanceof GetOperation.Callback) {
60-
GetOperation.Callback gcb=(GetOperation.Callback)cb;
61-
gcb.gotData(key, flags, data);
62-
} else if (cb instanceof GetsOperation.Callback) {
63-
GetsOperation.Callback gcb=(GetsOperation.Callback)cb;
64-
gcb.gotData(key, flags, responseCas, data);
65-
} else if (cb instanceof GetlOperation.Callback) {
66-
GetlOperation.Callback gcb=(GetlOperation.Callback)cb;
67-
gcb.gotData(key, flags, responseCas, data);
68-
} else if (cb instanceof GetAndTouchOperation.Callback) {
69-
GetAndTouchOperation.Callback gcb=(GetAndTouchOperation.Callback)cb;
70-
gcb.gotData(key, flags, responseCas, data);
71-
} else {
72-
throw new ClassCastException("Couldn't convert " + cb + "to a relevent op");
73-
}
31+
GetOperation.Callback gcb=(GetOperation.Callback)getCallback();
32+
gcb.gotData(key, flags, data);
7433
getCallback().receivedStatus(STATUS_OK);
7534
}
7635

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.spy.memcached.protocol.binary;
2+
3+
import net.spy.memcached.ops.GetlOperation;
4+
5+
public class GetlOperationImpl extends SingleKeyOperationImpl
6+
implements GetlOperation {
7+
8+
static final int GETL_CMD=0x94;
9+
10+
/**
11+
* Length of the extra header stuff for a GET response.
12+
*/
13+
static final int EXTRA_HDR_LEN=4;
14+
15+
private final int exp;
16+
17+
public GetlOperationImpl(String k, int e, GetlOperation.Callback cb) {
18+
super(GETL_CMD, generateOpaque(), k, cb);
19+
exp=e;
20+
}
21+
22+
@Override
23+
public void initialize() {
24+
prepareBuffer(key, 0, EMPTY_BYTES, exp);
25+
}
26+
27+
@Override
28+
protected void decodePayload(byte[] pl) {
29+
final int flags=decodeInt(pl, 0);
30+
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
31+
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
32+
GetlOperation.Callback gcb=(GetlOperation.Callback)getCallback();
33+
gcb.gotData(key, flags, responseCas, data);
34+
getCallback().receivedStatus(STATUS_OK);
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.spy.memcached.protocol.binary;
2+
3+
import net.spy.memcached.ops.GetsOperation;
4+
5+
public class GetsOperationImpl extends SingleKeyOperationImpl
6+
implements GetsOperation {
7+
8+
static final int GET_CMD=0x00;
9+
10+
/**
11+
* Length of the extra header stuff for a GET response.
12+
*/
13+
static final int EXTRA_HDR_LEN=4;
14+
15+
public GetsOperationImpl(String k, GetsOperation.Callback cb) {
16+
super(GET_CMD, generateOpaque(), k, cb);
17+
}
18+
19+
@Override
20+
public void initialize() {
21+
prepareBuffer(key, 0, EMPTY_BYTES);
22+
}
23+
24+
@Override
25+
protected void decodePayload(byte[] pl) {
26+
final int flags=decodeInt(pl, 0);
27+
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
28+
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
29+
GetsOperation.Callback gcb=(GetsOperation.Callback)getCallback();
30+
gcb.gotData(key, flags, responseCas, data);
31+
getCallback().receivedStatus(STATUS_OK);
32+
}
33+
34+
}

0 commit comments

Comments
 (0)