diff --git a/src/main/java/com/pivovarit/collectors/CollectingConfigurer.java b/src/main/java/com/pivovarit/collectors/CollectingConfigurer.java index f93a7cd7..3b07d78b 100644 --- a/src/main/java/com/pivovarit/collectors/CollectingConfigurer.java +++ b/src/main/java/com/pivovarit/collectors/CollectingConfigurer.java @@ -15,134 +15,19 @@ */ package com.pivovarit.collectors; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.Executor; -import java.util.function.UnaryOperator; - /** * Fluent configuration builder for collectors that collect all results (i.e. non-streaming). *
* Instances of this class are used internally to accumulate configuration options that are later
* interpreted by {@link ConfigProcessor}.
*/
-public final class CollectingConfigurer {
-
- private final List
- * 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.
- *
- * Note: 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 CollectingConfigurer batching() {
- addOnce(ConfigProcessor.Option.Batched.INSTANCE);
- return this;
- }
-
- /**
- * Sets the maximum level of parallelism.
- *
- * 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 CollectingConfigurer parallelism(int parallelism) {
- Preconditions.requireValidParallelism(parallelism);
-
- addOnce(new ConfigProcessor.Option.Parallelism(parallelism));
- return this;
- }
-
- /**
- * Sets the {@link Executor} used for running tasks.
- *
- * Note: The provided executor must not drop 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 CollectingConfigurer executor(Executor executor) {
- Preconditions.requireValidExecutor(executor);
-
- addOnce(new ConfigProcessor.Option.ThreadPool(executor));
- return this;
- }
-
- /**
- * Decorates the executor used for running tasks.
- *
- * The decorator receives the resolved executor (either the default virtual-thread executor or
- * the one provided via {@link #executor(Executor)}) and returns a wrapped replacement.
- * This is useful for augmenting the executor with cross-cutting concerns such as context
- * propagation (MDC, OpenTelemetry spans, etc.) or monitoring, without replacing the executor entirely.
- *
- * Note: The executor returned by the decorator must not drop tasks on rejection.
- * Dropping tasks will cause the collector to wait for results that will never be produced,
- * which can lead to deadlocks.
- *
- * @param decorator a function that wraps the resolved executor
- *
- * @return this configurer instance for fluent chaining
- */
- public CollectingConfigurer executorDecorator(UnaryOperator
- * The decorator receives the {@link Runnable} representing a single unit of work and returns a
- * wrapped replacement that runs in its place. This is useful for propagating thread-local context
- * (e.g. MDC entries, OpenTelemetry spans, {@code SecurityContext}) into worker threads, or for
- * per-task instrumentation, without replacing the executor entirely.
- *
- * Unlike {@link #executorDecorator(UnaryOperator)}, which wraps the executor as a whole,
- * this decorator is applied to each task individually and runs on the worker thread.
- *
- * @param decorator a function that wraps each submitted task
- *
- * @return this configurer instance for fluent chaining
- */
- public CollectingConfigurer taskDecorator(UnaryOperator
+ * 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.
+ *
+ * Note: 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.
+ *
+ * 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.
+ *
+ * Note: The provided executor must not drop 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();
+ }
+
+ /**
+ * Decorates the executor used for running tasks.
+ *
+ * The decorator receives the resolved executor (either the default virtual-thread executor or
+ * the one provided via {@link #executor(Executor)}) and returns a wrapped replacement.
+ * This is useful for augmenting the executor with cross-cutting concerns such as context
+ * propagation (MDC, OpenTelemetry spans, etc.) or monitoring, without replacing the executor entirely.
+ *
+ * Note: The executor returned by the decorator must not drop tasks on rejection.
+ * Dropping tasks will cause the collector to wait for results that will never be produced,
+ * which can lead to deadlocks.
+ *
+ * @param decorator a function that wraps the resolved executor
+ *
+ * @return this configurer instance for fluent chaining
+ */
+ public SELF executorDecorator(UnaryOperator
+ * The decorator receives the {@link Runnable} representing a single unit of work and returns a
+ * wrapped replacement that runs in its place. This is useful for propagating thread-local context
+ * (e.g. MDC entries, OpenTelemetry spans, {@code SecurityContext}) into worker threads, or for
+ * per-task instrumentation, without replacing the executor entirely.
+ *
+ * Unlike {@link #executorDecorator(UnaryOperator)}, which wraps the executor as a whole,
+ * this decorator is applied to each task individually and runs on the worker thread.
+ *
+ * @param decorator a function that wraps each submitted task
+ *
+ * @return this configurer instance for fluent chaining
+ */
+ public SELF taskDecorator(UnaryOperator
* Instances of this class are used internally to accumulate configuration options that are later
* interpreted by {@link ConfigProcessor}.
*/
-public final class StreamingConfigurer {
-
- private final List
@@ -50,114 +43,4 @@ public StreamingConfigurer ordered() {
addOnce(ConfigProcessor.Option.Ordered.INSTANCE);
return this;
}
-
- /**
- * Enables batching of work submitted to workers.
- *
- * 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.
- *
- * Note: 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 StreamingConfigurer batching() {
- addOnce(ConfigProcessor.Option.Batched.INSTANCE);
- return this;
- }
-
- /**
- * Sets the maximum level of parallelism.
- *
- * 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 StreamingConfigurer parallelism(int parallelism) {
- Preconditions.requireValidParallelism(parallelism);
-
- addOnce(new ConfigProcessor.Option.Parallelism(parallelism));
- return this;
- }
-
- /**
- * Sets the {@link Executor} used for running tasks.
- *
- * Use this to supply a custom execution strategy (for example, a dedicated thread pool).
- *
- * Note: The provided executor must not drop tasks on rejection (e.g. using a
- * {@code RejectedExecutionHandler} that discards submitted work). Dropping tasks will cause the
- * stream 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 StreamingConfigurer executor(Executor executor) {
- Preconditions.requireValidExecutor(executor);
-
- addOnce(new ConfigProcessor.Option.ThreadPool(executor));
- return this;
- }
-
- /**
- * Decorates the executor used for running tasks.
- *
- * The decorator receives the resolved executor (either the default virtual-thread executor or
- * the one provided via {@link #executor(Executor)}) and returns a wrapped replacement.
- * This is useful for augmenting the executor with cross-cutting concerns such as context
- * propagation (MDC, OpenTelemetry spans, etc.) or monitoring, without replacing the executor entirely.
- *
- * Note: The executor returned by the decorator must not drop tasks on rejection.
- * Dropping tasks will cause the stream to wait for results that will never be produced,
- * which can lead to deadlocks.
- *
- * @param decorator a function that wraps the resolved executor
- *
- * @return this configurer instance for fluent chaining
- */
- public StreamingConfigurer executorDecorator(UnaryOperator
- * The decorator receives the {@link Runnable} representing a single unit of work and returns a
- * wrapped replacement that runs in its place. This is useful for propagating thread-local context
- * (e.g. MDC entries, OpenTelemetry spans, {@code SecurityContext}) into worker threads, or for
- * per-task instrumentation, without replacing the executor entirely.
- *
- * Unlike {@link #executorDecorator(UnaryOperator)}, which wraps the executor as a whole,
- * this decorator is applied to each task individually and runs on the worker thread.
- *
- * @param decorator a function that wraps each submitted task
- *
- * @return this configurer instance for fluent chaining
- */
- public StreamingConfigurer taskDecorator(UnaryOperator