Class ClientRegistry

java.lang.Object
java.lang.Thread
org.kobe.xbot.JServer.ClientRegistry
All Implemented Interfaces:
Runnable

public class ClientRegistry extends Thread
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.

  • Constructor Details

    • ClientRegistry

      public ClientRegistry(XTablesServer instance)
      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.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • 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

      protected void handleException(Exception exception)
      Logs exceptions that occur during thread execution.
      Parameters:
      exception - the exception to log