This class encapsulates the low-level machinery required to implement
the interruption of selection operations. A concrete selector class must
invoke the begin and end methods before and
after, respectively, invoking an I/O operation that might block
indefinitely. In order to ensure that the end method is always
invoked, these methods should be used within a
try ... finally block:
try { begin(); // Perform blocking I/O operation here ... } finally { end(); }
This class also defines methods for maintaining a selector's
cancelled-key set and for removing a key from its channel's key set, and
declares the abstract register method that is invoked by a
selectable channel's register
method in order to perform the actual work of registering a channel.
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private static final VarHandle | |
| private volatile boolean | |
| private final Interruptible | |
| private final SelectorProvider |
| Access | Constructor and Description |
|---|---|
| protected | AbstractSelector(SelectorProvider
The provider that created this selector provider)Initializes a new instance of this class. |
| Modifier and Type | Method and Description |
|---|---|
| protected final void | |
| pack-priv void | |
| protected final Set | |
| public final void | close()
Implements abstract java. Implements java. Closes this selector. |
| protected final void | deregister(AbstractSelectionKey
The selection key to be removed key)Removes the given key from its channel's key set. |
| protected final void | |
| protected abstract void | |
| public final boolean | isOpen()
Implements abstract java. Tells whether or not this selector is open. |
| public final SelectorProvider | Returns: The provider that created this channelImplements abstract java. Returns the provider that created this channel. |
| protected abstract SelectionKey | Returns: A new key representing the registration of the given channel with this selectorThe channel to be registered ch, int The initial interest set, which must be valid ops, Object The initial attachment for the resulting key att)Registers the given channel with this selector. |
| cancelledKeys | back to summary |
|---|---|
| private final Set<SelectionKey> cancelledKeys | |
| CLOSED | back to summary |
|---|---|
| private static final VarHandle CLOSED | |
| closed | back to summary |
|---|---|
| private volatile boolean closed | |
| interruptor | back to summary |
|---|---|
| private final Interruptible interruptor | |
| provider | back to summary |
|---|---|
| private final SelectorProvider provider | |
| AbstractSelector | back to summary |
|---|---|
| protected AbstractSelector(SelectorProvider provider) Initializes a new instance of this class.
| |
| begin | back to summary |
|---|---|
| protected final void begin() Marks the beginning of an I/O operation that might block indefinitely. This method should be invoked in tandem with the Invoking this method arranges for the selector's | |
| cancel | back to summary |
|---|---|
| pack-priv void cancel(SelectionKey k) | |
| cancelledKeys | back to summary |
|---|---|
| protected final Set Retrieves this selector's cancelled-key set. This set should only be used while synchronized upon it.
| |
| close | back to summary |
|---|---|
| public final void close() throws IOException Implements abstract java. Implements java. Closes this selector. If the selector has already been closed then this method returns
immediately. Otherwise it marks the selector as closed and then invokes
the
| |
| deregister | back to summary |
|---|---|
| protected final void deregister(AbstractSelectionKey key) Removes the given key from its channel's key set. This method must be invoked by the selector for each channel that it deregisters.
| |
| end | back to summary |
|---|---|
| protected final void end() Marks the end of an I/O operation that might block indefinitely. This method should be invoked in tandem with the | |
| implCloseSelector | back to summary |
|---|---|
| protected abstract void implCloseSelector() throws IOException Closes this selector. This method is invoked by the An implementation of this method must arrange for any other thread
that is blocked in a selection operation upon this selector to return
immediately as if by invoking the
| |
| isOpen | back to summary |
|---|---|
| public final boolean isOpen() Implements abstract java. Doc from java. Tells whether or not this selector is open. | |
| provider | back to summary |
|---|---|
| public final SelectorProvider provider() Implements abstract java. Returns the provider that created this channel.
| |
| register | back to summary |
|---|---|
| protected abstract SelectionKey register(AbstractSelectableChannel ch, int ops, Object att) Registers the given channel with this selector. This method is invoked by a channel's
| |