Class LoadBalancer

java.lang.Object
com.tnsai.coordination.groups.hubspoke.LoadBalancer

public class LoadBalancer extends Object
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
  • Constructor Details

    • LoadBalancer

      public LoadBalancer(LoadBalancer.Strategy strategy)
      Creates a load balancer with the given strategy.
      Parameters:
      strategy - balancing strategy
  • Method Details

    • select

      public com.tnsai.agents.Agent select(List<com.tnsai.agents.Agent> spokes)
      Selects a spoke agent for the next task.
      Parameters:
      spokes - available spoke agents
      Returns:
      selected agent, or null if no spokes available
    • recordTaskAssigned

      public void recordTaskAssigned(String agentId)
      Records that a task was assigned to an agent.
      Parameters:
      agentId - agent ID
    • recordTaskCompleted

      public void recordTaskCompleted(String agentId)
      Records that a task was completed by an agent.
      Parameters:
      agentId - agent ID
    • getLoad

      public int getLoad(String agentId)
      Returns the current load for an agent.
      Parameters:
      agentId - agent ID
      Returns:
      current task count
    • getStrategy

      public LoadBalancer.Strategy getStrategy()
      Returns the strategy used by this balancer.
      Returns:
      strategy