Package org.dellroad.stuff.net
Interface SocketHandler
public interface SocketHandler
Implemented by objects that handle individual connections accepted by a
SocketAcceptor
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleConnection
(Socket socket) Handle the connection.void
Receive notification that the server is shutting down.
-
Method Details
-
handleConnection
Handle the connection.- Parameters:
socket
- connection socket- Throws:
IOException
- if needed
-
stop
Receive notification that the server is shutting down. This method should ensure that the thread currently executinghandleConnection()
returns as soon as possible.After this method returns, the
socket
will be closed (if not already). So one way to implement this method is to simply do nothing, which will trigger anIOException
on the next access from withinhandleConnection()
.Alternately, set some flag that
handleConnection()
detects each time around its processing loop, or useThread.interrupt()
, etc.In any case, it is important that
handleConnection()
thread does eventually return, otherwise the thread invokingSocketAcceptor.stop()
will hang.Note: it may be that
handleConnection()
has already returned when this method is invoked, in which case this method should do nothing.- Parameters:
thread
- the thread invokinghandleConnection()
socket
- connection socket
-