Package com.biglybt.core.networkmanager
Class VirtualChannelSelector
- java.lang.Object
-
- com.biglybt.core.networkmanager.VirtualChannelSelector
-
public class VirtualChannelSelector extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
VirtualChannelSelector.VirtualAbstractSelectorListener
static interface
VirtualChannelSelector.VirtualAcceptSelectorListener
static interface
VirtualChannelSelector.VirtualSelectorListener
Listener for notification upon socket channel selection.
-
Field Summary
Fields Modifier and Type Field Description private boolean
destroyed
private java.lang.String
name
private int
op
static int
OP_ACCEPT
static int
OP_CONNECT
static int
OP_READ
static int
OP_WRITE
private boolean
randomise_keys
private VirtualChannelSelectorImpl
selector_impl
-
Constructor Summary
Constructors Constructor Description VirtualChannelSelector(java.lang.String name, int interest_op, boolean pause_after_select)
Create a new virtual selectable-channel selector, selecting over the given interest-op.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel(java.nio.channels.spi.AbstractSelectableChannel channel)
Cancel the selection operations for the given channel.void
destroy()
java.lang.String
getName()
boolean
isDestroyed()
boolean
isPaused(java.nio.channels.spi.AbstractSelectableChannel channel)
boolean
isRegistered(java.nio.channels.spi.AbstractSelectableChannel channel)
void
pauseSelects(java.nio.channels.spi.AbstractSelectableChannel channel)
Pause selection operations for the given channelvoid
register(java.nio.channels.ServerSocketChannel channel, VirtualChannelSelector.VirtualAcceptSelectorListener listener, java.lang.Object attachment)
void
register(java.nio.channels.SocketChannel channel, VirtualChannelSelector.VirtualSelectorListener listener, java.lang.Object attachment)
protected void
registerSupport(java.nio.channels.spi.AbstractSelectableChannel channel, VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.lang.Object attachment)
Register the given selectable channel, using the given listener for notification of completed select operations.void
resumeSelects(java.nio.channels.spi.AbstractSelectableChannel channel)
Resume selection operations for the given channelint
select(long timeout)
Run a virtual select() operation, with the given selection timeout value; (1) cancellations are processed (2) the select operation is performed; (3) listener notification of completed selects (4) new registrations are processedvoid
selectFailure(VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.nio.channels.spi.AbstractSelectableChannel sc, java.lang.Object attachment, java.lang.Throwable msg)
boolean
selectSuccess(VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.nio.channels.spi.AbstractSelectableChannel sc, java.lang.Object attachment)
void
setRandomiseKeys(boolean _rk)
-
-
-
Field Detail
-
OP_ACCEPT
public static final int OP_ACCEPT
- See Also:
- Constant Field Values
-
OP_CONNECT
public static final int OP_CONNECT
- See Also:
- Constant Field Values
-
OP_READ
public static final int OP_READ
- See Also:
- Constant Field Values
-
OP_WRITE
public static final int OP_WRITE
- See Also:
- Constant Field Values
-
name
private final java.lang.String name
-
selector_impl
private final VirtualChannelSelectorImpl selector_impl
-
destroyed
private volatile boolean destroyed
-
op
private final int op
-
randomise_keys
private boolean randomise_keys
-
-
Constructor Detail
-
VirtualChannelSelector
public VirtualChannelSelector(java.lang.String name, int interest_op, boolean pause_after_select)
Create a new virtual selectable-channel selector, selecting over the given interest-op.- Parameters:
interest_op
- operation set of OP_CONNECT, OP_ACCEPT, OP_READ, or OP_WRITEpause_after_select
- whether or not to auto-disable interest op after select
-
-
Method Detail
-
getName
public java.lang.String getName()
-
register
public void register(java.nio.channels.SocketChannel channel, VirtualChannelSelector.VirtualSelectorListener listener, java.lang.Object attachment)
-
register
public void register(java.nio.channels.ServerSocketChannel channel, VirtualChannelSelector.VirtualAcceptSelectorListener listener, java.lang.Object attachment)
-
registerSupport
protected void registerSupport(java.nio.channels.spi.AbstractSelectableChannel channel, VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.lang.Object attachment)
Register the given selectable channel, using the given listener for notification of completed select operations. NOTE: For OP_CONNECT and OP_WRITE -type selectors, once a selection request op completes, the channel's op registration is automatically disabled (paused); any future wanted selection notification requires re-enabling via resume. For OP_READ selectors, it stays enabled until actively paused, no matter how many times it is selected.- Parameters:
channel
- socket to listen forlistener
- op-complete listenerattachment
- object to be passed back with listener notification
-
isPaused
public boolean isPaused(java.nio.channels.spi.AbstractSelectableChannel channel)
-
pauseSelects
public void pauseSelects(java.nio.channels.spi.AbstractSelectableChannel channel)
Pause selection operations for the given channel- Parameters:
channel
- to pause
-
resumeSelects
public void resumeSelects(java.nio.channels.spi.AbstractSelectableChannel channel)
Resume selection operations for the given channel- Parameters:
channel
- to resume
-
isRegistered
public boolean isRegistered(java.nio.channels.spi.AbstractSelectableChannel channel)
-
cancel
public void cancel(java.nio.channels.spi.AbstractSelectableChannel channel)
Cancel the selection operations for the given channel.- Parameters:
channel
- channel originally registered
-
setRandomiseKeys
public void setRandomiseKeys(boolean _rk)
-
select
public int select(long timeout)
Run a virtual select() operation, with the given selection timeout value; (1) cancellations are processed (2) the select operation is performed; (3) listener notification of completed selects (4) new registrations are processed- Parameters:
timeout
- in ms; if zero, block indefinitely- Returns:
- number of sockets selected
-
destroy
public void destroy()
-
isDestroyed
public boolean isDestroyed()
-
selectSuccess
public boolean selectSuccess(VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.nio.channels.spi.AbstractSelectableChannel sc, java.lang.Object attachment)
-
selectFailure
public void selectFailure(VirtualChannelSelector.VirtualAbstractSelectorListener listener, java.nio.channels.spi.AbstractSelectableChannel sc, java.lang.Object attachment, java.lang.Throwable msg)
-
-