use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerde method bytesToBinary.
public static Bytes bytesToBinary(final Windowed<Bytes> sessionKey) {
final byte[] bytes = sessionKey.key().get();
ByteBuffer buf = ByteBuffer.allocate(bytes.length + 2 * TIMESTAMP_SIZE);
buf.put(bytes);
buf.putLong(sessionKey.window().end());
buf.putLong(sessionKey.window().start());
return new Bytes(buf.array());
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerde method toBinary.
public static <K> Bytes toBinary(final Windowed<K> sessionKey, final Serializer<K> serializer) {
final byte[] bytes = serializer.serialize(SESSIONKEY, sessionKey.key());
ByteBuffer buf = ByteBuffer.allocate(bytes.length + 2 * TIMESTAMP_SIZE);
buf.put(bytes);
buf.putLong(sessionKey.window().end());
buf.putLong(sessionKey.window().start());
return new Bytes(buf.array());
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class RocksDBSegmentedBytesStore method fetch.
@Override
public KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to) {
final List<Segment> searchSpace = keySchema.segmentsToSearch(segments, from, to);
final Bytes binaryFrom = keySchema.lowerRange(key, from);
final Bytes binaryTo = keySchema.upperRange(key, to);
return new SegmentIterator(searchSpace.iterator(), keySchema.hasNextCondition(key, from, to), binaryFrom, binaryTo);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySchema method hasNextCondition.
@Override
public HasNextCondition hasNextCondition(final Bytes binaryKey, final long from, final long to) {
return new HasNextCondition() {
@Override
public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) {
if (iterator.hasNext()) {
final Bytes bytes = iterator.peekNextKey();
final Bytes keyBytes = Bytes.wrap(SessionKeySerde.extractKeyBytes(bytes.get()));
if (!keyBytes.equals(binaryKey)) {
return false;
}
final long start = SessionKeySerde.extractStart(bytes.get());
final long end = SessionKeySerde.extractEnd(bytes.get());
return end >= from && start <= to;
}
return false;
}
};
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingKeyValueStore method delete.
@Override
public synchronized V delete(final K key) {
validateStoreOpen();
final byte[] rawKey = serdes.rawKey(key);
final Bytes bytesKey = Bytes.wrap(rawKey);
final V v = get(rawKey);
cache.delete(cacheName, bytesKey);
underlying.delete(bytesKey);
return v;
}
Aggregations