Class DiscoveryService

java.lang.Object
com.tnsai.protocols.discovery.DiscoveryService

public final class DiscoveryService extends Object
Central discovery service for agents. Manages both internal (in-memory) and remote agent registrations.

Simplified to work directly with Agent instances. No intermediate AgentProfile - just use Agent directly.

Thread-safe singleton.

  • Method Details

    • getInstance

      public static DiscoveryService getInstance()
    • register

      public void register(com.tnsai.agents.Agent agent)
      Registers an agent (internal mode). If the agent is already registered with the same instance, this is a no-op.
      Parameters:
      agent - The agent to register
      Throws:
      IllegalStateException - if a DIFFERENT agent with the same ID is already registered
    • registerRemote

      public void registerRemote(com.tnsai.agents.Agent agent)
      Registers a remote agent. Used when agent is on different machine (received via HTTP/JSON).
      Parameters:
      agent - The agent instance (deserialized from JSON)
      Throws:
      IllegalStateException - if an agent with the same ID is already registered
    • unregister

      public boolean unregister(String agentId)
      Unregisters an agent.
      Parameters:
      agentId - Agent ID to unregister
      Returns:
      true if agent was removed
    • findAgent

      public com.tnsai.agents.Agent findAgent(String agentId)
      Finds agent by ID.
      Parameters:
      agentId - Agent ID
      Returns:
      Agent instance or null if not found
    • isInternal

      public boolean isInternal(String agentId)
      Checks if agent is registered and internal.
      Parameters:
      agentId - Agent ID
      Returns:
      true if agent is internal
    • isRemote

      public boolean isRemote(String agentId)
      Checks if agent is registered and remote.
      Parameters:
      agentId - Agent ID
      Returns:
      true if agent is remote
    • listAgentIds

      public List<String> listAgentIds()
      Lists all registered agent IDs.
      Returns:
      List of agent IDs
    • listAgents

      public List<com.tnsai.agents.Agent> listAgents()
      Lists all agents.
      Returns:
      List of agents
    • findByRole

      public List<com.tnsai.agents.Agent> findByRole(String roleName)
      Searches agents by role.
      Parameters:
      roleName - Role name to search for
      Returns:
      List of matching agents
    • findByParadigm

      public List<com.tnsai.agents.Agent> findByParadigm(String paradigm)
      Searches agents by communication paradigm.
      Parameters:
      paradigm - Paradigm name (DIRECT, BROADCAST, PUBSUB, REQUEST_REPLY)
      Returns:
      List of matching agents
    • findByTopic

      public List<com.tnsai.agents.Agent> findByTopic(String topic)
      Searches agents by topic (for Broadcast/PubSub).
      Parameters:
      topic - Topic name
      Returns:
      List of matching agents
    • findByDomain

      public List<com.tnsai.agents.Agent> findByDomain(String domain)
      Searches agents by domain.

      Domains are extracted from:

      • @RoleSpec.domains annotation on role classes
      • Role.getIdentity().getDomain() method
      Parameters:
      domain - Domain name to search for (case-insensitive)
      Returns:
      List of agents with roles matching the domain
      Since:
      0.0.4
    • getAgentCount

      public int getAgentCount()
      Gets total number of registered agents.
      Returns:
      Agent count
    • clear

      public void clear()
      Clears all registrations (for testing).