All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.responsive.kafka.api.async.AsyncFixedKeyProcessorSupplier Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2024 Responsive Computing, Inc.
 *
 * This source code is licensed under the Responsive Business Source License Agreement v1.0
 * available at:
 *
 * https://www.responsive.dev/legal/responsive-bsl-10
 *
 * This software requires a valid Commercial License Key for production use. Trial and commercial
 * licenses can be obtained at https://www.responsive.dev
 */

package dev.responsive.kafka.api.async;

import static dev.responsive.kafka.api.async.internals.AsyncProcessor.createAsyncFixedKeyProcessor;
import static dev.responsive.kafka.api.async.internals.AsyncUtils.initializeAsyncBuilders;

import dev.responsive.kafka.api.async.internals.AsyncProcessor;
import dev.responsive.kafka.api.async.internals.stores.AbstractAsyncStoreBuilder;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.kafka.streams.processor.api.FixedKeyProcessor;
import org.apache.kafka.streams.processor.api.FixedKeyProcessorSupplier;
import org.apache.kafka.streams.processor.api.ProcessorSupplier;
import org.apache.kafka.streams.state.StoreBuilder;

/**
 * A fixed-key version of the async processing api, for topologies that use the
 * fixed-key PAPI. This should be used in place of
 * {@link FixedKeyProcessorSupplier} from Kafka Streams.
 * 

* See javadocs for {@link AsyncProcessorSupplier} for full instructions and * documentation on the async processing framework. */ public class AsyncFixedKeyProcessorSupplier implements FixedKeyProcessorSupplier { private final FixedKeyProcessorSupplier userProcessorSupplier; private final Map> asyncStoreBuilders; /** * Create an AsyncProcessorSupplier that wraps a custom {@link ProcessorSupplier} * to enable async processing. If you aren't using a fixed-key processor, use * {@link AsyncProcessorSupplier#createAsyncProcessorSupplier} instead * * @param processorSupplier the {@link FixedKeyProcessorSupplier} that returns a (new) * instance of your custom {@link FixedKeyProcessor} on each * invocation of {@link ProcessorSupplier#get} */ @SuppressWarnings("checkstyle:linelength") public static AsyncFixedKeyProcessorSupplier createAsyncProcessorSupplier( final FixedKeyProcessorSupplier processorSupplier ) { return new AsyncFixedKeyProcessorSupplier<>(processorSupplier, processorSupplier.stores()); } private AsyncFixedKeyProcessorSupplier( final FixedKeyProcessorSupplier userProcessorSupplier, final Set> userStoreBuilders ) { this.userProcessorSupplier = userProcessorSupplier; this.asyncStoreBuilders = initializeAsyncBuilders(userStoreBuilders); } @Override public AsyncProcessor get() { return createAsyncFixedKeyProcessor(userProcessorSupplier.get(), asyncStoreBuilders); } @Override public Set> stores() { return new HashSet<>(asyncStoreBuilders.values()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy