Package org.kobe.xbot.JServer
Class ClientRegistry
java.lang.Object
java.lang.Thread
org.kobe.xbot.JServer.ClientRegistry
- All Implemented Interfaces:
Runnable
ClientRegistry - A service for managing connected clients in the XTables server.
This class monitors and manages the list of connected clients. It periodically updates the server with a new session ID and sends client updates to the server instance. The registry is also responsible for tracking session ID changes and notifying relevant components of any updates.
Author: Kobe Lei Version: 1.0 Package: XTABLES
This class runs as a background thread, performing regular updates and managing client connections for the XTABLES project.
-
Nested Class Summary
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
ConstructorsConstructorDescriptionClientRegistry
(XTablesServer instance) Constructor to initialize the ClientRegistry with the XTablesServer instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Forces the execution of the periodic task immediately, bypassing the scheduled loop.Returns the list of connected clients.long
Returns the number of milliseconds before the next loop will execute.com.google.protobuf.ByteString
Returns the current session ID.protected void
handleException
(Exception exception) Logs exceptions that occur during thread execution.void
run()
The run method handles the periodic task of updating the client registry and session ID.boolean
shouldStopClientRegistry
(int thresholdPercentage) Method to check if the client registry should stop based on current messages per second compared to the max iteration speed threshold percentage.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, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
ClientRegistry
Constructor to initialize the ClientRegistry with the XTablesServer instance.- Parameters:
instance
- the XTablesServer instance used to notify client updates
-
-
Method Details
-
run
public void run()The run method handles the periodic task of updating the client registry and session ID. It runs in a loop, checking every second to clear the client list and generate a new session ID. Once the session ID is updated, it notifies the server of the update. The loop runs until the thread is interrupted, and it sleeps for 100 milliseconds between iterations to reduce CPU usage. -
shouldStopClientRegistry
public boolean shouldStopClientRegistry(int thresholdPercentage) Method to check if the client registry should stop based on current messages per second compared to the max iteration speed threshold percentage. This method checks the pull, reply, and publish messages separately, with the reply being twice as sensitive.- Parameters:
thresholdPercentage
- the threshold percentage (0 to 100) to compare against- Returns:
- true if any message type exceeds the threshold, otherwise false
-
executeNow
public void executeNow()Forces the execution of the periodic task immediately, bypassing the scheduled loop. This method can be useful for manually triggering a client update outside the normal loop cycle. -
getMillisBeforeNextLoop
public long getMillisBeforeNextLoop()Returns the number of milliseconds before the next loop will execute.- Returns:
- milliseconds before the next loop
-
getSessionId
public com.google.protobuf.ByteString getSessionId()Returns the current session ID.- Returns:
- the session ID
-
getClients
Returns the list of connected clients.- Returns:
- the list of connected clients
-
handleException
Logs exceptions that occur during thread execution.- Parameters:
exception
- the exception to log
-