Interface ISocketComm

All Superinterfaces:
IWorkerTimeout
All Known Implementing Classes:
ServerSocketComm, SocketComm, SocketCommNIO

public interface ISocketComm extends IWorkerTimeout
The interface for sockets or server sockets to implement for processing events.
Author:
Christopher Mindus
  • Method Details

    • process

      void process(ByteBuffer buf)
      Called for the selection key associated with the ISocketComm implementor (normally SocketComm and ServerSocketComm) to process data.
    • close

      boolean close(boolean rightNow)
      Called when the socket should be closed.
      Parameters:
      rightNow - If true, the (server) socket channel is closed immediately, otherwise (SocketChannel), the socket may flush all output before closing.
      Returns:
      true if closed, false if already closed.
    • onProcessFailure

      default void onProcessFailure(Throwable failure)
      Called when process(ByteBuffer) terminated with an unchecked exception.

      process(ByteBuffer) declares no checked exceptions, so anything a handler throws arrives here instead of terminating the worker. One worker serves every socket registered with it, and terminal sessions in the same application session share one, so a defect in a single handler must not be allowed to stop the others.

      The implementation must close this connection: the handler has left it in an unknown state, and merely skipping it would present the same event again on the next selector pass, turning a one-off fault into an endless loop. An immediate close is correct rather than a graceful one - there is nothing to be gained by flushing through a handler that has just failed.

      The default closes immediately and reports nothing further. Implementations that own a listener should override to tell it, so an operator can distinguish a handler defect from a peer disconnect. The worker contains anything thrown out of this method and cancels the selection key regardless, so an implementation that fails here cannot keep the socket selectable, but it also cannot rely on any of its own later cleanup running.

      Parameters:
      failure - The exception or error thrown by process(ByteBuffer).