Interface TemporarySelectorState
-
- All Known Implementing Classes:
TemporarySelectorStateClosed
,TemporarySelectorStateOpen
public interface TemporarySelectorState
An interface which models the state and transitions of a temporary Selector.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TemporarySelectorState
cancelKeyAndFlushSelector(java.nio.channels.Selector theSelector, java.nio.channels.SelectionKey theSelectionKey)
Requests that the registration of a SelectableChannel with theSelector, theSelectionKey be cancelled and flushed from theSelector.TemporarySelectorState
close(java.nio.channels.Selector theSelector)
Closes theSelector.java.nio.channels.SelectionKey
registerChannel(java.nio.channels.Selector theSelector, java.nio.channels.SelectableChannel theSelectableChannel, int theOps)
Registers theSelectableChannel with theSelector, setting theSelection to the key returned by the registeration.TemporarySelectorState
removeSelectedKey(java.nio.channels.Selector theSelector, java.nio.channels.SelectionKey theSelectionKey)
Remove theSelectionKey from the theSelector's selected key set.int
select(java.nio.channels.Selector theSelector, long theTimeout)
Selects a set of keys whose corresponding SelectableChannel is ready for I/O operations.
-
-
-
Method Detail
-
select
int select(java.nio.channels.Selector theSelector, long theTimeout) throws java.io.IOException
Selects a set of keys whose corresponding SelectableChannel is ready for I/O operations.This method performs a blocking selection operation on theSelector. It returns only after the SelectableChannel is selected, theSelector's wakeup method is invoked, the current thread is interrupted, or the given timeout period expires, whichever comes first.
This method does not offer real-time guarantees: It schedules theTimeout as if by invoking the
Object.wait(long)
method.- Parameters:
theSelector
- The Selector to usetheTimeout
- If positive, block for up to theTimeout milliseconds, more or less, while waiting for a SelectableChannel to become ready; must be greater than 0 in value- Returns:
- The number of keys, possibly zero, whose ready-operation sets was updated.
- Throws:
java.io.IOException
- If an I/O error occursjava.nio.channels.ClosedSelectorException
- If this theSelector is closedjava.lang.IllegalArgumentException
- If the value of the theTimeout argument is not greater than 0
-
registerChannel
java.nio.channels.SelectionKey registerChannel(java.nio.channels.Selector theSelector, java.nio.channels.SelectableChannel theSelectableChannel, int theOps) throws java.io.IOException
Registers theSelectableChannel with theSelector, setting theSelection to the key returned by the registeration.- Parameters:
theSelector
- The selector with which this channel is to be registeredtheSelectableChannel
- The SelectableChannel to register theSelector with.theOps
- The interest set for the resulting key- Returns:
- A key representing the registration of theSelectableChannel with theSelector.
- Throws:
java.nio.channels.ClosedChannelException
- If theSelectableChannel is closedjava.nio.channels.IllegalBlockingModeException
- If theSelectableChannel is in blocking modejava.nio.channels.IllegalSelectorException
- If thSelectableChannel was not created by the same provider as theSelectorjava.nio.channels.CancelledKeyException
- If theSelectableChannel is currently registered with theSelector but the corresponding key has already been cancelledjava.lang.IllegalArgumentException
- If a bit intheOps
does not correspond to an operation that is supported by theSelectableChannel, that is, ifset & ~theSeletableChannel.validOps() != 0
java.io.IOException
-
cancelKeyAndFlushSelector
TemporarySelectorState cancelKeyAndFlushSelector(java.nio.channels.Selector theSelector, java.nio.channels.SelectionKey theSelectionKey) throws java.io.IOException
Requests that the registration of a SelectableChannel with theSelector, theSelectionKey be cancelled and flushed from theSelector. Upon return theSelectionKey will be invalid and will have been flushed from theSelector's key sets.If theSelectionKey has already been cancelled and it has been flushed from theSelector, then invoking this method has no effect. Once theSelectionKey is cancelled and flushed, theSelectionKey remains forever invalid.
This method may be invoked at any time. It synchronizes on the theSelector's cancelled-key set, and therefore may block briefly if invoked concurrently with a cancellation or selection operation involving the same selector.
- Parameters:
theSelector
- The selector with which this channel is to be registeredtheSelectionKey
- A key representing the registration of theSelectableChannel with theSelector- Returns:
- TemporarySelectorState, the state of the TemporarySelector after invoking this method.
- Throws:
java.io.IOException
- if an error occurred
-
close
TemporarySelectorState close(java.nio.channels.Selector theSelector) throws java.io.IOException
Closes theSelector.If a thread is currently blocked in one of theSelector's selection methods then it is interrupted as if by invoking theSelector's wakeup method.
Any uncancelled keys still associated with theSelector are invalidated, their SelectableChannels are deregistered, and any other resources associated with this selector are released.
If theSelector is already closed then invoking this method has no effect.
After theSelector is closed, any further attempt to use it, except by invoking this method, will cause a ClosedSelectorException to be thrown.
- Parameters:
theSelector
- The selector with which this channel is to be registered- Returns:
- TemporarySelectorState, the state of the TemporarySelector after invoking this method.
- Throws:
java.io.IOException
- If an I/O error occurs
-
removeSelectedKey
TemporarySelectorState removeSelectedKey(java.nio.channels.Selector theSelector, java.nio.channels.SelectionKey theSelectionKey) throws java.io.IOException
Remove theSelectionKey from the theSelector's selected key set.- Parameters:
theSelector
- The selector whose selected key set should have theSelectionKey removed.theSelectionKey
- A key representing the registration of theSelectableChannel with theSelector and the key should be removed key removed from the selected key set.- Returns:
- TemporarySelectorState, the state of the TemporarySelector after invoking this method.
- Throws:
java.io.IOException
- If this selector is closed
-
-