Search in sources :

Example 1 with Bytes

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());
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Bytes

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());
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Bytes

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);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes)

Example 4 with Bytes

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;
        }
    };
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator)

Example 5 with Bytes

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;
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)398 Test (org.junit.Test)309 Windowed (org.apache.kafka.streams.kstream.Windowed)84 KeyValue (org.apache.kafka.streams.KeyValue)68 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)53 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)50 Properties (java.util.Properties)49 ArrayList (java.util.ArrayList)42 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)38 StreamsConfig (org.apache.kafka.streams.StreamsConfig)35 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)35 Materialized (org.apache.kafka.streams.kstream.Materialized)33 Serdes (org.apache.kafka.common.serialization.Serdes)32 Metrics (org.apache.kafka.common.metrics.Metrics)29 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)27 Consumed (org.apache.kafka.streams.kstream.Consumed)25 KTable (org.apache.kafka.streams.kstream.KTable)23 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)22 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21