Interface TemporarySelectorState

All Known Implementing Classes:
TemporarySelectorStateClosed, TemporarySelectorStateOpen

public interface TemporarySelectorState
An interface which models the state and transitions of a temporary Selector.
  • Method Details

    • select

      int select(Selector theSelector, long theTimeout) throws 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 use
      theTimeout - 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:
      IOException - If an I/O error occurs
      ClosedSelectorException - If this theSelector is closed
      IllegalArgumentException - If the value of the theTimeout argument is not greater than 0
    • registerChannel

      SelectionKey registerChannel(Selector theSelector, SelectableChannel theSelectableChannel, int theOps) throws 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 registered
      theSelectableChannel - 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:
      ClosedChannelException - If theSelectableChannel is closed
      IllegalBlockingModeException - If theSelectableChannel is in blocking mode
      IllegalSelectorException - If thSelectableChannel was not created by the same provider as theSelector
      CancelledKeyException - If theSelectableChannel is currently registered with theSelector but the corresponding key has already been cancelled
      IllegalArgumentException - If a bit in theOps does not correspond to an operation that is supported by theSelectableChannel, that is, if set & ~theSeletableChannel.validOps() != 0
      IOException
    • cancelKeyAndFlushSelector

      TemporarySelectorState cancelKeyAndFlushSelector(Selector theSelector, SelectionKey theSelectionKey) throws 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 registered
      theSelectionKey - A key representing the registration of theSelectableChannel with theSelector
      Returns:
      TemporarySelectorState, the state of the TemporarySelector after invoking this method.
      Throws:
      IOException - if an error occurred
    • close

      TemporarySelectorState close(Selector theSelector) throws 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:
      IOException - If an I/O error occurs
    • removeSelectedKey

      TemporarySelectorState removeSelectedKey(Selector theSelector, SelectionKey theSelectionKey) throws 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:
      IOException - If this selector is closed