Class JdbcAgentPresence
- All Implemented Interfaces:
AgentPresence
AgentPresence (ADR-028 Phase A).
Reuses the agenor_agents table the rest of the JDBC directory already writes:
heartbeat(java.lang.String) touches only last_seen, which is lighter than
JdbcAgentRegistry's status update, and getStatus(java.lang.String) reads status
alongside last_seen. No new table, column or migration.
Staleness is evaluated at read time. A relational store has no key
expiry, so getStatus(java.lang.String) compares now - last_seen against the configured
window and answers AgentStatus.UNKNOWN when it is exceeded. Detection latency is
therefore coarse — tens of seconds to a couple of minutes at the recommended cadence —
and the answer is only as trustworthy as the clock skew between the writing and reading
nodes allows. The default window is deliberately wide enough to absorb ordinary NTP drift.
Something has to send the heartbeats. Nothing in the framework calls
heartbeat(java.lang.String) unless a heartbeat interval is configured, and with a bounded window a
store nobody heartbeats reports UNKNOWN for every agent one window after start-up.
Either enable the runtime's heartbeat driver, or construct this class with
UNBOUNDED_STALENESS_WINDOW, which never expires a status and matches the
in-memory backend's behaviour.
- Since:
- 0.26.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefault staleness window: three missed beats at the recommended 30-second cadence.static final DurationStaleness window meaning "never expire a status", the unbounded valueAgentPresence.getStatus(java.lang.String)permits. -
Constructor Summary
ConstructorsConstructorDescriptionJdbcAgentPresence(JdbcHelper helper) Creates a presence backend with the default staleness window and noop telemetry.JdbcAgentPresence(JdbcHelper helper, AgenorTelemetry telemetry, Duration stalenessWindow) Creates a presence backend. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current status of the given agent.Records a heartbeat for the given agent, refreshing itslastSeentimestamp.Returns the window after whichgetStatus(java.lang.String)reportsAgentStatus.UNKNOWN.
-
Field Details
-
DEFAULT_STALENESS_WINDOW
Default staleness window: three missed beats at the recommended 30-second cadence. -
UNBOUNDED_STALENESS_WINDOW
Staleness window meaning "never expire a status", the unbounded valueAgentPresence.getStatus(java.lang.String)permits. Use it when no heartbeat driver is running, sogetStatus(java.lang.String)simply reports what the registry last wrote.
-
-
Constructor Details
-
JdbcAgentPresence
Creates a presence backend with the default staleness window and noop telemetry.- Parameters:
helper- JDBC helper; must not be null
-
JdbcAgentPresence
Creates a presence backend.- Parameters:
helper- JDBC helper; must not be nulltelemetry- telemetry fordirectory.*spans; null treated as noopstalenessWindow- how long an agent may go unseen beforegetStatus(java.lang.String)answersAgentStatus.UNKNOWN; must not be null or negative. PassUNBOUNDED_STALENESS_WINDOWto disable expiry- Throws:
NullPointerException- if helper or stalenessWindow is nullIllegalArgumentException- if stalenessWindow is negative
-
-
Method Details
-
stalenessWindow
Returns the window after whichgetStatus(java.lang.String)reportsAgentStatus.UNKNOWN.- Returns:
- the staleness window; never null
-
heartbeat
Records a heartbeat for the given agent, refreshing itslastSeentimestamp.A heartbeat signals liveness and nothing else: it does not change the agent's
AgentStatus. UseAgentRegistry.updateStatus(java.lang.String, dev.agenor.core.AgentStatus)for that. An implementation backed by key expiry has no status to promote, so a heartbeat that also wrote a status could not mean the same thing across backends.A heartbeat for an agent the implementation does not know is ignored rather than rejected — it is a race with unregistration, not an error.
Issues a single-row
UPDATEagainst the primary key. A heartbeat for an agent that is not registered updates no rows and is ignored, per the contract.- Specified by:
heartbeatin interfaceAgentPresence- Parameters:
agentId- the unique agent identifier, must not be null- Returns:
- a future that completes when the heartbeat is recorded
-
getStatus
Returns 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.Answers
AgentStatus.UNKNOWNwhen no row exists, and also when the row'slast_seenis older than this instance's staleness window.- 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
-