Class XTablesSocketMonitor
- All Implemented Interfaces:
Runnable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum representing the status of a socket during monitoring.Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionXTablesSocketMonitor
(org.zeromq.ZContext context) Constructor for XTablesSocketMonitor. -
Method Summary
Modifier and TypeMethodDescriptionAdds a socket to the monitor for monitoring its connection events.Retrieves the current status of a monitored socket based on its name.void
Interrupts the monitoring thread and performs cleanup.boolean
isConnected
(String socketName) removeSocket
(String socketName) Removes a socket from the monitor based on its socket name.removeSocket
(org.zeromq.ZMQ.Socket socket) Removes a socket from the monitor based on the socket instance.void
run()
The main event loop for monitoring socket events.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
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
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
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
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
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
-
isConnected
-
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.
-
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.
-