Class SubscribeHandler
- All Implemented Interfaces:
Runnable
This class handles the reception of messages on a ZeroMQ socket, processes them, and stores the updates in a circular buffer. It also manages a separate consumer thread that handles the subscription consumers and invokes their functions for each new update. The handler supports both UPDATE and PUBLISH message categories.
Author: Kobe Lei Version: 1.0 Package: org.kobe.xbot.JClient
This is part of the XTABLES project and facilitates subscribing and handling incoming messages from the server.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class org.kobe.xbot.JClient.BaseHandler
logger, socket
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionSubscribeHandler
(org.zeromq.ZMQ.Socket socket, XTablesClient instance) Constructor that initializes the handler with the provided socket and server instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Logs exceptions and handles cleanup when the thread is interrupted.boolean
requestSubscribe
(byte[] topic) Requests a new subscription to a topic.boolean
requestUnsubscription
(byte[] topic) Requests unsubscription from a topic.void
run()
The main method for handling incoming messages.Methods inherited from class org.kobe.xbot.JClient.BaseHandler
cleanUp, handleException
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
-
SubscribeHandler
Constructor that initializes the handler with the provided socket and server instance.- Parameters:
socket
- The ZeroMQ socket to receive messages oninstance
- The XTablesClient instance
-
-
Method Details
-
requestSubscribe
public boolean requestSubscribe(byte[] topic) Requests a new subscription to a topic.- Parameters:
topic
- The topic to subscribe to.
-
requestUnsubscription
public boolean requestUnsubscription(byte[] topic) Requests unsubscription from a topic.- Parameters:
topic
- The topic to unsubscribe from.
-
run
public void run()The main method for handling incoming messages.It continuously receives messages from the JeroMQ socket, processes them by parsing the message into a protocol buffer, and stores the updates in the buffer. It also increments the count of subscription messages received.
-
interrupt
public void interrupt()Logs exceptions and handles cleanup when the thread is interrupted.This method interrupts the consumer handling thread and calls the parent class's interrupt method to clean up.
- Overrides:
interrupt
in classBaseHandler
-