Interface SocketHandler


public interface SocketHandler
Implemented by objects that handle individual connections accepted by a SocketAcceptor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Handle the connection.
    void
    stop(Thread thread, Socket socket)
    Receive notification that the server is shutting down.
  • Method Details

    • handleConnection

      void handleConnection(Socket socket) throws IOException
      Handle the connection.
      Parameters:
      socket - connection socket
      Throws:
      IOException - if needed
    • stop

      void stop(Thread thread, Socket socket)
      Receive notification that the server is shutting down. This method should ensure that the thread currently executing handleConnection() 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 an IOException on the next access from within handleConnection().

      Alternately, set some flag that handleConnection() detects each time around its processing loop, or use Thread.interrupt(), etc.

      In any case, it is important that handleConnection() thread does eventually return, otherwise the thread invoking SocketAcceptor.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 invoking handleConnection()
      socket - connection socket