Package net.rubyeye.xmemcached.transcoders

Examples of net.rubyeye.xmemcached.transcoders.CachedData


    }
  }

  @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

  static final byte EXTRAS_LENGTH = (byte) 8;

  @Override
  @SuppressWarnings("unchecked")
  public void encode() {
    CachedData data = null;
    if (this.transcoder != null) {
      data = this.transcoder.encode(this.value);
    }
    // header+key+value+extras
    int length = 24 + this.getKeyLength() + this.getValueLength(data)
View Full Code Here

  @Override
  public void testByteArray() throws Exception {
    byte[] a = { 'a', 'b', 'c' };
    try {
      CachedData cd = getTranscoder().encode(a);
      fail("Expected IllegalArgumentException, got " + cd);
    } catch (IllegalArgumentException e) {
      // pass
    }
  }
View Full Code Here

  public void testCompressedStringNotSmaller() throws Exception {
    String s1 = "This is a test simple string that will not be compressed.";
    // Reduce the compression threshold so it'll attempt to compress it.
    tc.setCompressionThreshold(8);
    CachedData cd = tc.encode(s1);
    // This should *not* be compressed because it is too small
    assertEquals(0, cd.getFlag());
    assertTrue(Arrays.equals(s1.getBytes(), cd.getData()));
    assertEquals(s1, tc.decode(cd));
  }
View Full Code Here

  public void testCompressedString() throws Exception {
    // This one will actually compress
    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    tc.setCompressionThreshold(8);
    CachedData cd = tc.encode(s1);
    assertEquals(SerializingTranscoder.COMPRESSED, cd.getFlag());
    assertFalse(Arrays.equals(s1.getBytes(), cd.getData()));
    assertEquals(s1, tc.decode(cd));
  }
View Full Code Here

    // do nothing
  }

  @Override
  protected boolean finish() {
    final CachedData cachedData = ((Map<String, CachedData>) this.result)
        .get(this.responseKey);
    Map<Object, Command> mergetCommands = getMergeCommands();
    if (mergetCommands != null) {
      final BinaryGetCommand command = (BinaryGetCommand) mergetCommands
          .remove(this.responseKey);
View Full Code Here

    }
    if (keyLength > 0) {
      byte[] bytes = new byte[keyLength];
      buffer.get(bytes);
      this.responseKey = ByteUtils.getString(bytes);
      CachedData value = new CachedData();
      value.setCas(this.responseCAS);
      value.setFlag(this.responseFlag);
      ((Map<String, CachedData>) this.result)
          .put(this.responseKey, value);
    }
    return true;
  }
View Full Code Here

  @Override
  protected boolean readValue(ByteBuffer buffer, int bodyLength,
      int keyLength, int extrasLength) {
    if (this.responseStatus == ResponseStatus.NO_ERROR) {
      int valueLength = bodyLength - keyLength - extrasLength;
      CachedData responseValue = ((Map<String, CachedData>) this.result)
          .get(this.responseKey);
      if (valueLength >= 0 && responseValue.getCapacity() < 0) {
        responseValue.setCapacity(valueLength);
        responseValue.setData(new byte[valueLength]);
      }
      int remainingCapacity = responseValue.remainingCapacity();
      int remaining = buffer.remaining();
      if (remaining < remainingCapacity) {
        int length = remaining > remainingCapacity ? remainingCapacity
            : remaining;
        responseValue.fillData(buffer, length);
        return false;
      } else if (remainingCapacity > 0) {
        responseValue.fillData(buffer, remainingCapacity);
      }
      return true;
    } else {
      ((Map<String, CachedData>) this.result).remove(this.responseKey);
      return true;
View Full Code Here

    assertEquals(s1, tc.decode(cd));
  }

  public void testObject() throws Exception {
    Calendar c = Calendar.getInstance();
    CachedData cd = tc.encode(c);
    assertEquals(SerializingTranscoder.SERIALIZED, cd.getFlag());
    assertEquals(c, tc.decode(cd));
  }
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.