ChatServer
, ServerSocketObserverAdapter
public interface ServerSocketObserver
A server socket observer is responsible for handling incoming connections by implementing a callback to properly assign a SocketObserver to the new connections.
All callbacks will be run on the NIOService-thread, so callbacks should try to return as quickly as possible since the callback blocks communication on all sockets of the service.
Modifier and Type | Method | Description |
---|---|---|
void |
acceptFailed(java.io.IOException exception) |
Called by the NIOService on the NIO thread when an accept fails on the socket.
|
void |
newConnection(NIOSocket nioSocket) |
Called by the NIOService on the NIO thread when a new connection has been accepted by the socket.
|
void |
serverSocketDied(java.lang.Exception exception) |
Called by the NIOService on the NIO thread when the server socket is closed.
|
void acceptFailed(java.io.IOException exception)
Note: Since this is a direct callback on the NIO thread, this method will suspend IO on all other connections until the method returns. It is therefore strongly recommended that the implementation of this method returns as quickly as possible to avoid blocking IO.
exception
- the reason for the failure, never null.void serverSocketDied(java.lang.Exception exception)
Note: Since this is a direct callback on the NIO thread, this method will suspend IO on all other connections until the method returns. It is therefore strongly recommended that the implementation of this method returns as quickly as possible to avoid blocking IO.
exception
- the exception that caused the close, or null if this was
caused by an explicit close()
on the NIOServerSocket.void newConnection(NIOSocket nioSocket)
The normal behaviour would be for the observer to assign a reader and a writer to the socket,
and then finally invoke NIOSocket#listen(SocketObserver)
on the socket.
Note: Since this is a direct callback on the NIO thread, this method will suspend IO on all other connections until the method returns. It is therefore strongly recommended that the implementation of this method returns as quickly as possible to avoid blocking IO.
nioSocket
- the socket that was accepted.