Package org.restlet.util
Class SelectionRegistration
- java.lang.Object
-
- org.restlet.util.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 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 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 java.lang.String
getName(int operation)
Returns the name of the given IO operation.int
getReadyOperations()
Returns the IO operations ready.java.nio.channels.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.java.nio.channels.SelectionKey
register(java.nio.channels.Selector selector)
Effectively registers thegetSelectableChannel()
with the givenSelector
for thegetInterestOperations()
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.java.lang.String
toString()
void
unblock()
Unblocks the optionally blocked thread.java.nio.channels.SelectionKey
update()
Effectively updates the registration of thegetSelectableChannel()
with the givenSelector
for 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.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 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 givenSelector
for 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:
toString
in classjava.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 thegetSelectableChannel()
with the givenSelector
for thegetInterestOperations()
operations.- Returns:
- The updated selection key or a new one if it was registered again.
-
-