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

HandlerParadigmUse Case
DirectMessageHandlerPoint-to-pointAgent-to-agent direct messaging
BroadcastHandlerOne-to-manyAnnouncements to all agents
PubSubHandlerTopic-basedSubscribe/publish on topics
RequestReplyHandlerRequest-responseSynchronous RPC-style calls
DebateProtocolHandlerMulti-agent debateConsensus 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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Callback interface for async sends.
    static class 
    Handler exception.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the transport used by this handler.
    boolean
    Checks if handler is running.
    com.tnsai.protocols.models.Message
    send(com.tnsai.protocols.models.Message message)
    Sends a message using this protocol.
    void
    sendAsync(com.tnsai.protocols.models.Message message, ProtocolHandler.HandlerCallback callback)
    Sends a message asynchronously.
    void
    Starts the protocol handler.
    void
    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 send
      callback - 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