Search in sources :

Example 16 with KeyValueBytesStoreSupplier

use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafka by apache.

the class RangeQueryIntegrationTest method getStoreConfig.

private Materialized<String, String, KeyValueStore<Bytes, byte[]>> getStoreConfig(final StoreType type, final boolean cachingEnabled, final boolean loggingEnabled) {
    final Supplier<KeyValueBytesStoreSupplier> createStore = () -> {
        if (type == StoreType.InMemory) {
            return Stores.inMemoryKeyValueStore(TABLE_NAME);
        } else if (type == StoreType.RocksDB) {
            return Stores.persistentKeyValueStore(TABLE_NAME);
        } else if (type == StoreType.Timed) {
            return Stores.persistentTimestampedKeyValueStore(TABLE_NAME);
        } else {
            return Stores.inMemoryKeyValueStore(TABLE_NAME);
        }
    };
    final KeyValueBytesStoreSupplier stateStoreSupplier = createStore.get();
    final Materialized<String, String, KeyValueStore<Bytes, byte[]>> stateStoreConfig = Materialized.<String, String>as(stateStoreSupplier).withKeySerde(Serdes.String()).withValueSerde(Serdes.String());
    if (cachingEnabled) {
        stateStoreConfig.withCachingEnabled();
    } else {
        stateStoreConfig.withCachingDisabled();
    }
    if (loggingEnabled) {
        stateStoreConfig.withLoggingEnabled(new HashMap<>());
    } else {
        stateStoreConfig.withLoggingDisabled();
    }
    return stateStoreConfig;
}
Also used : KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) ReadOnlyKeyValueStore(org.apache.kafka.streams.state.ReadOnlyKeyValueStore)

Example 17 with KeyValueBytesStoreSupplier

use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafka by apache.

the class PositionRestartIntegrationTest method beforeTest.

public void beforeTest(final boolean cleanup) {
    final StoreSupplier<?> supplier = storeToTest.supplier();
    final StreamsBuilder builder = new StreamsBuilder();
    if (Objects.equals(kind, "DSL") && supplier instanceof KeyValueBytesStoreSupplier) {
        setUpKeyValueDSLTopology((KeyValueBytesStoreSupplier) supplier, builder);
    } else if (Objects.equals(kind, "PAPI") && supplier instanceof KeyValueBytesStoreSupplier) {
        setUpKeyValuePAPITopology((KeyValueBytesStoreSupplier) supplier, builder);
    } else if (Objects.equals(kind, "DSL") && supplier instanceof WindowBytesStoreSupplier) {
        setUpWindowDSLTopology((WindowBytesStoreSupplier) supplier, builder);
    } else if (Objects.equals(kind, "PAPI") && supplier instanceof WindowBytesStoreSupplier) {
        setUpWindowPAPITopology((WindowBytesStoreSupplier) supplier, builder);
    } else if (Objects.equals(kind, "DSL") && supplier instanceof SessionBytesStoreSupplier) {
        setUpSessionDSLTopology((SessionBytesStoreSupplier) supplier, builder);
    } else if (Objects.equals(kind, "PAPI") && supplier instanceof SessionBytesStoreSupplier) {
        setUpSessionPAPITopology((SessionBytesStoreSupplier) supplier, builder);
    } else {
        throw new AssertionError("Store supplier is an unrecognized type.");
    }
    kafkaStreams = IntegrationTestUtils.getStartedStreams(streamsConfig, builder, cleanup);
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) SessionBytesStoreSupplier(org.apache.kafka.streams.state.SessionBytesStoreSupplier)

Example 18 with KeyValueBytesStoreSupplier

use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafkastreams-cep by fhussonnois.

the class QueryStoreBuilders method getAggregateStateStore.

/**
 * Build all {@link StoreBuilder} used to store aggregate states for stages.
 *
 * @return a new collection of {@link StoreBuilder}.
 */
public StoreBuilder<AggregatesStateStore<K>> getAggregateStateStore(final Queried<K, V> queried) {
    final String storeName = QueryStores.getQueryAggregateStatesStoreName(queryName);
    final QueriedInternal<K, V> internal = new QueriedInternal<>(queried);
    KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier) internal.storeSupplier();
    if (supplier == null) {
        supplier = Stores.persistentKeyValueStore(storeName);
    }
    final StoreBuilder<AggregatesStateStore<K>> builder = QueryStores.aggregatesStoreBuilder(supplier);
    return mayEnableCaching(internal, mayEnableLogging(internal, builder));
}
Also used : KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) QueriedInternal(com.github.fhuss.kafka.streams.cep.state.internal.QueriedInternal)

