Class LoadBalancer
java.lang.Object
com.tnsai.coordination.groups.hubspoke.LoadBalancer
Load balancer for distributing tasks to spoke agents.
Supports multiple balancing strategies:
- ROUND_ROBIN - Cycle through spokes in order
- LEAST_LOADED - Pick the spoke with fewest active tasks
- RANDOM - Random spoke selection
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLoadBalancer(LoadBalancer.Strategy strategy) Creates a load balancer with the given strategy. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current load for an agent.Returns the strategy used by this balancer.voidrecordTaskAssigned(String agentId) Records that a task was assigned to an agent.voidrecordTaskCompleted(String agentId) Records that a task was completed by an agent.com.tnsai.agents.AgentSelects a spoke agent for the next task.
-
Constructor Details
-
LoadBalancer
Creates a load balancer with the given strategy.- Parameters:
strategy- balancing strategy
-
-
Method Details
-
select
Selects a spoke agent for the next task.- Parameters:
spokes- available spoke agents- Returns:
- selected agent, or null if no spokes available
-
recordTaskAssigned
Records that a task was assigned to an agent.- Parameters:
agentId- agent ID
-
recordTaskCompleted
Records that a task was completed by an agent.- Parameters:
agentId- agent ID
-
getLoad
Returns the current load for an agent.- Parameters:
agentId- agent ID- Returns:
- current task count
-
getStrategy
Returns the strategy used by this balancer.- Returns:
- strategy
-