Class AFSocketServer<A extends AFSocketAddress>
java.lang.Object
org.newsclub.net.unix.server.SocketServer<A, AFSocket<? extends A>, AFServerSocket<? extends A>>
org.newsclub.net.unix.server.AFSocketServer<A>
- Type Parameters:
A- The supported address type.
public abstract class AFSocketServer<A extends AFSocketAddress>
extends SocketServer<A, AFSocket<? extends A>, AFServerSocket<? extends A>>
A base implementation for a simple, multi-threaded socket server using
AFSockets.- Author:
- Christian Kohlschütter
-
Constructor Summary
ConstructorsConstructorDescriptionAFSocketServer(A listenAddress) Creates a server using the givenSocketAddress.AFSocketServer(AFServerSocket<? extends A> serverSocket) Creates a server using the given, boundServerSocket. -
Method Summary
Methods inherited from class SocketServer
doServeSocket, doSocketClose, getListenAddress, getMaxConcurrentConnections, getServerBusyTimeout, getServerTimeout, getSocketTimeout, isReady, isRunning, onAfterServingSocket, onBeforeServingSocket, onListenException, onListenException, onServerBound, onServerBusy, onServerReady, onServerShuttingDown, onServerStarting, onServerStopped, onServingException, onServingException, onSocketExceptionAfterAccept, onSocketExceptionDuringAccept, onSubmitted, setMaxConcurrentConnections, setServerBusyTimeout, setServerTimeout, setSocketTimeout, start, startAndWaitToBecomeReady, startAndWaitToBecomeReady, startThenStopAfter, stopModifier and TypeMethodDescriptionprotected abstract voiddoServeSocket(AFSocket<? extends A> socket) Called when a socket is ready to be served.protected voiddoSocketClose(AFSocket<? extends A> socket) Called upon closing a socket after serving the connection.protected AReturns the address the server listens to.intReturns the maximum number of concurrent connections.intReturns the server-busy timeout (in milliseconds).intReturns the server timeout (in milliseconds).intReturns the socket timeout (in milliseconds).booleanisReady()Checks if the server is running and accepting new connections.booleanChecks if the server is running.protected voidonAfterServingSocket(AFSocket<? extends A> socket) Called after the socket has been served.protected voidonBeforeServingSocket(AFSocket<? extends A> socket) Called before serving the socket.protected voidDeprecated.protected voidCalled when an exception was thrown while listening on the server socket.protected voidonServerBound(A address) Called when the server has been bound to a socket.protected voidonServerBusy(long busyStartTime) Called when the server is busy / not ready to accept a new connection.protected voidonServerReady(int activeCount) Called when the server is ready to accept a new connection.protected voidCalled when the server is shutting down.protected voidCalled when the server is starting up.protected voidonServerStopped(AFServerSocket<? extends A> socket) Called when the server has been stopped.protected voidonServingException(AFSocket<? extends A> socket, Exception e) Deprecated.protected voidonServingException(AFSocket<? extends A> socket, Throwable t) Called when a throwable was thrown while serving a socket.protected voidonSocketExceptionAfterAccept(AFSocket<? extends A> socket, SocketException e) Called when aSocketExceptionwas thrown during "accept".protected voidCalled when aSocketExceptionwas thrown during "accept".protected voidonSubmitted(AFSocket<? extends A> socket, Future<?> submission) Called when a socket gets submitted into the process queue.voidsetMaxConcurrentConnections(int maxConcurrentConnections) Sets the maximum number of concurrent connections.voidsetServerBusyTimeout(int timeout) Sets the server-busy timeout (in milliseconds).voidsetServerTimeout(int timeout) Sets the server timeout (in milliseconds).voidsetSocketTimeout(int timeout) Sets the socket timeout (in milliseconds).voidstart()Starts the server, and returns immediately.voidStarts the server and waits until it is ready or had to stop due to an error.booleanstartAndWaitToBecomeReady(long duration, TimeUnit unit) Starts the server and waits until it is ready or had to stop due to an error.startThenStopAfter(long delay, TimeUnit unit) Requests that the server will be stopped after the given time delay.voidstop()Stops the server.
-
Constructor Details
-
AFSocketServer
Creates a server using the given, boundServerSocket.- Parameters:
serverSocket- The server socket to use (must be bound).
-
AFSocketServer
Creates a server using the givenSocketAddress.- Parameters:
listenAddress- The address to bind the socket on.
-
-
Method Details
-
newServerSocket
Description copied from class:SocketServerReturns a new server socket.- Specified by:
newServerSocketin classSocketServer<A extends AFSocketAddress, AFSocket<? extends A extends AFSocketAddress>, AFServerSocket<? extends A extends AFSocketAddress>>- Returns:
- The new socket (an
AFServerSocketif the listen address is anAFSocketAddress). - Throws:
IOException- on error.
-
SocketServer.onListenException(Throwable)