Skip to content

Commit

Permalink
Issue 96: ClassPathException fix
Browse files Browse the repository at this point in the history
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 <matt@couchbase.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information
Mike Wiederhold authored and Michael Wiederhold committed Jul 11, 2011
1 parent e50ec2d commit 5f01535
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FlushOperation flush(int delay, OperationCallback cb) {

public GetAndTouchOperation getAndTouch(String key, int expiration,
GetAndTouchOperation.Callback cb) {
return new GetOperationImpl(key, expiration, cb);
return new GetAndTouchOperationImpl(key, expiration, cb);
}

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

public GetlOperation getl(String key, int exp, GetlOperation.Callback cb) {
return new GetOperationImpl(key, exp, cb);
return new GetlOperationImpl(key, exp, cb);
}

public GetsOperation gets(String key, GetsOperation.Callback cb) {
return new GetOperationImpl(key, cb);
return new GetsOperationImpl(key, cb);
}

public MutatorOperation mutate(Mutator m, String key, int by,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.spy.memcached.protocol.binary;

import net.spy.memcached.ops.GetAndTouchOperation;

public class GetAndTouchOperationImpl extends SingleKeyOperationImpl
implements GetAndTouchOperation {

static final int GAT_CMD=0x1d;

/**
* Length of the extra header stuff for a GET response.
*/
static final int EXTRA_HDR_LEN=4;

private final int exp;

public GetAndTouchOperationImpl(String k, int e, GetAndTouchOperation.Callback cb) {
super(GAT_CMD, generateOpaque(), k, cb);
exp=e;
}

@Override
public void initialize() {
prepareBuffer(key, 0, EMPTY_BYTES, exp);
}

@Override
protected void decodePayload(byte[] pl) {
final int flags=decodeInt(pl, 0);
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
GetAndTouchOperation.Callback gcb=(GetAndTouchOperation.Callback)getCallback();
gcb.gotData(key, flags, responseCas, data);
getCallback().receivedStatus(STATUS_OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package net.spy.memcached.protocol.binary;

import net.spy.memcached.ops.GetAndTouchOperation;
import net.spy.memcached.ops.GetOperation;
import net.spy.memcached.ops.GetlOperation;
import net.spy.memcached.ops.GetsOperation;
import net.spy.memcached.ops.OperationCallback;

class GetOperationImpl extends SingleKeyOperationImpl
implements GetOperation, GetsOperation, GetlOperation, GetAndTouchOperation {
implements GetOperation {

static final int GET_CMD=0x00;
static final int GETL_CMD=0x94;
Expand All @@ -18,59 +14,22 @@ class GetOperationImpl extends SingleKeyOperationImpl
*/
static final int EXTRA_HDR_LEN=4;

private final int exp;

public GetOperationImpl(String k, GetOperation.Callback cb) {
super(GET_CMD, generateOpaque(), k, cb);
exp=0;
}

public GetOperationImpl(String k, GetsOperation.Callback cb) {
super(GET_CMD, generateOpaque(), k, cb);
exp=0;
}

public GetOperationImpl(String k, int e, GetlOperation.Callback cb) {
super(GETL_CMD, generateOpaque(), k, cb);
exp=e;
}

public GetOperationImpl(String k, int e, GetAndTouchOperation.Callback cb) {
super(GAT_CMD, generateOpaque(), k, cb);
exp=e;
}

@Override
public void initialize() {
if (exp > 0) {
prepareBuffer(key, 0, EMPTY_BYTES, exp);
} else {
prepareBuffer(key, 0, EMPTY_BYTES);
}
prepareBuffer(key, 0, EMPTY_BYTES);
}

@Override
protected void decodePayload(byte[] pl) {
final int flags=decodeInt(pl, 0);
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
// Assume we're processing a get unless the cast fails.
OperationCallback cb = getCallback();
if (cb instanceof GetOperation.Callback) {
GetOperation.Callback gcb=(GetOperation.Callback)cb;
gcb.gotData(key, flags, data);
} else if (cb instanceof GetsOperation.Callback) {
GetsOperation.Callback gcb=(GetsOperation.Callback)cb;
gcb.gotData(key, flags, responseCas, data);
} else if (cb instanceof GetlOperation.Callback) {
GetlOperation.Callback gcb=(GetlOperation.Callback)cb;
gcb.gotData(key, flags, responseCas, data);
} else if (cb instanceof GetAndTouchOperation.Callback) {
GetAndTouchOperation.Callback gcb=(GetAndTouchOperation.Callback)cb;
gcb.gotData(key, flags, responseCas, data);
} else {
throw new ClassCastException("Couldn't convert " + cb + "to a relevent op");
}
GetOperation.Callback gcb=(GetOperation.Callback)getCallback();
gcb.gotData(key, flags, data);
getCallback().receivedStatus(STATUS_OK);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.spy.memcached.protocol.binary;

import net.spy.memcached.ops.GetlOperation;

public class GetlOperationImpl extends SingleKeyOperationImpl
implements GetlOperation {

static final int GETL_CMD=0x94;

/**
* Length of the extra header stuff for a GET response.
*/
static final int EXTRA_HDR_LEN=4;

private final int exp;

public GetlOperationImpl(String k, int e, GetlOperation.Callback cb) {
super(GETL_CMD, generateOpaque(), k, cb);
exp=e;
}

@Override
public void initialize() {
prepareBuffer(key, 0, EMPTY_BYTES, exp);
}

@Override
protected void decodePayload(byte[] pl) {
final int flags=decodeInt(pl, 0);
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
GetlOperation.Callback gcb=(GetlOperation.Callback)getCallback();
gcb.gotData(key, flags, responseCas, data);
getCallback().receivedStatus(STATUS_OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.spy.memcached.protocol.binary;

import net.spy.memcached.ops.GetsOperation;

public class GetsOperationImpl extends SingleKeyOperationImpl
implements GetsOperation {

static final int GET_CMD=0x00;

/**
* Length of the extra header stuff for a GET response.
*/
static final int EXTRA_HDR_LEN=4;

public GetsOperationImpl(String k, GetsOperation.Callback cb) {
super(GET_CMD, generateOpaque(), k, cb);
}

@Override
public void initialize() {
prepareBuffer(key, 0, EMPTY_BYTES);
}

@Override
protected void decodePayload(byte[] pl) {
final int flags=decodeInt(pl, 0);
final byte[] data=new byte[pl.length - EXTRA_HDR_LEN];
System.arraycopy(pl, EXTRA_HDR_LEN, data, 0, pl.length-EXTRA_HDR_LEN);
GetsOperation.Callback gcb=(GetsOperation.Callback)getCallback();
gcb.gotData(key, flags, responseCas, data);
getCallback().receivedStatus(STATUS_OK);
}

}

0 comments on commit 5f01535

Please sign in to comment.