Interface SelectorSupport.IOHandler

All Known Implementing Classes:
ChannelConnection, TCPConnection
Enclosing class:
SelectorSupport

public static interface SelectorSupport.IOHandler
Callback interface used by SelectorSupport.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Invoked when an exception is thrown by serviceIO().
    void
    Handle ready I/O.
  • Method Details

    • serviceIO

      void serviceIO(SelectionKey key) throws IOException
      Handle ready I/O.
      Parameters:
      key - selection key
      Throws:
      IOException - if an I/O error occurs; this will result in close() being invoked
    • close

      void close(Throwable cause)
      Invoked when an exception is thrown by serviceIO().

      This usually indicates the channel has been (or should be) closed. In any case, it allows for this handler to perform any required cleanup.

      Typically this method will close the associated channel, which implicitly unregisters the associated SelectionKeys. This also causes the serviceIO() methods of other handlers waiting on the same channel to be invoked due to the ready I/O, where they will then likely throw ClosedChannelException, causing another invocation of this method. Therefore, this method should be idempotent.

      Parameters:
      cause - the error that occurred