Interface WorkerPool

All Superinterfaces:
AutoCloseable, Executor, ExecutorService
All Known Implementing Classes:
ForkJoinPoolWrapper, ManagedThreadPool

public interface WorkerPool extends ExecutorService
Extension of ExecutorService that adds per-actor job management.

This interface exists primarily for backward compatibility with ForkJoinPool-based implementations. ForkJoinPool uses work-stealing with internally distributed queues that offer no API for external queue manipulation, making per-actor job cancellation impossible. Replacing it with ManagedThreadPool (ThreadPoolExecutor + LinkedBlockingDeque) enables direct queue access via queue.remove(), but would break callers that reference ExecutorService directly.

By introducing this interface with no-op default methods, existing ForkJoinPool wrappers continue to work unchanged. Only ManagedThreadPool overrides the defaults and returns supportsCancellation() == true.

Callers should check supportsCancellation() before relying on cancelJobsForActor(String).

Since:
2.0.0
Author:
devteam@scivicslab.com
See Also:
  • Method Details

    • cancelJobsForActor

      default int cancelJobsForActor(String actorName)
      Cancels all pending (not yet started) jobs submitted for the given actor. Jobs already running are not interrupted and will run to completion.

      The default implementation is a no-op for ForkJoinPool-based implementations, which cannot access their internal queues.

      Parameters:
      actorName - the name of the actor whose pending jobs should be cancelled
      Returns:
      the number of jobs removed from the queue; 0 if unsupported
    • getPendingJobCountForActor

      default int getPendingJobCountForActor(String actorName)
      Returns the number of pending (not yet started) jobs for the given actor.

      The default implementation returns 0 for ForkJoinPool-based implementations.

      Parameters:
      actorName - the name of the actor
      Returns:
      the number of pending jobs; 0 if unsupported
    • supportsCancellation

      default boolean supportsCancellation()
      Returns whether this implementation supports per-actor job cancellation.

      Returns false for ForkJoinPool-based implementations. Returns true for ManagedThreadPool.

      Returns:
      true if cancelJobsForActor(String) actually removes jobs