Interface HubSpoke

All Superinterfaces:
com.tnsai.agents.groups.AgentGroup
All Known Implementing Classes:
DefaultHubSpoke

public interface HubSpoke extends com.tnsai.agents.groups.AgentGroup
A hub-spoke organization with a central hub agent and peripheral spoke agents.

HubSpoke extends AgentGroup with centralized task routing through a hub agent, load-balanced distribution to spoke agents, and hub promotion.

Key Features

  • Central hub: One agent acts as coordinator
  • Spoke agents: Worker agents that receive tasks from the hub
  • Load balancing: Round-robin, least-loaded, or random distribution
  • Hub promotion: Any spoke can be promoted to hub

Usage Example


 HubSpoke hs = HubSpoke.builder()
     .name("Task Distributor")
     .hub(coordinator)
     .spoke(worker1)
     .spoke(worker2)
     .loadBalancing(LoadBalancer.Strategy.LEAST_LOADED)
     .build();

 hs.start();
 HubSpokeResult result = hs.routeToSpoke("Process this data");
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new HubSpoke builder.
    Optional<com.tnsai.agents.Agent>
    Returns the hub agent.
    Returns the load balancer.
    Returns the current load distribution across spokes.
    List<com.tnsai.agents.Agent>
    Returns all spoke agents.
    void
    Promotes a spoke agent to hub, making the current hub a spoke.
    Routes a task to an available spoke via the load balancer.
    void
    setHub(com.tnsai.agents.Agent agent)
    Sets the hub agent.

    Methods inherited from interface com.tnsai.agents.groups.AgentGroup

    addLifecycleListener, addMember, addMembershipListener, assignTask, broadcast, broadcast, dissolve, electLeader, electLeader, findMembers, getDescription, getEventBus, getId, getLeader, getLifecycle, getMember, getMemberCount, getMembers, getMembershipManager, getMetrics, getName, getPolicy, hasMember, isActive, isDissolved, removeLifecycleListener, removeMember, removeMembershipListener, scatter, scatter, scatterAsync, setPolicy, start, stop, stopNow
  • Method Details

    • getHub

      Optional<com.tnsai.agents.Agent> getHub()
      Returns the hub agent.
      Returns:
      hub agent, or empty if not set
    • getSpokes

      List<com.tnsai.agents.Agent> getSpokes()
      Returns all spoke agents.
      Returns:
      list of spoke agents
    • setHub

      void setHub(com.tnsai.agents.Agent agent)
      Sets the hub agent. Agent must already be a member.
      Parameters:
      agent - hub agent
    • promoteToHub

      void promoteToHub(String agentId)
      Promotes a spoke agent to hub, making the current hub a spoke.
      Parameters:
      agentId - agent ID to promote
      Throws:
      IllegalArgumentException - if agent is not a member
    • routeToSpoke

      HubSpokeResult routeToSpoke(String task)
      Routes a task to an available spoke via the load balancer.
      Parameters:
      task - task to route
      Returns:
      routing result
    • getLoadDistribution

      Map<String,Integer> getLoadDistribution()
      Returns the current load distribution across spokes.
      Returns:
      map of spoke ID to current task count
    • getLoadBalancer

      LoadBalancer getLoadBalancer()
      Returns the load balancer.
      Returns:
      load balancer
    • builder

      static HubSpokeBuilder builder()
      Creates a new HubSpoke builder.
      Returns:
      builder