Class XTablesSocketMonitor

java.lang.Object
java.lang.Thread
org.kobe.xbot.JClient.XTablesSocketMonitor
All Implemented Interfaces:
Runnable

public class XTablesSocketMonitor extends Thread
XTablesSocketMonitor - A class for monitoring the state of ZeroMQ sockets.

This class provides functionality for monitoring multiple ZeroMQ sockets by using the ZeroMQ socket monitor API. It listens for various socket events such as connections, disconnections, and retries, and processes these events in real-time. The monitor provides feedback on socket status, including the connection state, and reports it through various events.

The class also includes methods for adding and removing sockets, as well as retrieving their status. It handles these socket events asynchronously, making it suitable for real-time monitoring in applications that rely on ZeroMQ for messaging.

Author: Kobe Lei Version: 1.0 Package: org.kobe.xbot.JClient

This is part of the XTABLES project and provides socket monitoring functionality within a ZeroMQ-based communication system.

  • Constructor Details

    • XTablesSocketMonitor

      public XTablesSocketMonitor(org.zeromq.ZContext context)
      Constructor for XTablesSocketMonitor. Initializes the monitor with the given ZeroMQ context and sets up the polling mechanism.

      Parameters:
      context - The ZeroMQ context used for creating and managing sockets.
  • Method Details

    • addSocket

      public XTablesSocketMonitor addSocket(String socketName, org.zeromq.ZMQ.Socket socket)
      Adds a socket to the monitor for monitoring its connection events.

      Registers the socket to monitor various connection events such as connection, delay, retry, disconnection, and monitor stop. Also sets up the socket for polling events.

      Parameters:
      socketName - The name of the socket for identification.
      socket - The ZeroMQ socket to monitor.
      Returns:
      The XTablesSocketMonitor instance for method chaining.
    • removeSocket

      public XTablesSocketMonitor removeSocket(String socketName)
      Removes a socket from the monitor based on its socket name.

      Unregisters the socket from monitoring and removes it from the internal maps.

      Parameters:
      socketName - The name of the socket to remove.
      Returns:
      The XTablesSocketMonitor instance for method chaining.
    • removeSocket

      public XTablesSocketMonitor removeSocket(org.zeromq.ZMQ.Socket socket)
      Removes a socket from the monitor based on the socket instance.

      Unregisters the socket from monitoring and removes it from the internal maps.

      Parameters:
      socket - The ZeroMQ socket to remove.
      Returns:
      The XTablesSocketMonitor instance for method chaining.
    • getStatus

      public XTablesSocketMonitor.SocketStatus getStatus(String socketName)
      Retrieves the current status of a monitored socket based on its name.

      Parameters:
      socketName - The name of the socket whose status is to be retrieved.
      Returns:
      The current status of the socket.
    • getSimplifiedMessage

      public String getSimplifiedMessage()
    • isConnected

      public boolean isConnected(String socketName)
    • run

      public void run()
      The main event loop for monitoring socket events.

      This method continuously polls for socket events and processes them accordingly, logging and updating statuses.

      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • interrupt

      public void interrupt()
      Interrupts the monitoring thread and performs cleanup.

      Sets the running flag to false, terminates the thread, and cleans up any resources.

      Overrides:
      interrupt in class Thread