Package com.tnsai.protocols.handlers
Interface ProtocolHandler
- All Known Implementing Classes:
AbstractProtocolHandler,BroadcastHandler,DebateProtocolHandler,DirectMessageHandler,PubSubHandler,RequestReplyHandler
public interface ProtocolHandler
Base interface for protocol handlers in the TnsAI multi-agent communication system.
Protocol handlers encapsulate the logic for different communication paradigms, providing a uniform interface while supporting paradigm-specific behavior.
Available Handlers
| Handler | Paradigm | Use Case |
|---|---|---|
DirectMessageHandler | Point-to-point | Agent-to-agent direct messaging |
BroadcastHandler | One-to-many | Announcements to all agents |
PubSubHandler | Topic-based | Subscribe/publish on topics |
RequestReplyHandler | Request-response | Synchronous RPC-style calls |
DebateProtocolHandler | Multi-agent debate | Consensus building, voting |
Lifecycle
ProtocolHandler handler = new DirectMessageHandler(transport);
handler.start(); // Initialize and start listening
// Synchronous send
Message reply = handler.send(message);
// Asynchronous send
handler.sendAsync(message, new HandlerCallback() {
public void onSuccess(Message response) { ... }
public void onFailure(Exception error) { ... }
});
handler.stop(); // Cleanup and shutdown
Thread Safety
All handler implementations must be thread-safe. Multiple threads may
call send(com.tnsai.protocols.models.Message) and sendAsync(com.tnsai.protocols.models.Message, com.tnsai.protocols.handlers.ProtocolHandler.HandlerCallback) concurrently.
Transport Layer
Handlers delegate actual message delivery to a Transport instance.
The transport provides the underlying communication mechanism:
- InternalTransport: In-memory (same JVM)
- HttpTransport: HTTP/REST (distributed)
- WebSocketTransport: Real-time bidirectional
- Since:
- 0.0.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCallback interface for async sends.static classHandler exception. -
Method Summary
Modifier and TypeMethodDescriptionGets the transport used by this handler.booleanChecks if handler is running.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.voidstart()Starts the protocol handler.voidstop()Stops the protocol handler.
-
Method Details
-
send
com.tnsai.protocols.models.Message send(com.tnsai.protocols.models.Message message) throws ProtocolHandler.HandlerException Sends a message using this protocol.- Parameters:
message- Message to send- Returns:
- Response message (null for async protocols)
- Throws:
ProtocolHandler.HandlerException- if send fails
-
sendAsync
void sendAsync(com.tnsai.protocols.models.Message message, ProtocolHandler.HandlerCallback callback) Sends a message asynchronously.- Parameters:
message- Message to sendcallback- Callback for response
-
start
Starts the protocol handler.- Throws:
ProtocolHandler.HandlerException
-
stop
void stop()Stops the protocol handler. -
isRunning
boolean isRunning()Checks if handler is running.- Returns:
- true if running
-
getTransport
Transport getTransport()Gets the transport used by this handler.- Returns:
- Transport instance
-