Class SelectionRegistration


  • public class SelectionRegistration
    extends java.lang.Object
    Represents a unique registration between a NIO selector and a selectable channel. For the operation codes, see the constants in SelectionKey.
    Author:
    Jerome Louvel
    See Also:
    SelectionKey
    • Constructor Detail

      • SelectionRegistration

        public SelectionRegistration​(int interestOperations,
                                     SelectionListener selectionListener,
                                     org.restlet.engine.io.WakeupListener wakeupListener)
        Constructor.
        Parameters:
        interestOperations - The IO operations interest.
        selectionListener - The selection listener that will be notified.
        wakeupListener - The wakeup listener that will be notified.
      • SelectionRegistration

        public SelectionRegistration​(java.nio.channels.SelectableChannel selectableChannel,
                                     int interestOperations,
                                     SelectionListener selectionListener,
                                     org.restlet.engine.io.WakeupListener wakeupListener)
        Constructor.
        Parameters:
        selectableChannel - The parent selectable channel.
        interestOperations - The IO operations interest.
        selectionListener - The selection listener that will be notified.
        wakeupListener - The wakeup listener that will be notified.
    • Method Detail

      • getName

        public static java.lang.String getName​(int operation)
        Returns the name of the given IO operation.
        Parameters:
        operation - The IO operation code.
        Returns:
        The name of the given IO operation.
      • addInterestOperations

        public void addInterestOperations​(int interest)
        Adds a given operations to the current list.
        Parameters:
        interest -
      • block

        public void block()
                   throws java.io.IOException
        Blocks the calling thread.
        Throws:
        java.io.IOException
        See Also:
        block()
      • clear

        public void clear()
        Clears the registration.
      • getInterestOperations

        public int getInterestOperations()
        Returns the IO operations interest.
        Returns:
        The IO operations interest.
      • getReadyOperations

        public int getReadyOperations()
        Returns the IO operations ready.
        Returns:
        The IO operations ready.
      • getSelectableChannel

        public java.nio.channels.SelectableChannel getSelectableChannel()
        Returns the parent selectable channel.
        Returns:
        The parent selectable channel.
      • getSelectionListener

        public SelectionListener getSelectionListener()
        Returns the selection listener that will be notified.
        Returns:
        The selection listener that will be notified.
      • getWakeupListener

        public org.restlet.engine.io.WakeupListener getWakeupListener()
        Returns the wakeup listener that will be notified.
        Returns:
        The wakeup listener that will be notified.
      • isCanceling

        public boolean isCanceling()
        Indicates if a canceling of the registration has been requested.
        Returns:
        True if the registration has been canceled.
      • isConnectable

        public boolean isConnectable()
        Indicates if the NIO channel is connectable.
        Returns:
        True if the NIO channel is connectable.
      • isInterestReady

        public boolean isInterestReady()
        Indicates if the operations of interest are ready.
        Returns:
        True if the operations of interest are ready.
      • isReadable

        public boolean isReadable()
        Indicates if the NIO channel is readable.
        Returns:
        True if the NIO channel is readable.
      • isWritable

        public boolean isWritable()
        Indicates if the NIO channel is writable.
        Returns:
        True if the NIO channel is writable.
      • onSelected

        public void onSelected​(int readyOperations)
                        throws java.io.IOException
        Called back with some interest operations are ready. By default, it calls back the registered listener provided by getSelectionListener().
        Parameters:
        readyOperations - The ready operations.
        Throws:
        java.io.IOException
      • register

        public java.nio.channels.SelectionKey register​(java.nio.channels.Selector selector)
        Effectively registers the getSelectableChannel() with the given Selector for the getInterestOperations() operations.
        Parameters:
        selector - The NIO selector to register to.
      • resume

        public void resume()
        Resume interest in new listener notifications. This should be called after a suspend() call.
      • setCanceling

        public void setCanceling​(boolean canceling)
        Sets interest in canceling the registration.
        Parameters:
        canceling - True if a canceling request is made.
      • setInterestOperations

        public boolean setInterestOperations​(int interest)
        Sets the IO operations interest. Note that it also clears the ready operations.
        Parameters:
        interest - The IO operations interest.
        Returns:
        True if the operations effectively changed.
      • setNoInterest

        public void setNoInterest()
        Sets interest in no IO operations.
      • setReadInterest

        public void setReadInterest()
        Sets interest in IO read operations.
      • setReadyOperations

        public void setReadyOperations​(int readyOperations)
        Sets the IO operations ready.
        Parameters:
        readyOperations - The IO operations ready.
      • setSelectionListener

        public void setSelectionListener​(SelectionListener listener)
        Sets the selection listener that will be notified.
        Parameters:
        listener - The selection listener that will be notified.
      • setWakeupListener

        public void setWakeupListener​(org.restlet.engine.io.WakeupListener wakeupListener)
        Sets the wakeup listener that will be notified.
        Parameters:
        wakeupListener - The wakeup listener that will be notified.
      • setWriteInterest

        public void setWriteInterest()
        Sets interest in IO read operations.
      • suspend

        public void suspend()
        Suspend interest in new listener notifications. By default, remembers the current interest and calls setInterestOperations(int) with a 0 value.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • unblock

        public void unblock()
                     throws java.io.IOException
        Unblocks the optionally blocked thread.
        Throws:
        java.io.IOException
        See Also:
        block()
      • update

        public java.nio.channels.SelectionKey update()
        Effectively updates the registration of the getSelectableChannel() with the given Selector for the getInterestOperations() operations.
        Returns:
        The updated selection key or a new one if it was registered again.