Package net.rubyeye.xmemcached.transcoders

Examples of net.rubyeye.xmemcached.transcoders.CachedData


      // pass
    }
  }

  public void testUndecodeable() throws Exception {
    CachedData cd=new CachedData(
        Integer.MAX_VALUE &
        ~(SerializingTranscoder.COMPRESSED
            | SerializingTranscoder.SERIALIZED),
        tu.encodeInt(Integer.MAX_VALUE),
        tc.getMaxSize(),-1);
View Full Code Here


        tc.getMaxSize(),-1);
    assertNull(tc.decode(cd));
  }

  public void testUndecodeableSerialized() throws Exception {
    CachedData cd=new CachedData(SerializingTranscoder.SERIALIZED,
        tu.encodeInt(Integer.MAX_VALUE),
        tc.getMaxSize(),-1);
    assertNull(tc.decode(cd));
  }
View Full Code Here

        tc.getMaxSize(),-1);
    assertNull(tc.decode(cd));
  }

  public void testUndecodeableCompressed() throws Exception {
    CachedData cd=new CachedData(
      SerializingTranscoder.COMPRESSED,
      tu.encodeInt(Integer.MAX_VALUE),
      tc.getMaxSize(),-1);
    System.out.println("got " + tc.decode(cd));
    assertNull(tc.decode(cd));
View Full Code Here

          decodeError();
        } else {
          this.countDownLatch();
        }
      } else {
        CachedData data = this.returnValues.get(this.getKey());
        setResult(data);
        this.countDownLatch();
      }
    } else {
      // merge get
View Full Code Here

    }
  }

  @Override
  public final void encode() {
    final CachedData data = encodeValue();
    String cmdStr = getCommandName();
    byte[] encodedData = data.getData();
    int flag = data.getFlag();
    int size = cmdStr.length() + this.keyBytes.length
        + ByteUtils.stringSize(flag)
        + ByteUtils.stringSize(this.expTime) + encodedData.length
        + ByteUtils.stringSize(encodedData.length) + 8;
    if (this.commandType == CommandType.CAS) {
View Full Code Here

    this.ioBuffer = IoBuffer.wrap(buf);
  }

  @SuppressWarnings("unchecked")
  protected CachedData encodeValue() {
    final CachedData data = this.transcoder.encode(this.value);
    return data;
  }
View Full Code Here

        if (item == null) {
          return false;
        } else {
          this.currentReturnKey = item;
          this.returnValues.put(this.currentReturnKey,
              new CachedData());
          this.parseStatus = ParseStatus.FLAG;
          continue;
        }
      case FLAG:
        item = getItem(buffer, ' ');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setFlag(Integer.parseInt(item));
          this.parseStatus = ParseStatus.DATA_LEN;
          continue;
        }
      case DATA_LEN:
        item = getItem(buffer, '\r', ' ');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setCapacity(Integer.parseInt(item));
          assert (cachedData.getCapacity() >= 0);
          cachedData.setData(new byte[cachedData.getCapacity()]);
          this.parseStatus = ParseStatus.DATA_LEN_DONE;
          continue;
        }
      case DATA_LEN_DONE:
        if (buffer.remaining() < 1) {
          return false;
        } else {
          first = buffer.get(buffer.position());
          // check if buffer has cas value
          if (first == '\n') {
            // skip '\n'
            buffer.position(buffer.position() + 1);
            this.parseStatus = ParseStatus.DATA;
            continue;
          } else {
            this.parseStatus = ParseStatus.CAS;
            continue;
          }
        }
      case CAS:
        // has cas value
        item = getItem(buffer, '\r');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setCas(Long.parseLong(item));
          this.parseStatus = ParseStatus.CAS_DONE;
          continue;
        }
      case CAS_DONE:
        if (buffer.remaining() < 1) {
          return false;
        } else {
          this.parseStatus = ParseStatus.DATA;
          // skip '\n'
          buffer.position(buffer.position() + 1);
          continue;
        }
      case DATA:
        final CachedData value = this.returnValues
            .get(this.currentReturnKey);
        int remaining = buffer.remaining();
        int remainingCapacity = value.remainingCapacity();
        assert (remainingCapacity >= 0);
        // Data is not enough,return false
        if (remaining < remainingCapacity + 2) {
          int length = remaining > remainingCapacity ? remainingCapacity
              : remaining;
          value.fillData(buffer, length);
          return false;
        } else if (remainingCapacity > 0) {
          value.fillData(buffer, remainingCapacity);
        }
        assert (value.remainingCapacity() == 0);
        buffer
            .position(buffer.position()
                + ByteUtils.SPLIT.remaining());

        Map<Object, Command> mergetCommands = getMergeCommands();
