Class Server
- java.lang.Object
-
- com.kristensoft.kdc.Server
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
- Direct Known Subclasses:
KristenHttpServer,TcpServer,WebSocketServer
public abstract class Server extends Object implements Closeable, Runnable
Provides the base implementation for KDC communication servers.A server runs on its own thread and manages clients created from incoming connections. Connected clients may be maintained in the server's
Hub, allowing agents to be broadcast to all clients associated with the server.Transport-specific servers extend this class to provide the server's main processing and shutdown behavior.
- Author:
- Charles B. Kozoyed
- See Also:
CommsEntity,ServerParameters,Hub
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclose()Closes this server and releases its transport-specific resources.voidflushMetrics()Flushes the accumulated latency metrics for this communication entity.AgentSerializergetAgentSerializer()Returns the agent serializer used by this communication entity.intgetBacklog()Returns the maximum number of pending connections allowed in the server's connection backlog.HubgetHub()Returns the hub containing the clients associated with this server.voidhalt()Stops this server and closes its transport-specific resources.booleanisRunning()Determines whether this communication entity is currently running.abstract voidrun()Executes the main processing loop for this server.voidsendAsync(Agent agent)Sends an asynchronous agent to all clients connected to this server.voidstart()Starts the server thread responsible for accepting incoming connections.voidstop()Stops the server thread responsible for accepting incoming connections.
-
-
-
Method Detail
-
run
public abstract void run()
Executes the main processing loop for this server.Transport-specific server implementations provide the logic required to accept and process incoming connections or requests.
-
close
public abstract void close()
Closes this server and releases its transport-specific resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
sendAsync
public void sendAsync(Agent agent) throws IOException
Sends an asynchronous agent to all clients connected to this server.- Parameters:
agent- the agent to send- Throws:
IOException- if an I/O error occurs while sending the agent
-
halt
public void halt()
Stops this server and closes its transport-specific resources.This method stops the server thread responsible for accepting incoming connections and then closes the server.
-
start
public void start()
Starts the server thread responsible for accepting incoming connections.If the server is already running, this method has no effect.
-
stop
public void stop()
Stops the server thread responsible for accepting incoming connections.The server is marked as no longer running and, if a server thread exists, the thread is interrupted and this method waits for it to terminate.
-
getBacklog
public final int getBacklog()
Returns the maximum number of pending connections allowed in the server's connection backlog.- Returns:
- the server connection backlog
-
getHub
public final Hub getHub()
Returns the hub containing the clients associated with this server.The hub may be used to access the server's clients and to broadcast agents to all connected clients.
- Returns:
- the server's hub
-
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
-
-