Class ActionSelector
- java.lang.Object
-
- org.simpleframework.transport.reactor.ActionSelector
-
class ActionSelector extends java.lang.Object
TheActionSelector
object is used to perform socket based selection with the help of theActionSet
object. All registered channels have an associated action set. The action set contains a set of actions that should be executed when the selector selects the channel.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.Selector
selector
This is the selector used to perform the select operations.
-
Constructor Summary
Constructors Constructor Description ActionSelector()
Constructor for theActionSelector
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This is used to close the associated selector.ActionSet
register(java.nio.channels.SelectableChannel channel, int interest)
This performs the actual registration of the channel for selection based on the provided interest bitmask.java.util.List<ActionSet>
registeredSets()
This is used to acquire all the action sets that are associated with this selector.private java.util.List<ActionSet>
registeredSets(java.util.Iterator<java.nio.channels.SelectionKey> keys)
This is used to acquire all the action sets that are associated with this selector.int
select(long timeout)
This is used to perform a select on the selector.java.util.List<ActionSet>
selectedSets()
This is used to acquire all the action sets that are selected by this selector.private java.util.List<ActionSet>
selectedSets(java.util.Iterator<java.nio.channels.SelectionKey> keys)
This is used to acquire all the action sets that are selected by this selector.void
wake()
This is used to wake the selector if it is in the middle of a select operation.
-
-
-
Constructor Detail
-
ActionSelector
public ActionSelector() throws java.io.IOException
Constructor for theActionSelector
object. This is used to create a selector that can register socket channels with an associatedActionSet
. The set can then be used to store actions to be executed upon selection.- Throws:
java.io.IOException
-
-
Method Detail
-
select
public int select(long timeout) throws java.io.IOException
This is used to perform a select on the selector. This returns the number of channels that have been selected. If this returns a number greater than zero theready
method can be used to acquire the actions that are ready for execution.- Parameters:
timeout
- this is the timeout associated with the select- Returns:
- this returns the number of channels that are ready
- Throws:
java.io.IOException
-
register
public ActionSet register(java.nio.channels.SelectableChannel channel, int interest) throws java.io.IOException
This performs the actual registration of the channel for selection based on the provided interest bitmask. When the channel has been registered for selection this returns anActionSet
for the selection key. The set can then be used to register the actions that should be executed when selection succeeds.- Parameters:
channel
- this is the channel to register for selectioninterest
- this is the interested operations bitmask- Returns:
- this is the action set associated with the registration
- Throws:
java.io.IOException
-
registeredSets
public java.util.List<ActionSet> registeredSets()
This is used to acquire all the action sets that are associated with this selector. Only action sets that have a valid selection key are returned. Modification of the list will not affect the associated selector instance.- Returns:
- this returns all the associated action sets for this
-
registeredSets
private java.util.List<ActionSet> registeredSets(java.util.Iterator<java.nio.channels.SelectionKey> keys)
This is used to acquire all the action sets that are associated with this selector. Only action sets that have a valid selection key are returned. Modification of the list will not affect the associated selector instance.- Parameters:
keys
- the selection keys to get the associated sets from- Returns:
- this returns all the associated action sets for this
-
selectedSets
public java.util.List<ActionSet> selectedSets() throws java.io.IOException
This is used to acquire all the action sets that are selected by this selector. All action sets returned are unregistered from the selector and must be registered again to hear about further I/O events that occur on the associated channel.- Returns:
- this returns all the selected action sets for this
- Throws:
java.io.IOException
-
selectedSets
private java.util.List<ActionSet> selectedSets(java.util.Iterator<java.nio.channels.SelectionKey> keys)
This is used to acquire all the action sets that are selected by this selector. All action sets returned are unregistered from the selector and must be registered again to hear about further I/O events that occur on the associated channel.- Parameters:
keys
- the selection keys to get the associated sets from- Returns:
- this returns all the selected action sets for this
-
wake
public void wake() throws java.io.IOException
This is used to wake the selector if it is in the middle of a select operation. Waking up the selector in this manner is useful if further actions are to be registered with it.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
This is used to close the associated selector. Further attempts to register a channel with the selector will fail. All actions should be cancelled before closing the selector in this way.- Throws:
java.io.IOException
-
-