Class AbstractSelector

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public abstract class AbstractSelector
    extends Selector
    AbstractSelector is the base implementation class for selectors. It realizes the interruption of selection by begin and end. It also holds the cancellation and the deletion of the key set.
    • Constructor Detail

      • AbstractSelector

        protected AbstractSelector​(SelectorProvider selectorProvider)
    • Method Detail

      • close

        public final void close()
                         throws IOException
        Closes this selector. This method does nothing if this selector is already closed. The actual closing must be implemented by subclasses in implCloseSelector().
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in class Selector
        Throws:
        IOException - if an I/O error occurs.
      • implCloseSelector

        protected abstract void implCloseSelector()
                                           throws IOException
        Implements the closing of this channel.
        Throws:
        IOException
      • isOpen

        public final boolean isOpen()
        Returns true if this selector is open.
        Specified by:
        isOpen in class Selector
        Returns:
        true if this selector is not closed, false otherwise.
      • provider

        public final SelectorProvider provider()
        Returns this selector's provider.
        Specified by:
        provider in class Selector
        Returns:
        the provider of this selector.
      • cancelledKeys

        protected final Set<SelectionKey> cancelledKeys()
        Returns this channel's set of canceled selection keys.
      • register

        protected abstract SelectionKey register​(AbstractSelectableChannel channel,
                                                 int operations,
                                                 Object attachment)
        Registers channel with this selector.
        Parameters:
        operations - the interest set of channel.
        attachment - the attachment for the selection key.
        Returns:
        the key related to the channel and this selector.
      • deregister

        protected final void deregister​(AbstractSelectionKey key)
        Deletes the key from the channel's key set.
      • begin

        protected final void begin()
        Indicates the beginning of a code section that includes an I/O operation that is potentially blocking. After this operation, the application should invoke the corresponding end(boolean) method.
      • end

        protected final void end()
        Indicates the end of a code section that has been started with begin() and that includes a potentially blocking I/O operation.