Package com.ultikits.ultitools.utils
Class AgentMessageRouter
java.lang.Object
com.ultikits.ultitools.utils.AgentMessageRouter
Validates envelopes and dispatches framework handlers; internal, not for module use.
Handlers validate their own payloads. Synchronous validation and runtime failures
become correlated errors; diagnostics never include raw payload or exception text.
The capability predicate receives contract capability names such as commands
and files:read, plus the literal fromPayload:module for module.request.
Integration must return true for that sentinel so the module handler can validate
the payload's module identifier and answer module_not_found when no responder is
owned by that module. The module handler does not check the negotiated
modules:<id>@<version> capabilities; whether a request for a module the
gateway did not accept is filtered is decided in 22-21. The sentinel is never
declared in hello or welcome. Likewise, accept power here; its handler applies the
operator switch and answers power_disabled itself.
- Since:
- 6.3.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceHears every request the capability gate refused because the operator's switch (or the handshake) does not allow it, after its correlatedcapability_not_acceptedreply was handed to the channel (22-23 fix): the place the remote action log records that refusal as one DENIED entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LongSupplierprivate final Map<String, CloudRequestHandler> private static final Loggerprivate ShutdownGate -
Constructor Summary
ConstructorsConstructorDescriptionAgentMessageRouter(Predicate<String> capabilityEnabled, Function<String, String> refusalForCapability) Creates a router using the system clock for warning throttling.AgentMessageRouter(Predicate<String> capabilityEnabled, Function<String, String> refusalForCapability, LongSupplier clock) Creates a router with an injectable clock. -
Method Summary
Modifier and TypeMethodDescriptionprivate voiddispatch(Envelope envelope, CloudChannel channel) voiddispatch(String text, CloudChannel channel) Parses and dispatches one frame, applying the capability gate before the handler.private voiddispatchAdmitted(Envelope envelope, CloudChannel channel) private voiderror(CloudChannel channel, String id, String code, String message, com.google.gson.JsonObject details) private voiderror(CloudChannel channel, String id, String code, String message, com.google.gson.JsonObject details, String diagnostic) (package private) voidonShutdown(ShutdownGate gate) Sets the shutdown gate (ShutdownGate): from the moment it refuses, every state-changing type it covers is answered with its shutting-down failure before the switch gate or a handler sees it; a request it lets in keeps the gate's permit for the whole switch check and handler call.(package private) voidSets the listener told of each refusal by the capability gate;nullremoves it.private voidrefuse(CloudChannel channel, String id, String capability, String message) voidregister(String type, CloudRequestHandler handler) Registers or replaces the handler for one frozen-contract message type.private void
-
Field Details
-
LOGGER
-
handlers
-
lastWarnings
-
capabilityEnabled
-
refusalForCapability
-
clock
-
switchRefusals
-
shutdown
-
-
Constructor Details
-
AgentMessageRouter
public AgentMessageRouter(Predicate<String> capabilityEnabled, Function<String, String> refusalForCapability) Creates a router using the system clock for warning throttling.- Parameters:
capabilityEnabled- the per-request capability gaterefusalForCapability- supplies safe refusal text naming the configuration key
-
AgentMessageRouter
public AgentMessageRouter(Predicate<String> capabilityEnabled, Function<String, String> refusalForCapability, LongSupplier clock) Creates a router with an injectable clock. Warnings are limited to one per error code per minute; rejected requests still receive their own error reply.- Parameters:
capabilityEnabled- the per-request capability gaterefusalForCapability- supplies safe refusal text, never payload or exception textclock- supplies epoch milliseconds for warning throttling
-
-
Method Details
-
onSwitchRefusal
Sets the listener told of each refusal by the capability gate;nullremoves it. A listener that throws never costs the request its reply, which was sent before the listener runs.- Parameters:
listener- the listener, ornull
-
onShutdown
Sets the shutdown gate (ShutdownGate): from the moment it refuses, every state-changing type it covers is answered with its shutting-down failure before the switch gate or a handler sees it; a request it lets in keeps the gate's permit for the whole switch check and handler call.nullremoves it.- Parameters:
gate- the gate, ornull
-
register
Registers or replaces the handler for one frozen-contract message type.- Parameters:
type- the exact registered protocol typehandler- the non-null handler, invoked on the dispatching thread- Throws:
IllegalArgumentException- if the type is not in the contract
-
dispatch
Parses and dispatches one frame, applying the capability gate before the handler. Invalid frames without a usable id are discarded at FINE; otherwise failures receive a correlated protocol error. Unhandled error, ack and welcome are ignored.- Parameters:
text- the incoming JSON text, never included in diagnosticschannel- supplies current limits and receives replies
-
dispatch
-
dispatchAdmitted
-
refuse
-
error
private void error(CloudChannel channel, String id, String code, String message, com.google.gson.JsonObject details) -
error
private void error(CloudChannel channel, String id, String code, String message, com.google.gson.JsonObject details, String diagnostic) -
warn
-