Class WorkerPool

java.lang.Object
com.tnsai.coordination.WorkerPool

public class WorkerPool extends Object
Manages a pool of worker agents for the orchestrator-worker pattern. Tracks worker availability and load balancing.
  • Constructor Details

    • WorkerPool

      public WorkerPool(String name)
  • Method Details

    • addWorker

      public void addWorker(com.tnsai.agents.Agent worker)
      Adds a worker to the pool.
      Parameters:
      worker - the worker agent
    • removeWorker

      public boolean removeWorker(String workerId)
      Removes a worker from the pool.
      Parameters:
      workerId - the worker ID
      Returns:
      true if removed
    • getNextWorker

      public com.tnsai.agents.Agent getNextWorker()
      Gets the next available worker using round-robin strategy.
      Returns:
      the next worker, or null if no workers available
    • getLeastLoadedWorker

      public com.tnsai.agents.Agent getLeastLoadedWorker()
      Gets the least loaded worker (worker with fewest active tasks).
      Returns:
      the least loaded worker, or null if no workers available
    • taskStarted

      public void taskStarted(String workerId, String taskId)
      Marks a task as started for a worker.
      Parameters:
      workerId - the worker ID
      taskId - the task ID
    • taskCompleted

      public void taskCompleted(String workerId, String taskId)
      Marks a task as completed for a worker.
      Parameters:
      workerId - the worker ID
      taskId - the task ID
    • getWorkers

      public List<com.tnsai.agents.Agent> getWorkers()
      Gets all workers in the pool.
      Returns:
      immutable list of workers
    • size

      public int size()
      Gets the number of workers in the pool.
      Returns:
      worker count
    • isEmpty

      public boolean isEmpty()
      Checks if the pool is empty.
      Returns:
      true if no workers
    • getWorkerStatus

      public WorkerPool.WorkerStatus getWorkerStatus(String workerId)
      Gets status information for a specific worker.
      Parameters:
      workerId - the worker ID
      Returns:
      worker status, or null if not found
    • getStatistics

      public WorkerPool.PoolStatistics getStatistics()
      Gets statistics about the pool.
      Returns:
      pool statistics
    • getName

      public String getName()
    • toString

      public String toString()
      Overrides:
      toString in class Object