- All Implemented Interfaces:
- Closeable,- AutoCloseable
 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.  
- Since:
- 1.4
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractSelector(SelectorProvider provider) Initializes a new instance of this class.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final voidbegin()Marks the beginning of an I/O operation that might block indefinitely.protected final Set<SelectionKey>Retrieves this selector's cancelled-key set.final voidclose()Closes this selector.protected final voidRemoves the given key from its channel's key set.protected final voidend()Marks the end of an I/O operation that might block indefinitely.protected abstract voidCloses this selector.final booleanisOpen()Tells whether or not this selector is open.final SelectorProviderprovider()Returns the provider that created this channel.protected abstract SelectionKeyregister(AbstractSelectableChannel ch, int ops, Object att) Registers the given channel with this selector.
- 
Constructor Details- 
AbstractSelectorInitializes a new instance of this class.- Parameters:
- provider- The provider that created this selector
 
 
- 
- 
Method Details- 
closeCloses 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 implCloseSelectormethod in order to complete the close operation.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein class- Selector
- Throws:
- IOException- If an I/O error occurs
 
- 
implCloseSelectorCloses this selector.This method is invoked by the closemethod in order to perform the actual work of closing the selector. This method is only invoked if the selector has not yet been closed, and it is never invoked more than once.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 wakeupmethod.- Throws:
- IOException- If an I/O error occurs while closing the selector
 
- 
isOpenpublic final boolean isOpen()Description copied from class:SelectorTells whether or not this selector is open.
- 
providerReturns the provider that created this channel.
- 
cancelledKeysRetrieves this selector's cancelled-key set.This set should only be used while synchronized upon it. - Returns:
- The cancelled-key set
 
- 
registerRegisters the given channel with this selector.This method is invoked by a channel's registermethod in order to perform the actual work of registering the channel with this selector.- Parameters:
- ch- The channel to be registered
- ops- The initial interest set, which must be valid
- att- The initial attachment for the resulting key
- Returns:
- A new key representing the registration of the given channel with this selector
 
- 
deregisterRemoves the given key from its channel's key set.This method must be invoked by the selector for each channel that it deregisters. - Parameters:
- key- The selection key to be removed
 
- 
beginprotected final void begin()Marks the beginning of an I/O operation that might block indefinitely.This method should be invoked in tandem with the endmethod, using atry...finallyblock as shown above, in order to implement interruption for this selector.Invoking this method arranges for the selector's wakeupmethod to be invoked if a thread'sinterruptmethod is invoked while the thread is blocked in an I/O operation upon the selector.
- 
endprotected final void end()
 
-