View Full Code Here

        if (item == null) {
          return false;
        } else {
          this.currentReturnKey = item;
          this.returnValues.put(this.currentReturnKey,
              new CachedData());
          this.parseStatus = ParseStatus.FLAG;
          continue;
        }
      case FLAG:
        item = getItem(buffer, ' ');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setFlag(Integer.parseInt(item));
          this.parseStatus = ParseStatus.DATA_LEN;
          continue;
        }
      case DATA_LEN:
        item = getItem(buffer, '\r', ' ');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setCapacity(Integer.parseInt(item));
          assert (cachedData.getCapacity() >= 0);
          cachedData.setData(new byte[cachedData.getCapacity()]);
          this.parseStatus = ParseStatus.DATA_LEN_DONE;
          continue;
        }
      case DATA_LEN_DONE:
        if (buffer.remaining() < 1) {
          return false;
        } else {
          pos = buffer.position();
          first = buffer.get(pos);
          // check if buffer has cas value
          if (first == '\n') {
            // skip '\n'
            buffer.position(pos + 1);
            this.parseStatus = ParseStatus.DATA;
            continue;
          } else {
            this.parseStatus = ParseStatus.CAS;
            continue;
          }
        }
      case CAS:
        // has cas value
        item = getItem(buffer, '\r');
        if (item == null) {
          return false;
        } else {
          final CachedData cachedData = this.returnValues
              .get(this.currentReturnKey);
          cachedData.setCas(Long.parseLong(item));
          this.parseStatus = ParseStatus.CAS_DONE;
          continue;
        }
      case CAS_DONE:
        if (buffer.remaining() < 1) {
          return false;
        } else {
          this.parseStatus = ParseStatus.DATA;
          // skip '\n'
          buffer.position(buffer.position() + 1);
          continue;
        }
      case DATA:
        final CachedData value = this.returnValues
            .get(this.currentReturnKey);
        int remaining = buffer.remaining();
        int remainingCapacity = value.remainingCapacity();
        assert (remainingCapacity >= 0);
        // Data is not enough,return false
        if (remaining < remainingCapacity + 2) {
          int length = remaining > remainingCapacity ? remainingCapacity
              : remaining;
          value.fillData(buffer, length);
          return false;
        } else if (remainingCapacity > 0) {
          value.fillData(buffer, remainingCapacity);
        }
        assert (value.remainingCapacity() == 0);
        buffer
            .position(buffer.position()
                + ByteUtils.SPLIT.remaining());

        Map<Object, Command> mergetCommands = getMergeCommands();
View Full Code Here

  public BinaryGetCommand(String key, byte[] keyBytes, CommandType cmdType,
      CountDownLatch latch, OpCode opCode, boolean noreply) {
    super(key, keyBytes, cmdType, latch, 0, 0, null, noreply, null);
    this.opCode = opCode;
    this.responseValue = new CachedData();
  }
View Full Code Here

          decodeError();
        } else {
          this.countDownLatch();
        }
      } else {
        CachedData data = this.returnValues.get(this.getKey());
        setResult(data);
        this.countDownLatch();
      }
    } else {
      // merge get
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.transcoders.CachedData

Copyright © 2018 www.massapicom. 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.