Class InMemoryAgentDirectory
- All Implemented Interfaces:
AgentDirectory,AgentDiscovery,AgentPresence,AgentRegistry,AgentResolver
AgentDirectory.
All registered agents are assigned a AgentEndpoint with
transportType="local" and a runtime-generated nodeId. This
allows the InMemoryMessageDispatcher to
short-circuit point-to-point messages without a transport hop.
This implementation replaces the LocalAgentDirectory class removed at 0.22.0.
- Since:
- 0.20.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates anInMemoryAgentDirectorywith a randomly generated node ID and noop telemetry.InMemoryAgentDirectory(String nodeId) Creates anInMemoryAgentDirectorywith the given node ID and noop telemetry.InMemoryAgentDirectory(String nodeId, AgenorTelemetry telemetry) Creates anInMemoryAgentDirectorywith the given node ID and telemetry. -
Method Summary
Modifier and TypeMethodDescriptionfindAgents(AgentQuery query, PageRequest request) Finds agents matching the given query, returning a bounded page of results.findByCapability(String capability) Finds all agents that declare the given capability.Finds an agent by its unique identifier.findByType(String agentType) Finds all agents of the given type.Returns the current status of the given agent.Refreshes the agent'slastSeentimestamp, leaving its status alone.nodeId()Returns the node ID assigned to this JVM instance.register(AgentDescriptor descriptor) Registers an agent in the directory, making it discoverable.resolveEndpoint(String agentId) Resolves the transport endpoint for the given agent ID.voidsetTelemetry(AgenorTelemetry telemetry) Updates the telemetry instance after construction.unregister(String agentId) Removes an agent from the directory.updateStatus(String agentId, AgentStatus status) Updates the status of a registered agent.
-
Constructor Details
-
InMemoryAgentDirectory
public InMemoryAgentDirectory()Creates anInMemoryAgentDirectorywith a randomly generated node ID and noop telemetry. -
InMemoryAgentDirectory
Creates anInMemoryAgentDirectorywith the given node ID and noop telemetry.- Parameters:
nodeId- the node identifier for this JVM; must not be null
-
InMemoryAgentDirectory
Creates anInMemoryAgentDirectorywith the given node ID and telemetry.- Parameters:
nodeId- the node identifier for this JVM; must not be nulltelemetry- telemetry instance fordirectory.resolvespans; null treated as noop
-
-
Method Details
-
setTelemetry
Updates the telemetry instance after construction.- Parameters:
telemetry- the telemetry instance; null treated as noop
-
nodeId
Returns the node ID assigned to this JVM instance. -
register
Description copied from interface:AgentRegistryRegisters an agent in the directory, making it discoverable.If an agent with the same ID is already registered, the implementation should update the existing entry.
- Specified by:
registerin interfaceAgentRegistry- Parameters:
descriptor- the agent descriptor, must not be null- Returns:
- a future that completes when registration succeeds
-
unregister
Description copied from interface:AgentRegistryRemoves an agent from the directory.If the agent is not registered the call is a no-op.
- Specified by:
unregisterin interfaceAgentRegistry- Parameters:
agentId- the unique agent identifier, must not be null- Returns:
- a future that completes when unregistration succeeds
-
updateStatus
Description copied from interface:AgentRegistryUpdates the status of a registered agent.Implementations should also update the agent's
lastSeentimestamp. If the agent is not registered the behaviour is implementation-defined (log-and-ignore is recommended for leniency).- Specified by:
updateStatusin interfaceAgentRegistry- Parameters:
agentId- the unique agent identifier, must not be nullstatus- the new status, must not be null- Returns:
- a future that completes when the update succeeds
-
resolveEndpoint
Description copied from interface:AgentResolverResolves the transport endpoint for the given agent ID.- Specified by:
resolveEndpointin interfaceAgentResolver- Parameters:
agentId- the unique agent identifier, must not be null- Returns:
- a future containing the endpoint if the agent is registered and reachable, or empty if the agent is unknown
-
findById
Description copied from interface:AgentDiscoveryFinds an agent by its unique identifier.- Specified by:
findByIdin interfaceAgentDiscovery- Parameters:
agentId- the unique identifier, must not be null- Returns:
- a future containing the descriptor if found, or empty if not registered
-
findByCapability
Description copied from interface:AgentDiscoveryFinds all agents that declare the given capability.- Specified by:
findByCapabilityin interfaceAgentDiscovery- Parameters:
capability- the capability tag, must not be null- Returns:
- a future containing a (possibly empty) list of matching descriptors
-
findByType
Description copied from interface:AgentDiscoveryFinds all agents of the given type.- Specified by:
findByTypein interfaceAgentDiscovery- Parameters:
agentType- the agent type string, must not be null- Returns:
- a future containing a (possibly empty) list of matching descriptors
-
findAgents
Description copied from interface:AgentDiscoveryFinds agents matching the given query, returning a bounded page of results.Use
AgentQuery.all()to retrieve all agents with pagination.- Specified by:
findAgentsin interfaceAgentDiscovery- Parameters:
query- the search criteria, must not be nullrequest- pagination parameters, must not be null- Returns:
- a future containing the page of matching descriptors
-
heartbeat
Refreshes the agent'slastSeentimestamp, leaving its status alone.A heartbeat is a liveness signal and nothing more (ADR-028 D-1). It used to be
updateStatus(agentId, RUNNING), which meant an agent stuck inSTARTINGwas promoted by the mere fact of being alive. A backend with key expiry cannot implement that, so the three implementations would have disagreed.Unknown agent ids are ignored rather than rejected: a heartbeat for an agent that has just unregistered is a race, not an error.
- Specified by:
heartbeatin interfaceAgentPresence- Parameters:
agentId- the agent to touch, must not be null- Returns:
- a future completing when the timestamp is refreshed
- Throws:
NullPointerException- if agentId is null
-
getStatus
Description copied from interface:AgentPresenceReturns the current status of the given agent.The answer is
AgentStatus.UNKNOWNwhen the agent is not registered, and also when it has not been seen within the implementation's staleness window. That window is a property of the implementation, not of this contract: an unbounded window is a legal value, and means the backend never expires a status.- Specified by:
getStatusin interfaceAgentPresence- Parameters:
agentId- the unique agent identifier, must not be null- Returns:
- a future containing the agent's status, or
AgentStatus.UNKNOWNif it is unregistered or stale
-