Example 19 with KeyValueBytesStoreSupplier

use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafkastreams-cep by fhussonnois.

the class QueryStoreBuilders method getEventBufferStore.

/**
 * Build a new {@link StoreBuilder} used to store match sequences.
 *
 * @param queried the {@link Queried} instance.
 *
 * @return a new {@link StoreBuilder} instance.
 */
public StoreBuilder<SharedVersionedBufferStateStore<K, V>> getEventBufferStore(final Queried<K, V> queried) {
    final String storeName = QueryStores.getQueryEventBufferStoreName(queryName);
    final QueriedInternal<K, V> internal = new QueriedInternal<>(queried);
    KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier) internal.storeSupplier();
    if (supplier == null) {
        supplier = Stores.persistentKeyValueStore(storeName);
    }
    StoreBuilder<SharedVersionedBufferStateStore<K, V>> builder = QueryStores.bufferStoreBuilder(supplier, internal.keySerde(), internal.valueSerde());
    return mayEnableCaching(internal, mayEnableLogging(internal, builder));
}
Also used : KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) QueriedInternal(com.github.fhuss.kafka.streams.cep.state.internal.QueriedInternal)

Example 20 with KeyValueBytesStoreSupplier

use of org.apache.kafka.streams.state.KeyValueBytesStoreSupplier in project kafkastreams-cep by fhussonnois.

the class QueryStoreBuilders method getNFAStateStore.

/**
 * Build a persistent {@link StoreBuilder}.
 *
 * @param queried the {@link Queried} instance.
 *
 * @return a new {@link StoreBuilder} instance.
 */
public StoreBuilder<NFAStateStore<K, V>> getNFAStateStore(final Queried<K, V> queried) {
    final String storeName = QueryStores.getQueryNFAStoreName(queryName);
    final QueriedInternal<K, V> internal = new QueriedInternal<>(queried);
    KeyValueBytesStoreSupplier supplier = (KeyValueBytesStoreSupplier) internal.storeSupplier();
    if (supplier == null) {
        supplier = Stores.persistentKeyValueStore(storeName);
    }
    final NFAStoreBuilder<K, V> builder = QueryStores.nfaStoreBuilder(supplier, stages.getAllStages(), internal.keySerde(), internal.valueSerde());
    return mayEnableCaching(internal, mayEnableLogging(internal, builder));
}
Also used : KeyValueBytesStoreSupplier(org.apache.kafka.streams.state.KeyValueBytesStoreSupplier) QueriedInternal(com.github.fhuss.kafka.streams.cep.state.internal.QueriedInternal)

Aggregations

KeyValueBytesStoreSupplier (org.apache.kafka.streams.state.KeyValueBytesStoreSupplier)20 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)8 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)7 KafkaStreams (org.apache.kafka.streams.KafkaStreams)5 Test (org.junit.Test)5 QueriedInternal (com.github.fhuss.kafka.streams.cep.state.internal.QueriedInternal)3 Properties (java.util.Properties)3 SessionBytesStoreSupplier (org.apache.kafka.streams.state.SessionBytesStoreSupplier)3 WindowBytesStoreSupplier (org.apache.kafka.streams.state.WindowBytesStoreSupplier)3 InMemoryKeyValueStore (org.apache.kafka.streams.state.internals.InMemoryKeyValueStore)3 IntegrationTest (org.apache.kafka.test.IntegrationTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)2 Bytes (org.apache.kafka.common.utils.Bytes)2 Topology (org.apache.kafka.streams.Topology)2 MaterializedInternal (org.apache.kafka.streams.kstream.internals.MaterializedInternal)2 StateStore (org.apache.kafka.streams.processor.StateStore)2 ReadOnlyKeyValueStore (org.apache.kafka.streams.state.ReadOnlyKeyValueStore)2 TimestampedKeyValueStore (org.apache.kafka.streams.state.TimestampedKeyValueStore)2