- java.lang.Object
-
- java.nio.channels.Selector
-
- java.nio.channels.spi.AbstractSelector
-
- All Implemented Interfaces:
- Closeable, AutoCloseable
public abstract class AbstractSelector extends Selector
Base implementation class for selectors.This class encapsulates the low-level machinery required to implement the interruption of selection operations. A concrete selector class must invoke the
begin
andend
methods before and after, respectively, invoking an I/O operation that might block indefinitely. In order to ensure that theend
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'sregister
method in order to perform the actual work of registering a channel.- Since:
- 1.4
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
AbstractSelector(SelectorProvider provider)
Initializes a new instance of this class.
-
Method Summary
Methods Modifier and Type Method and Description protected void
begin()
Marks the beginning of an I/O operation that might block indefinitely.protected Set<SelectionKey>
cancelledKeys()
Retrieves this selector's cancelled-key set.void
close()
Closes this selector.protected void
deregister(AbstractSelectionKey key)
Removes the given key from its channel's key set.protected void
end()
Marks the end of an I/O operation that might block indefinitely.protected abstract void
implCloseSelector()
Closes this selector.boolean
isOpen()
Tells whether or not this selector is open.SelectorProvider
provider()
Returns the provider that created this channel.protected abstract SelectionKey
register(AbstractSelectableChannel ch, int ops, Object att)
Registers the given channel with this selector.
-
-
-
Constructor Detail
-
AbstractSelector
protected AbstractSelector(SelectorProvider provider)
Initializes a new instance of this class.
-
-
Method Detail
-
close
public final void close() throws IOException
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
implCloseSelector
method in order to complete the close operation.- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classSelector
- Throws:
IOException
- If an I/O error occurs
-
implCloseSelector
protected abstract void implCloseSelector() throws IOException
Closes this selector.This method is invoked by the
close
method 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
wakeup
method.- Throws:
IOException
- If an I/O error occurs while closing the selector
-
isOpen
public final boolean isOpen()
Description copied from class:Selector
Tells whether or not this selector is open.
-
provider
public final SelectorProvider provider()
Returns the provider that created this channel.
-
cancelledKeys
protected final Set<SelectionKey> cancelledKeys()
Retrieves this selector's cancelled-key set.This set should only be used while synchronized upon it.
- Returns:
- The cancelled-key set
-
register
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
register
method in order to perform the actual work of registering the channel with this selector.- Parameters:
ch
- The channel to be registeredops
- The initial interest set, which must be validatt
- The initial attachment for the resulting key- Returns:
- A new key representing the registration of the given channel with this selector
-
deregister
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.
- Parameters:
key
- The selection key to be removed
-
begin
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
end
method, using a try ... finally block as shown above, in order to implement interruption for this selector.Invoking this method arranges for the selector's
wakeup
method to be invoked if a thread'sinterrupt
method is invoked while the thread is blocked in an I/O operation upon the selector.
-
end
protected final void end()
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/nio/channels/spi/AbstractSelector.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.