Skip to content

Unify CollectingConfigurer and StreamingConfigurer#1225

Open
pivovarit wants to merge 1 commit intomainfrom
configurer
Open

Unify CollectingConfigurer and StreamingConfigurer#1225
pivovarit wants to merge 1 commit intomainfrom
configurer

Conversation

@pivovarit
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 9, 2026 16:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the configuration builders by extracting shared configuration logic from CollectingConfigurer and StreamingConfigurer into a new common base class (Configurer) to remove duplication and centralize option handling.

Changes:

  • Introduce a shared Configurer<SELF> base class containing common configuration options and option de-duplication logic.
  • Update CollectingConfigurer and StreamingConfigurer to extend the new base class and remove duplicated implementations.
  • Keep streaming-specific configuration (ordered()) in StreamingConfigurer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/main/java/com/pivovarit/collectors/StreamingConfigurer.java Simplifies streaming configurer by inheriting common configuration methods from Configurer and keeping ordered().
src/main/java/com/pivovarit/collectors/Configurer.java Adds new shared base class implementing common fluent configuration methods and option tracking.
src/main/java/com/pivovarit/collectors/CollectingConfigurer.java Simplifies collecting configurer by inheriting common configuration methods from Configurer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +27 to +82
sealed abstract class Configurer<SELF extends Configurer<SELF>> permits CollectingConfigurer, StreamingConfigurer {

private final List<ConfigProcessor.Option> modifiers = new ArrayList<>();
private final Set<Class<? extends ConfigProcessor.Option>> seen = new HashSet<>();

abstract SELF self();

/**
* Enables batching of work submitted to workers.
* <p>
* When enabled, each worker thread receives a batch of input items and processes them in one go,
* instead of scheduling one task per item. This reduces the number of tasks created and typically
* decreases contention on the underlying worker queue.
*
* <p><b>Note:</b> Depending on batch sizing and workload skew, batching may reduce load balancing and
* can lead to thread starvation (some workers become idle while others remain overloaded).
*
* @return this configurer instance for fluent chaining
*/
public SELF batching() {
addOnce(ConfigProcessor.Option.Batched.INSTANCE);
return self();
}

/**
* Sets the maximum level of parallelism.
* <p>
* This limits the number of tasks submitted to the worker queue at once, effectively bounding
* the amount of in-flight work and the maximum concurrency used by the collector.
*
* @param parallelism the desired parallelism level (must be positive)
*
* @return this configurer instance for fluent chaining
*/
public SELF parallelism(int parallelism) {
Preconditions.requireValidParallelism(parallelism);
addOnce(new ConfigProcessor.Option.Parallelism(parallelism));
return self();
}

/**
* Sets the {@link Executor} used for running tasks.
*
* <p><b>Note:</b> The provided executor must not <em>drop</em> tasks on rejection (e.g. using a
* {@code RejectedExecutionHandler} that discards submitted work). Dropping tasks will cause the
* collector to wait for results that will never be produced, which can lead to deadlocks.
*
* @param executor the executor to use
*
* @return this configurer instance for fluent chaining
*/
public SELF executor(Executor executor) {
Preconditions.requireValidExecutor(executor);
addOnce(new ConfigProcessor.Option.ThreadPool(executor));
return self();
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configurer is package-private, but it now declares the public fluent API methods (batching/parallelism/executor/executorDecorator/taskDecorator). For callers outside com.pivovarit.collectors, these methods become inaccessible (e.g. Configurer.parallelism(int) is defined in an inaccessible class), which breaks the public CollectingConfigurer/StreamingConfigurer API used from README and ParallelCollectors examples. To keep the external API working, either make Configurer public, or redeclare these methods in each public configurer (delegating to the superclass) so the declaring class is accessible to library consumers.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants