use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerdeTest method shouldConvertToBinaryAndBack.
@Test
public void shouldConvertToBinaryAndBack() throws Exception {
final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
final Windowed<String> result = SessionKeySerde.from(serialized.get(), Serdes.String().deserializer());
assertEquals(windowedKey, result);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingKeyValueStore method range.
@Override
public KeyValueIterator<K, V> range(final K from, final K to) {
validateStoreOpen();
final Bytes origFrom = Bytes.wrap(serdes.rawKey(from));
final Bytes origTo = Bytes.wrap(serdes.rawKey(to));
final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo);
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo);
return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingSessionStore method putAndMaybeForward.
private void putAndMaybeForward(final ThreadCache.DirtyEntry entry, final InternalProcessorContext context) {
final Bytes binaryKey = entry.key();
final RecordContext current = context.recordContext();
context.setRecordContext(entry.recordContext());
try {
final Windowed<K> key = SessionKeySerde.from(binaryKey.get(), keySerde.deserializer());
if (flushListener != null) {
final AGG newValue = serdes.valueFrom(entry.newValue());
final AGG oldValue = fetchPrevious(binaryKey);
if (!(newValue == null && oldValue == null)) {
flushListener.apply(key, newValue == null ? null : newValue, oldValue);
}
}
bytesStore.put(new Windowed<>(Bytes.wrap(serdes.rawKey(key.key())), key.window()), entry.newValue());
} finally {
context.setRecordContext(current);
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class CachingWindowStore method fetch.
@Override
public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) {
// since this function may not access the underlying inner store, we need to validate
// if store is open outside as well.
validateStoreOpen();
Bytes fromBytes = WindowStoreUtils.toBinaryKey(key, timeFrom, 0, serdes);
Bytes toBytes = WindowStoreUtils.toBinaryKey(key, timeTo, 0, serdes);
final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key));
final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo);
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, fromBytes, toBytes);
final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes, timeFrom, timeTo);
final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition);
return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator, underlyingIterator, new StateSerdes<>(serdes.stateName(), Serdes.Long(), serdes.valueSerde()));
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class ChangeLoggingKeyValueStore method put.
@Override
public void put(final K key, final V value) {
final Bytes bytesKey = Bytes.wrap(serdes.rawKey(key));
final byte[] bytesValue = serdes.rawValue(value);
innerBytes.put(bytesKey, bytesValue);
}
Aggregations