@Override public int getSize(StaticBuffer data) { return data.length(); }
public Entry(TransactionLogHeader header, StaticBuffer content, LogTxStatus status, EnumMap<LogTxMeta,Object> metadata) { Preconditions.checkArgument(status != null && metadata != null); Preconditions.checkArgument(header!=null); Preconditions.checkArgument(content==null || content.length()>0); this.header = header; this.content = content; this.status = status; this.metadata=metadata; }
public static Entry of(StaticBuffer buffer) { return new StaticArrayEntry(buffer,buffer.length()); }
public StaticBuffer serializeUserLog(Serializer serializer, Entry sourceTxEntry, StandardTransactionId sourceTxId) { Preconditions.checkArgument(sourceTxEntry!=null && sourceTxEntry.status==LogTxStatus.PRECOMMIT && sourceTxEntry.header.transactionId==sourceTxId.getTransactionId()); StaticBuffer sourceContent = sourceTxEntry.content; Preconditions.checkArgument(sourceContent!=null && sourceContent.length()>0); final EnumMap<LogTxMeta, Object> meta = new EnumMap<>(LogTxMeta.class); meta.put(LogTxMeta.SOURCE_TRANSACTION,sourceTxId); DataOutput out = serializeHeader(serializer, 50 + sourceContent.length(), LogTxStatus.USER_LOG, meta); out.putBytes(sourceContent); return out.getStaticBuffer(); }
private StaticBuffer concatenate(StaticBuffer front, StaticBuffer end, final boolean appendLength) { final boolean addKeyLength = !hasFixedKeyLength() && appendLength; int length = getLength(front); byte[] result = new byte[length + end.length() + (addKeyLength ? variableKeyLengthSize : 0)]; int position = 0; for (int i = 0; i < front.length(); i++) result[position++] = front.getByte(i); for (int i = 0; i < end.length(); i++) result[position++] = end.getByte(i); if (addKeyLength) { result[position++] = (byte) (length >>> 8); result[position] = (byte) length; } return StaticArrayBuffer.of(result); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; if (!(o instanceof StaticBuffer)) return false; final StaticBuffer b = (StaticBuffer) o; return length() == b.length() && compareTo(b) == 0; }
private int getKeyLength(StaticBuffer concat) { int length = keyLength; if (!hasFixedKeyLength()) { //variable key length length = concat.getShort(concat.length() - variableKeyLengthSize); } return length; }
public static WriteBuffer put(WriteBuffer out, StaticBuffer in) { for (int i=0;i<in.length();i++) out.putByte(in.getByte(i)); return out; }
public static void writeBuffer(DataOutput out, StaticBuffer buffer) { VariableLong.writePositive(out,buffer.length()); out.putBytes(buffer); }
private StaticBuffer getColumnFromKey(StaticBuffer concat) { int offset = getKeyLength(concat); int length = concat.length() - offset; if (!hasFixedKeyLength()) { //variable key length => remove length at end length -= variableKeyLengthSize; } return concat.subrange(offset, length); }
@Override public int compareTo(StaticBuffer other) { int otherLen = (other instanceof Entry)?((Entry) other).getValuePosition():other.length(); return compareTo(getValuePosition(),other, otherLen); }
public static StaticBuffer getKey(final HashLength hashPrefixLen, StaticBuffer hasPrefixedKey) { return hasPrefixedKey.subrange(hashPrefixLen.length(), hasPrefixedKey.length() - hashPrefixLen.length()); }
@Override public int compareTo(StaticBuffer other) { int otherLen = (other instanceof Entry)?((Entry) other).getValuePosition():other.length(); return compareTo(getValuePosition(),other, otherLen); }
private Entry writeMessage(KCVSMessage msg) { StaticBuffer content = msg.getContent(); DataOutput out = manager.serializer.getDataOutput(8 + 8 + manager.senderId.length() + 2 + content.length()); Instant rawTimestamp = msg.getTimestamp(); Preconditions.checkArgument(rawTimestamp.isAfter(Instant.EPOCH)); out.putLong(times.getTime(rawTimestamp)); out.writeObjectNotNull(manager.senderId); out.putLong(numMsgCounter.incrementAndGet()); final int valuePos = out.getPosition(); out.putBytes(content); return new StaticArrayEntry(out.getStaticBuffer(),valuePos); }
public StaticBuffer toLockCol(Instant ts, StaticBuffer rid, TimestampProvider provider) { WriteBuffer b = new WriteByteBuffer(rid.length() + 8); b.putLong(provider.getTime(ts)); WriteBufferUtil.put(b, rid); return b.getStaticBuffer(); }