Package java.nio.channels.spi
Class AbstractSelector
java.lang.Object
java.nio.channels.Selector
java.nio.channels.spi.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 Summary
Constructors Modifier Constructor Description protectedAbstractSelector(SelectorProvider selectorProvider) -
Method Summary
Modifier and Type Method Description protected voidbegin()Indicates the beginning of a code section that includes an I/O operation that is potentially blocking.protected Set<SelectionKey>cancelledKeys()Returns this channel's set of canceled selection keys.voidclose()Closes this selector.protected voidderegister(AbstractSelectionKey key)Deletes the key from the channel's key set.protected voidend()Indicates the end of a code section that has been started withbegin()and that includes a potentially blocking I/O operation.protected abstract voidimplCloseSelector()Implements the closing of this channel.booleanisOpen()Returns true if this selector is open.SelectorProviderprovider()Returns this selector's provider.protected abstract SelectionKeyregister(AbstractSelectableChannel channel, int operations, Object attachment)Registerschannelwith this selector.
-
Constructor Details
-
AbstractSelector
-
-
Method Details
-
close
Closes this selector. This method does nothing if this selector is already closed. The actual closing must be implemented by subclasses inimplCloseSelector().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classSelector- Throws:
IOException- if an I/O error occurs.
-
implCloseSelector
Implements the closing of this channel.- Throws:
IOException
-
isOpen
public final boolean isOpen()Returns true if this selector is open. -
provider
Returns this selector's provider. -
cancelledKeys
Returns this channel's set of canceled selection keys. -
register
protected abstract SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment)Registerschannelwith this selector.- Parameters:
operations- theinterest setofchannel.attachment- the attachment for the selection key.- Returns:
- the key related to the channel and this selector.
-
deregister
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 correspondingend(boolean)method. -
end
protected final void end()Indicates the end of a code section that has been started withbegin()and that includes a potentially blocking I/O operation.
-