Exemplo n.º 1
0
public class CounterCacheKey implements CacheKey {
  private static final long EMPTY_SIZE =
      ObjectSizes.measure(
              new CounterCacheKey(
                  null,
                  ByteBufferUtil.EMPTY_BYTE_BUFFER,
                  CellNames.simpleDense(ByteBuffer.allocate(1))))
          + ObjectSizes.measure(new UUID(0, 0));

  public final UUID cfId;
  public final byte[] partitionKey;
  public final byte[] cellName;

  private CounterCacheKey(UUID cfId, ByteBuffer partitionKey, CellName cellName) {
    this.cfId = cfId;
    this.partitionKey = ByteBufferUtil.getArray(partitionKey);
    this.cellName = ByteBufferUtil.getArray(cellName.toByteBuffer());
  }

  public static CounterCacheKey create(UUID cfId, ByteBuffer partitionKey, CellName cellName) {
    return new CounterCacheKey(cfId, partitionKey, cellName);
  }

  public UUID getCFId() {
    return cfId;
  }

  public long unsharedHeapSize() {
    return EMPTY_SIZE + ObjectSizes.sizeOfArray(partitionKey) + ObjectSizes.sizeOfArray(cellName);
  }

  @Override
  public String toString() {
    return String.format(
        "CounterCacheKey(%s, %s, %s)",
        cfId,
        ByteBufferUtil.bytesToHex(ByteBuffer.wrap(partitionKey)),
        ByteBufferUtil.bytesToHex(ByteBuffer.wrap(cellName)));
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {cfId, partitionKey, cellName});
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;

    if (!(o instanceof CounterCacheKey)) return false;

    CounterCacheKey cck = (CounterCacheKey) o;

    return cfId.equals(cck.cfId)
        && Arrays.equals(partitionKey, cck.partitionKey)
        && Arrays.equals(cellName, cck.cellName);
  }
}
Exemplo n.º 2
0
 public long unsharedHeapSize() {
   return EMPTY_SIZE + ObjectSizes.sizeOfArray(partitionKey) + ObjectSizes.sizeOfArray(cellName);
 }