Package net.spy.memcached.protocol.binary

Source Code of net.spy.memcached.protocol.binary.MutatorOperationImpl

package net.spy.memcached.protocol.binary;

import net.spy.memcached.ops.MutatatorOperation;
import net.spy.memcached.ops.Mutator;
import net.spy.memcached.ops.OperationCallback;
import net.spy.memcached.ops.OperationStatus;

public class MutatorOperationImpl extends OperationImpl implements
    MutatatorOperation {

  private static final int CMD_INCR=5;

  private final String key;
  private final long by;
  private final int exp;
  private final long def;

  public MutatorOperationImpl(Mutator m, String k, long b,
      long d, int e, OperationCallback cb) {
    super(CMD_INCR, generateOpaque(), cb);
    assert d >= 0 : "Default value is below zero";
    key=k;
    by=m == Mutator.incr ? b : 0-b;
    exp=e;
    def=d;
  }

  @Override
  public void initialize() {
    // We're passing around a long so we can cover an unsigned integer.
    byte[] defBytes=new byte[8];
    defBytes[0]=(byte)((def >> 56) & 0xff);
    defBytes[1]=(byte)((def >> 48) & 0xff);
    defBytes[2]=(byte)((def >> 40) & 0xff);
    defBytes[3]=(byte)((def >> 32) & 0xff);
    defBytes[4]=(byte)((def >> 24) & 0xff);
    defBytes[5]=(byte)((def >> 16) & 0xff);
    defBytes[6]=(byte)((def >> 8) & 0xff);
    defBytes[7]=(byte)(def & 0xff);
    prepareBuffer(key, EMPTY_BYTES, by, defBytes, exp);
  }

  @Override
  protected OperationStatus getStatusForErrorCode(int errCode, byte[] errPl) {
    return errCode == ERR_NOT_FOUND ? NOT_FOUND_STATUS : null;
  }

  @Override
  protected void decodePayload(byte[] pl) {
    getCallback().receivedStatus(new OperationStatus(true,
      new String(pl)));
  }

}
TOP

Related Classes of net.spy.memcached.protocol.binary.MutatorOperationImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.