- All Implemented Interfaces:
AutoCloseable
This class supports parallel execution and optional event-based instrumentation. Two execution modes are available:
- Internal thread pool: Created via
withThreads(int), shut down byclose(). UsesForkJoinPoolinternally to handle nested parallelism without deadlock. - External executor: Provided via
withExecutor(ExecutorService), NOT shut down byclose()
An optional ValidationEventListener can be configured via
withListener(ValidationEventListener) to receive callbacks during
validation. By default, a NoOpValidationEventListener is used,
ensuring zero overhead when instrumentation is not needed.
Instances should be used with try-with-resources or explicitly closed after validation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ValidationConfigSingle-threaded sequential execution (default, current behavior). -
Method Summary
Modifier and TypeMethodDescription@Owning ValidationConfigaddListener(ValidationEventListener additionalListener) Create a new configuration that adds an additional event listener, preserving the current parallel execution settings and any existing listener.voidclose()Shut down internal executor if one was created.Get the executor service, creating an internal pool if needed.Get the configured validation event listener.booleanCheck if parallel execution is enabled.static @Owning ValidationConfigwithExecutor(ExecutorService executor) Create configuration using an application-provided executor.@Owning ValidationConfigwithListener(ValidationEventListener listener) Create a new configuration with the specified event listener, preserving the current parallel execution settings.static @Owning ValidationConfigwithThreads(int threadCount) Create configuration that creates an internal thread pool.
-
Field Details
-
SEQUENTIAL
Single-threaded sequential execution (default, current behavior).This instance does not need to be closed.
-
-
Method Details
-
withExecutor
@NonNull @Owning public static @Owning ValidationConfig withExecutor(@NonNull ExecutorService executor) Create configuration using an application-provided executor.The executor is NOT shut down by
close(); the caller retains ownership.The caller owns the returned configuration and is responsible for closing it.
- Parameters:
executor- the executor service to use for parallel tasks- Returns:
- configuration using the provided executor
- Throws:
NullPointerException- if executor is null
-
withThreads
Create configuration that creates an internal thread pool.The internal pool is shut down when
close()is called.The caller owns the returned configuration and is responsible for closing it.
- Parameters:
threadCount- number of threads (must be >= 1)- Returns:
- configuration with internal thread pool
- Throws:
IllegalArgumentException- if threadCount < 1
-
withListener
@NonNull @Owning public @Owning ValidationConfig withListener(@NonNull ValidationEventListener listener) Create a new configuration with the specified event listener, preserving the current parallel execution settings.If this config owns its executor, the derived config will lazily create its own independent pool to avoid unsafe sharing of owned executors.
- Parameters:
listener- the event listener to use for validation instrumentation- Returns:
- a new configuration with the given listener
- Throws:
NullPointerException- if listener is null
-
addListener
@NonNull @Owning public @Owning ValidationConfig addListener(@NonNull ValidationEventListener additionalListener) Create a new configuration that adds an additional event listener, preserving the current parallel execution settings and any existing listener.If the current listener is a
NoOpValidationEventListener, the new listener replaces it directly. Otherwise, aCompositeValidationEventListeneris created to deliver events to both the existing and new listeners.- Parameters:
additionalListener- the additional event listener to add- Returns:
- a new configuration with the additional listener
- Throws:
NullPointerException- if additionalListener is null
-
isParallel
public boolean isParallel()Check if parallel execution is enabled.- Returns:
- true if using more than one thread
-
getListener
Get the configured validation event listener.- Returns:
- the event listener, never null
-
getExecutor
Get the executor service, creating an internal pool if needed.For internal pools, the executor is created lazily on first call.
- Returns:
- the executor service
- Throws:
IllegalStateException- if called on SEQUENTIAL config
-
close
public void close()Shut down internal executor if one was created.Does nothing if using an external executor or if no executor was created.
- Specified by:
closein interfaceAutoCloseable
-