Class TcpServer
- java.lang.Object
-
- com.kristensoft.kdc.Server
-
- com.kristensoft.kdc.TcpServer
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
public class TcpServer extends Server implements Runnable
Provides a TCP server that accepts incoming socket connections and createsTcpClientinstances 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'sHub.- Author:
- Charles B. Kozoyed
- See Also:
Server,TcpClient,TcpServerParameters
-
-
Constructor Summary
Constructors Constructor Description TcpServer(TcpServerParameters tcpServerParameters)Creates a TCP server using the specified configuration parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the TCP server socket.voidflushMetrics()Flushes the accumulated latency metrics for this communication entity.AgentSerializergetAgentSerializer()Returns the agent serializer used by this communication entity.TcpServerParametersgetTcpServerParameters()Returns the configuration parameters for this TCP server.voidhalt()Halts all clients connected to this TCP server and then stops the server.voidhaltAllClients()Halts all clients connected to this TCP server.voidhandleConnection(Socket socket)Creates and starts a server-sideTcpClientfor an accepted socket.booleanisRunning()Determines whether this communication entity is currently running.voidrun()Runs the TCP server and accepts incoming client connections.voidstop()Stops this TCP server and closes its server socket.-
Methods inherited from class com.kristensoft.kdc.Server
getBacklog, getHub, sendAsync, start
-
-
-
-
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 errorKristenCommsException- 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.
-
handleConnection
public void handleConnection(Socket socket)
Creates and starts a server-sideTcpClientfor 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.
-
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.
-
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.
-
isRunning
public boolean isRunning()
Determines whether this communication entity is currently running.- Returns:
trueif this communication entity is running;falseotherwise
-
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
-
-