public abstract class ConcurrentServerRunner<T extends Client> extends ContextAwareBase implements Runnable, ServerRunner<T>A concurrent
An instance of this object is created with a
Executor. On invocation of the
#start()method, it passes itself to the given
Executorand returns immediately. On invocation of its
run()method by the
Executorit begins accepting client connections via its
ServerListener. As each new
Clientis accepted, the client is configured with the runner's
LoggingContextand is then passed to the
Executorfor concurrent execution of the client's service loop.
On invocation of the
stop()method, the runner closes the listener and each of the connected clients (by invoking
Client.close()effectively interrupting any blocked I/O calls and causing these concurrent subtasks to exit gracefully). This ensures that before the
stop()method returns (1) all I/O resources have been released and (2) all of the threads of the
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
accept(ClientVisitor<T> visitor)Presents each connected client to the given visitor.
isRunning()Gets a flag indicating whether the server is currently running.
stop()Stops execution of the runner.
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getStatusManager, setContext
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ConcurrentServerRunner(ServerListener<T> listener, Executor executor)Constructs a new server runner.
listener- the listener from which the server will accept new clients
executor- a executor that will facilitate execution of the listening and client-handling tasks; while any
Executoris allowed here, outside of unit testing the only reasonable choice is a bounded thread pool of some kind.
public boolean isRunning()Gets a flag indicating whether the server is currently running.
public void stop() throws IOExceptionStops execution of the runner.
This method must cause all I/O and thread resources associated with the runner to be released. If the receiver has not been started, this method must have no effect.
public void accept(ClientVisitor<T> visitor)Presents each connected client to the given visitor.