Class TcpServer

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Runnable

    public class TcpServer
    extends Server
    implements Runnable
    Provides a TCP server that accepts incoming socket connections and creates TcpClient instances for connected clients.

    Each accepted connection is represented by a server-side TcpClient, allowing the connection to use the standard KDC TCP client communication facilities. Connected clients are maintained in the server's Hub.

    Author:
    Charles B. Kozoyed
    See Also:
    Server, TcpClient, TcpServerParameters
    • Constructor Detail

      • TcpServer

        public TcpServer​(TcpServerParameters tcpServerParameters)
                  throws com.kristensoft.kdc.license.runtime.LicenseException,
                         KristenCommsException
        Creates a TCP server using the specified configuration parameters.

        If automatic startup is enabled in the parameters, the server is started during construction.

        Parameters:
        tcpServerParameters - the TCP server configuration parameters
        Throws:
        com.kristensoft.kdc.license.runtime.LicenseException - if the server cannot be created because of a licensing error
        KristenCommsException - if an error occurs while configuring KDC communication
        See Also:
        TcpServerParameters
    • Method Detail

      • getTcpServerParameters

        public TcpServerParameters getTcpServerParameters()
        Returns the configuration parameters for this TCP server.
        Returns:
        the TCP server configuration parameters
      • run

        public void run()
        Runs the TCP server and accepts incoming client connections.

        This method starts the connection queue, creates the server socket, and listens for incoming connections while the server is running. Each accepted socket is added to the connection queue for creation and initialization of a server-side TcpClient.

        The connection queue is stopped when the server terminates.

        Specified by:
        run in interface Runnable
        Specified by:
        run in class Server
      • handleConnection

        public void handleConnection​(Socket socket)
        Creates and starts a server-side TcpClient for an accepted socket.

        The client is configured using this server's communication settings and registered with the server's Hub. This allows the accepted connection to use the standard KDC TCP client communication facilities.

        Parameters:
        socket - the socket for the accepted client connection
      • close

        public void close()
        Closes the TCP server socket.

        The server is marked as no longer running and registered event handlers are notified when the server socket is successfully closed.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in class Server
      • haltAllClients

        public void haltAllClients()
        Halts all clients connected to this TCP server.
      • halt

        public void halt()
        Halts all clients connected to this TCP server and then stops the server.

        If the server is already being halted, this method has no effect.

        Overrides:
        halt in class Server
      • stop

        public void stop()
        Stops this TCP server and closes its server socket.

        The server is marked as no longer running, its thread is interrupted, and the server socket is closed. This releases the server thread if it is waiting for a connection or for space in the connection queue.

        The method waits for the server thread to terminate.

        Overrides:
        stop in class Server
      • isRunning

        public boolean isRunning()
        Determines whether this communication entity is currently running.
        Returns:
        true if this communication entity is running; false otherwise
      • flushMetrics

        public void flushMetrics()
        Flushes the accumulated latency metrics for this communication entity.

        This method may be used to report any currently accumulated metrics without waiting for the configured latency reporting interval.

      • getAgentSerializer

        public AgentSerializer getAgentSerializer()
        Returns the agent serializer used by this communication entity.

        The serializer may be used to inspect or modify serialization settings at runtime, including compression and encryption settings.

        Returns:
        the agent serializer used by this communication entity