Package com.tnsai.protocols.handlers
Class PubSubHandler
java.lang.Object
com.tnsai.protocols.handlers.AbstractProtocolHandler
com.tnsai.protocols.handlers.PubSubHandler
- All Implemented Interfaces:
ProtocolHandler
Handler for publish-subscribe messaging.
Similar to Broadcast but supports multiple topics and filtering.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a publish operation.Nested classes/interfaces inherited from interface com.tnsai.protocols.handlers.ProtocolHandler
ProtocolHandler.HandlerCallback, ProtocolHandler.HandlerException -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the result of the last publish operation.intgetSubscriberCount(String topic) Gets subscriber count for a topic.Gets topics managed by this handler.com.tnsai.protocols.models.Messagesend(com.tnsai.protocols.models.Message message) Sends a message using this protocol.voidsendAsync(com.tnsai.protocols.models.Message message, ProtocolHandler.HandlerCallback callback) Sends a message asynchronously.voidSubscribes an agent to a topic.voidunsubscribe(String topic, String agentId) Unsubscribes an agent from a topic.Methods inherited from class com.tnsai.protocols.handlers.AbstractProtocolHandler
getTransport, isRunning, start, stop
-
Constructor Details
-
PubSubHandler
-
-
Method Details
-
subscribe
Subscribes an agent to a topic. Uses atomic addIfAbsent to prevent TOCTOU race condition.- Parameters:
topic- Topic nameagentId- Agent ID
-
unsubscribe
Unsubscribes an agent from a topic.- Parameters:
topic- Topic nameagentId- Agent ID
-
send
public com.tnsai.protocols.models.Message send(com.tnsai.protocols.models.Message message) throws ProtocolHandler.HandlerException Description copied from interface:ProtocolHandlerSends a message using this protocol.- Parameters:
message- Message to send- Returns:
- Response message (null for async protocols)
- Throws:
ProtocolHandler.HandlerException- if send fails
-
getLastPublishResult
Gets the result of the last publish operation. Useful for checking delivery statistics after publishing.- Returns:
- the last publish result, or null if no publish has occurred
-
sendAsync
public void sendAsync(com.tnsai.protocols.models.Message message, ProtocolHandler.HandlerCallback callback) Description copied from interface:ProtocolHandlerSends a message asynchronously.- Parameters:
message- Message to sendcallback- Callback for response
-
getTopics
Gets topics managed by this handler.- Returns:
- List of topics
-
getSubscriberCount
Gets subscriber count for a topic.- Parameters:
topic- Topic name- Returns:
- Number of subscribers
-