Package org.restlet.util
Class SelectionRegistration
- java.lang.Object
 - 
- org.restlet.util.SelectionRegistration
 
 
- 
public class SelectionRegistration extends java.lang.ObjectRepresents a unique registration between a NIO selector and a selectable channel. For the operation codes, see the constants inSelectionKey.- Author:
 - Jerome Louvel
 - See Also:
 SelectionKey
 
- 
- 
Constructor Summary
Constructors Constructor Description SelectionRegistration(int interestOperations, SelectionListener selectionListener, org.restlet.engine.io.WakeupListener wakeupListener)Constructor.SelectionRegistration(java.nio.channels.SelectableChannel selectableChannel, int interestOperations, SelectionListener selectionListener, org.restlet.engine.io.WakeupListener wakeupListener)Constructor. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInterestOperations(int interest)Adds a given operations to the current list.voidblock()Blocks the calling thread.voidclear()Clears the registration.intgetInterestOperations()Returns the IO operations interest.static java.lang.StringgetName(int operation)Returns the name of the given IO operation.intgetReadyOperations()Returns the IO operations ready.java.nio.channels.SelectableChannelgetSelectableChannel()Returns the parent selectable channel.SelectionListenergetSelectionListener()Returns the selection listener that will be notified.org.restlet.engine.io.WakeupListenergetWakeupListener()Returns the wakeup listener that will be notified.booleanisCanceling()Indicates if a canceling of the registration has been requested.booleanisConnectable()Indicates if the NIO channel is connectable.booleanisInterestReady()Indicates if the operations of interest are ready.booleanisReadable()Indicates if the NIO channel is readable.booleanisWritable()Indicates if the NIO channel is writable.voidonSelected(int readyOperations)Called back with some interest operations are ready.java.nio.channels.SelectionKeyregister(java.nio.channels.Selector selector)Effectively registers thegetSelectableChannel()with the givenSelectorfor thegetInterestOperations()operations.voidresume()Resume interest in new listener notifications.voidsetCanceling(boolean canceling)Sets interest in canceling the registration.booleansetInterestOperations(int interest)Sets the IO operations interest.voidsetNoInterest()Sets interest in no IO operations.voidsetReadInterest()Sets interest in IO read operations.voidsetReadyOperations(int readyOperations)Sets the IO operations ready.voidsetSelectionListener(SelectionListener listener)Sets the selection listener that will be notified.voidsetWakeupListener(org.restlet.engine.io.WakeupListener wakeupListener)Sets the wakeup listener that will be notified.voidsetWriteInterest()Sets interest in IO read operations.voidsuspend()Suspend interest in new listener notifications.java.lang.StringtoString()voidunblock()Unblocks the optionally blocked thread.java.nio.channels.SelectionKeyupdate()Effectively updates the registration of thegetSelectableChannel()with the givenSelectorfor thegetInterestOperations()operations. 
 - 
 
- 
- 
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.IOExceptionBlocks 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.IOExceptionCalled back with some interest operations are ready. By default, it calls back the registered listener provided bygetSelectionListener().- Parameters:
 readyOperations- The ready operations.- Throws:
 java.io.IOException
 
- 
register
public java.nio.channels.SelectionKey register(java.nio.channels.Selector selector)
Effectively registers thegetSelectableChannel()with the givenSelectorfor thegetInterestOperations()operations.- Parameters:
 selector- The NIO selector to register to.
 
- 
resume
public void resume()
Resume interest in new listener notifications. This should be called after asuspend()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 callssetInterestOperations(int)with a 0 value. 
- 
toString
public java.lang.String toString()
- Overrides:
 toStringin classjava.lang.Object
 
- 
unblock
public void unblock() throws java.io.IOExceptionUnblocks the optionally blocked thread.- Throws:
 java.io.IOException- See Also:
 block()
 
- 
update
public java.nio.channels.SelectionKey update()
Effectively updates the registration of thegetSelectableChannel()with the givenSelectorfor thegetInterestOperations()operations.- Returns:
 - The updated selection key or a new one if it was registered again.
 
 
 - 
 
 -