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 (if not already closed), which implicitly unregisters the associated SelectionKeys and causes the serviceIO() methods of other handlers waiting on the same channel to be invoked, where they will then likely throw ClosedChannelException, which in turn causes a subsequent invocation of this method. Therefore, if this instance is shared by multiple selection keys selecting on the same channel, it should be idempotent.

      Parameters:
      cause - the error that occurred