Package com.tnsai.protocols.discovery
Class DiscoveryService
java.lang.Object
com.tnsai.protocols.discovery.DiscoveryService
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRegistration mode enum. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all registrations (for testing).com.tnsai.agents.AgentFinds agent by ID.List<com.tnsai.agents.Agent> findByDomain(String domain) Searches agents by domain.List<com.tnsai.agents.Agent> findByParadigm(String paradigm) Searches agents by communication paradigm.List<com.tnsai.agents.Agent> findByRole(String roleName) Searches agents by role.List<com.tnsai.agents.Agent> findByTopic(String topic) Searches agents by topic (for Broadcast/PubSub).intGets total number of registered agents.static DiscoveryServicebooleanisInternal(String agentId) Checks if agent is registered and internal.booleanChecks if agent is registered and remote.Lists all registered agent IDs.List<com.tnsai.agents.Agent> Lists all agents.voidregister(com.tnsai.agents.Agent agent) Registers an agent (internal mode).voidregisterRemote(com.tnsai.agents.Agent agent) Registers a remote agent.booleanunregister(String agentId) Unregisters an agent.
-
Method Details
-
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
Unregisters an agent.- Parameters:
agentId- Agent ID to unregister- Returns:
- true if agent was removed
-
findAgent
Finds agent by ID.- Parameters:
agentId- Agent ID- Returns:
- Agent instance or null if not found
-
isInternal
Checks if agent is registered and internal.- Parameters:
agentId- Agent ID- Returns:
- true if agent is internal
-
isRemote
Checks if agent is registered and remote.- Parameters:
agentId- Agent ID- Returns:
- true if agent is remote
-
listAgentIds
Lists all registered agent IDs.- Returns:
- List of agent IDs
-
listAgents
Lists all agents.- Returns:
- List of agents
-
findByRole
Searches agents by role.- Parameters:
roleName- Role name to search for- Returns:
- List of matching agents
-
findByParadigm
Searches agents by communication paradigm.- Parameters:
paradigm- Paradigm name (DIRECT, BROADCAST, PUBSUB, REQUEST_REPLY)- Returns:
- List of matching agents
-
findByTopic
Searches agents by topic (for Broadcast/PubSub).- Parameters:
topic- Topic name- Returns:
- List of matching agents
-
findByDomain
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).
-