Class XTablesServer
This class initializes and manages the server components, including JeroMQ sockets for handling PUB, PULL, and REQ/REP messaging patterns. It also supports mDNS registration for service discovery.
Author: Kobe Lei Version: 1.0 Package: XTABLES
This is part of the XTABLES project and provides core server functionality in a multithreaded environment.
-
Field Summary
FieldsModifier and TypeFieldDescriptionorg.zeromq.ZContext
final AtomicInteger
final AtomicInteger
final AtomicInteger
static final XTablesData
-
Method Summary
Modifier and TypeMethodDescriptionReturns the ClientRegistry instance associated with the XTables server.AtomicReference<com.google.protobuf.ByteString>
com.google.protobuf.ByteString
static XTablesServer
Retrieves the current instance of the XTablesServer.int
Retrieves the iteration speed.getRate()
Retrieves the current status of the server.getTable()
Returns the current data table associated with this instance.Retrieves the version of the server.static XTablesServer
initialize
(String version, int pullSocketPort, int replySocketPort, int publishSocketPort, boolean additionalFeatures) Initializes the XTablesServer instance and starts the main server thread.boolean
isDebug()
Checks if debug mode is enabled.void
restart()
Restarts the server by performing a clean shutdown followed by a restart.void
setDebug
(boolean value) Sets the debug mode state.void
shutdown()
Shuts down the server and releases all associated resources, including JeroMQ context, mDNS service, and handler threads.
-
Field Details
-
table
-
pullMessages
-
replyMessages
-
publishMessages
-
context
public org.zeromq.ZContext context -
publishQueue
-
-
Method Details
-
initialize
public static XTablesServer initialize(String version, int pullSocketPort, int replySocketPort, int publishSocketPort, boolean additionalFeatures) Initializes the XTablesServer instance and starts the main server thread. Ensures the server is properly cleaned up during JVM shutdown.- Parameters:
pullSocketPort
- Port for the PULL socketreplySocketPort
- Port for the REP socketpublishSocketPort
- Port for the PUB socket- Returns:
- The initialized server instance
-
getInstance
Retrieves the current instance of the XTablesServer.- Returns:
- The current server instance, or null if not initialized
-
restart
public void restart()Restarts the server by performing a clean shutdown followed by a restart. Updates the server status appropriately and ensures proper resource management. -
shutdown
public void shutdown()Shuts down the server and releases all associated resources, including JeroMQ context, mDNS service, and handler threads. -
getRate
-
getTable
Returns the current data table associated with this instance.- Returns:
- an instance of
XTablesData
representing the current table data.
-
getClientRegistry
Returns the ClientRegistry instance associated with the XTables server.This method provides access to the ClientRegistry, which manages the list of connected clients and periodically updates the server with new session IDs and client information. The ClientRegistry operates as a background thread that handles client management tasks.
- Returns:
- the ClientRegistry instance managing client connections and session updates
-
getClientRegistrySessionId
public com.google.protobuf.ByteString getClientRegistrySessionId() -
getClientRegistrySession
-
getIterationSpeed
public int getIterationSpeed()Retrieves the iteration speed.This method returns the number of iterations per second that the server can process, representing its current processing capability.
- Returns:
- the iteration speed as an integer
-
getVersion
Retrieves the version of the server.This method provides the version string for the current instance, which can be useful for diagnostics or display purposes.
- Returns:
- the version as a string
-
getStatus
Retrieves the current status of the server.This method accesses the current status stored in an atomic reference, providing a thread-safe way to get the server's state.
- Returns:
- the current status as an
XTableStatus
object
-
isDebug
public boolean isDebug()Checks if debug mode is enabled.- Returns:
- boolean - true if debug mode is enabled, false otherwise. This method retrieves the current value of the debug mode flag.
-
setDebug
public void setDebug(boolean value) Sets the debug mode state.- Parameters:
value
- boolean - the value to set for debug mode. This method sets the debug mode flag to the provided value. When enabled, the system starts publishing logs to the clients for debugging purposes.
-