use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.
the class TopologyTest method addProcessorWithStore.
private TopologyDescription.Processor addProcessorWithStore(final String processorName, final String[] storeNames, final boolean newStores, final TopologyDescription.Node... parents) {
final String[] parentNames = new String[parents.length];
for (int i = 0; i < parents.length; ++i) {
parentNames[i] = parents[i].name();
}
topology.addProcessor(processorName, new MockProcessorSupplier(), parentNames);
if (newStores) {
for (final String store : storeNames) {
final StoreBuilder storeBuilder = EasyMock.createNiceMock(StoreBuilder.class);
EasyMock.expect(storeBuilder.name()).andReturn(store).anyTimes();
EasyMock.replay(storeBuilder);
topology.addStateStore(storeBuilder, processorName);
}
} else {
topology.connectProcessorAndStateStores(processorName, storeNames);
}
final TopologyDescription.Processor expectedProcessorNode = new InternalTopologyBuilder.Processor(processorName, new HashSet<>(Arrays.asList(storeNames)));
for (final TopologyDescription.Node parent : parents) {
((InternalTopologyBuilder.AbstractNode) parent).addSuccessor(expectedProcessorNode);
((InternalTopologyBuilder.AbstractNode) expectedProcessorNode).addPredecessor(parent);
}
return expectedProcessorNode;
}
use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.
the class InternalStreamsBuilder method globalTable.
@SuppressWarnings("unchecked")
public <K, V> GlobalKTable<K, V> globalTable(final String topic, final ConsumedInternal<K, V> consumed, final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materialized) {
Objects.requireNonNull(consumed, "consumed can't be null");
Objects.requireNonNull(materialized, "materialized can't be null");
// explicitly disable logging for global stores
materialized.withLoggingDisabled();
final StoreBuilder storeBuilder = new KeyValueStoreMaterializer<>(materialized).materialize();
final String sourceName = newProcessorName(KStreamImpl.SOURCE_NAME);
final String processorName = newProcessorName(KTableImpl.SOURCE_NAME);
final KTableSource<K, V> tableSource = new KTableSource<>(storeBuilder.name());
internalTopologyBuilder.addGlobalStore(storeBuilder, sourceName, consumed.timestampExtractor(), consumed.keyDeserializer(), consumed.valueDeserializer(), topic, processorName, tableSource);
return new GlobalKTableImpl<>(new KTableSourceValueGetterSupplier<K, V>(storeBuilder.name()), materialized.isQueryable());
}
use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.
the class KTableImpl method doFilter.
private KTable<K, V> doFilter(final Predicate<? super K, ? super V> predicate, final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materialized, final boolean filterNot) {
String name = builder.newProcessorName(FILTER_NAME);
KTableProcessorSupplier<K, V, V> processorSupplier = new KTableFilter<>(this, predicate, filterNot, materialized.storeName());
builder.internalTopologyBuilder.addProcessor(name, processorSupplier, this.name);
final StoreBuilder builder = new KeyValueStoreMaterializer<>(materialized).materialize();
this.builder.internalTopologyBuilder.addStateStore(builder, name);
return new KTableImpl<>(this.builder, name, processorSupplier, this.keySerde, this.valSerde, sourceNodes, builder.name(), true);
}
use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.
the class RocksDBKeyValueStoreTest method createKeyValueStore.
@SuppressWarnings("unchecked")
@Override
protected <K, V> KeyValueStore<K, V> createKeyValueStore(final ProcessorContext context) {
final StoreBuilder storeBuilder = Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("my-store"), (Serde<K>) context.keySerde(), (Serde<V>) context.valueSerde());
final StateStore store = storeBuilder.build();
store.init(context, store);
return (KeyValueStore<K, V>) store;
}
use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.
the class InMemoryKeyValueStoreTest method createKeyValueStore.
@SuppressWarnings("unchecked")
@Override
protected <K, V> KeyValueStore<K, V> createKeyValueStore(final ProcessorContext context) {
final StoreBuilder storeBuilder = Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("my-store"), (Serde<K>) context.keySerde(), (Serde<V>) context.valueSerde());
final StateStore store = storeBuilder.build();
store.init(context, store);
return (KeyValueStore<K, V>) store;
}
Aggregations