org.restlet.util
Class SelectionRegistration

java.lang.Object
  extended by org.restlet.util.SelectionRegistration

public class SelectionRegistration
extends 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 Summary
SelectionRegistration(int interestOperations, SelectionListener selectionListener, org.restlet.engine.io.WakeupListener wakeupListener)
          Constructor.
SelectionRegistration(SelectableChannel selectableChannel, int interestOperations, SelectionListener selectionListener, org.restlet.engine.io.WakeupListener wakeupListener)
          Constructor.
 
Method Summary
 void addInterestOperations(int interest)
          Adds a given operations to the current list.
 void block()
          Blocks the calling thread.
 void clear()
          Clears the registration.
 int getInterestOperations()
          Returns the IO operations interest.
static String getName(int operation)
          Returns the name of the given IO operation.
 int getReadyOperations()
          Returns the IO operations ready.
 SelectableChannel getSelectableChannel()
          Returns the parent selectable channel.
 SelectionListener getSelectionListener()
          Returns the selection listener that will be notified.
 org.restlet.engine.io.WakeupListener getWakeupListener()
          Returns the wakeup listener that will be notified.
 boolean isCanceling()
          Indicates if a canceling of the registration has been requested.
 boolean isConnectable()
          Indicates if the NIO channel is connectable.
 boolean isInterestReady()
          Indicates if the operations of interest are ready.
 boolean isReadable()
          Indicates if the NIO channel is readable.
 boolean isWritable()
          Indicates if the NIO channel is writable.
 void onSelected(int readyOperations)
          Called back with some interest operations are ready.
 SelectionKey register(Selector selector)
          Effectively registers the getSelectableChannel() with the given Selector for the getInterestOperations() operations.
 void resume()
          Resume interest in new listener notifications.
 void setCanceling(boolean canceling)
          Sets interest in canceling the registration.
 boolean setInterestOperations(int interest)
          Sets the IO operations interest.
 void setNoInterest()
          Sets interest in no IO operations.
 void setReadInterest()
          Sets interest in IO read operations.
 void setReadyOperations(int readyOperations)
          Sets the IO operations ready.
 void setSelectionListener(SelectionListener listener)
          Sets the selection listener that will be notified.
 void setWakeupListener(org.restlet.engine.io.WakeupListener wakeupListener)
          Sets the wakeup listener that will be notified.
 void setWriteInterest()
          Sets interest in IO read operations.
 void suspend()
          Suspend interest in new listener notifications.
 String toString()
           
 void unblock()
          Unblocks the optionally blocked thread.
 SelectionKey update()
          Effectively updates the registration of the getSelectableChannel() with the given Selector for the getInterestOperations() operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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(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 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 IOException
Blocks the calling thread.

Throws:
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 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 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:
IOException

register

public SelectionKey register(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 String toString()
Overrides:
toString in class Object

unblock

public void unblock()
             throws IOException
Unblocks the optionally blocked thread.

Throws:
IOException
See Also:
block()

update

public 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.


Copyright © 2005-2013 Restlet.