Package com.tnsai.coordination
Class WorkerPool
java.lang.Object
com.tnsai.coordination.WorkerPool
Manages a pool of worker agents for the orchestrator-worker pattern.
Tracks worker availability and load balancing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPool statistics.static classWorker status tracking. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWorker(com.tnsai.agents.Agent worker) Adds a worker to the pool.com.tnsai.agents.AgentGets the least loaded worker (worker with fewest active tasks).getName()com.tnsai.agents.AgentGets the next available worker using round-robin strategy.Gets statistics about the pool.List<com.tnsai.agents.Agent> Gets all workers in the pool.getWorkerStatus(String workerId) Gets status information for a specific worker.booleanisEmpty()Checks if the pool is empty.booleanremoveWorker(String workerId) Removes a worker from the pool.intsize()Gets the number of workers in the pool.voidtaskCompleted(String workerId, String taskId) Marks a task as completed for a worker.voidtaskStarted(String workerId, String taskId) Marks a task as started for a worker.toString()
-
Constructor Details
-
WorkerPool
-
-
Method Details
-
addWorker
public void addWorker(com.tnsai.agents.Agent worker) Adds a worker to the pool.- Parameters:
worker- the worker agent
-
removeWorker
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
Marks a task as started for a worker.- Parameters:
workerId- the worker IDtaskId- the task ID
-
taskCompleted
Marks a task as completed for a worker.- Parameters:
workerId- the worker IDtaskId- the task ID
-
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
Gets status information for a specific worker.- Parameters:
workerId- the worker ID- Returns:
- worker status, or null if not found
-
getStatistics
Gets statistics about the pool.- Returns:
- pool statistics
-
getName
-
toString
-