Package com.tnsai.protocols.callbacks
Class MessageCallbackDispatcher
java.lang.Object
com.tnsai.protocols.callbacks.MessageCallbackDispatcher
Dispatches incoming messages to annotated callback methods in Roles.
Scans Role classes for @OnMessageReceived annotations and invokes matching methods when messages arrive.
Supported message types:
- DIRECT - Point-to-point messages
- BROADCAST - One-to-many messages
- PUBSUB - Topic-based messages
- REQUEST/REPLY - Request-response pattern
- Author:
- TnsAI Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when a callback invocation fails in FAIL_FAST mode.static enumStrategy for handling callback failures. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchBroadcast(AgentMessage message, String topic) Dispatches a broadcast message to registered callbacks.voiddispatchMessage(AgentMessage message) Dispatches a direct message to registered callbacks.voiddispatchProtocolMessage(Message message) Dispatches a protocol message to registered callbacks.voiddispatchPubSub(AgentMessage message, String topic) Dispatches a PubSub message to registered callbacks.voiddispatchReply(AgentMessage message) Dispatches a reply message to registered callbacks.voiddispatchRequest(AgentMessage message) Dispatches a request message to registered callbacks.intGets the total count of failed callback invocations.Gets the current failure strategy.booleanReturns true if any callbacks are registered.voidregisterRole(Role role) Registers callbacks from a Role instance.voidResets the failed callback counter.voidSets the failure strategy for callback invocation.
-
Constructor Details
-
MessageCallbackDispatcher
public MessageCallbackDispatcher()
-
-
Method Details
-
registerRole
Registers callbacks from a Role instance.A callback is invoked directly on each matching message, so the access gate,
@Securitychecks and approval never run for it. A role is therefore refused, with none of its callbacks registered, when a callback declares an execution policy on the method, through a composed annotation, through an overridden declaration or on the role class, or@Securityin any of those places but a composed annotation: a composed@Securityis not detected yet.- Parameters:
role- The role to scan for callbacks- Throws:
SecurityException- withUNAUTHORIZEDwhen a callback declares access restrictions
-
dispatchMessage
Dispatches a direct message to registered callbacks.- Parameters:
message- The received message
-
dispatchBroadcast
Dispatches a broadcast message to registered callbacks.- Parameters:
message- The received broadcast messagetopic- The broadcast topic
-
dispatchPubSub
Dispatches a PubSub message to registered callbacks.- Parameters:
message- The received PubSub messagetopic- The PubSub topic
-
dispatchRequest
Dispatches a request message to registered callbacks.- Parameters:
message- The received request message
-
dispatchReply
Dispatches a reply message to registered callbacks.- Parameters:
message- The received reply message
-
dispatchProtocolMessage
Dispatches a protocol message to registered callbacks.- Parameters:
message- The received protocol message
-
setFailureStrategy
Sets the failure strategy for callback invocation.- Parameters:
strategy- the failure handling strategy
-
getFailureStrategy
Gets the current failure strategy.- Returns:
- the current failure strategy
-
getFailedCallbackCount
public int getFailedCallbackCount()Gets the total count of failed callback invocations.- Returns:
- the number of failed callbacks
-
resetFailedCallbackCount
public void resetFailedCallbackCount()Resets the failed callback counter. -
hasCallbacks
public boolean hasCallbacks()Returns true if any callbacks are registered.
-