Top Description Fields Constructors Methods
jnr.enxio.channels

pack-priv Class PollSelector

extends AbstractSelector
Class Inheritance
Imports
jnr.constants.platform.Errno, java.io.IOException, java.nio.ByteBuffer, .ByteOrder, java.nio.channels.SelectionKey, .Selector, java.nio.channels.spi.AbstractSelectableChannel, .SelectorProvider, java.util.*, java.util.concurrent.ConcurrentHashMap

An implementation of a java.nio.channels.Selector that uses good old poll(2)

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private PollSelectionKey[]
private final Map<SelectionKey, Boolean>
private int
private final int[]
private ByteBuffer
pack-priv static final int
private static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private final Object
private static final int
private final Set<SelectionKey>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private short
getPollEvents(int idx)

private int
getPollFD(int idx)

private short
getPollRevents(int idx)

protected void
pack-priv void
public Set<SelectionKey>
keys()

Implements abstract java.nio.channels.Selector.keys.

Returns this selector's key set.
private int
poll(long timeout)

private void
putPollEvents(int idx, int events)

private void
putPollFD(int idx, int fd)

private void
putPollRevents(int idx, int events)

protected SelectionKey
register(AbstractSelectableChannel
The channel to be registered
ch
,
int
The initial interest set, which must be valid
ops
,
Object
The initial attachment for the resulting key
att
)

Implements abstract java.nio.channels.spi.AbstractSelector.register.

Registers the given channel with this selector.
private void
public int
select(long
If positive, block for up to timeout milliseconds, more or less, while waiting for a channel to become ready; if zero, block indefinitely; must not be negative
timeout
)

Implements abstract java.nio.channels.Selector.select.

Selects a set of keys whose corresponding channels are ready for I/O operations.
public int
select()

Implements abstract java.nio.channels.Selector.select.

Selects a set of keys whose corresponding channels are ready for I/O operations.
public Set<SelectionKey>
selectedKeys()

Implements abstract java.nio.channels.Selector.selectedKeys.

Returns this selector's selected-key set.
public int
selectNow()

Implements abstract java.nio.channels.Selector.selectNow.

Selects a set of keys whose corresponding channels are ready for I/O operations.
public Selector
wakeup()

Implements abstract java.nio.channels.Selector.wakeup.

Causes the first selection operation that has not yet returned to return immediately.
private void
Inherited from java.nio.channels.spi.AbstractSelector:
begincancelledKeysclosederegisterendisOpenprovider

Field Detail

EVENTS_OFFSETback to summary
private static final int EVENTS_OFFSET
FD_OFFSETback to summary
private static final int FD_OFFSET
keyArrayback to summary
private PollSelectionKey[] keyArray
keysback to summary
private final Map<SelectionKey, Boolean> keys
nfdsback to summary
private int nfds
pipefdback to summary
private final int[] pipefd
pollDataback to summary
private ByteBuffer pollData
POLLERRback to summary
pack-priv static final int POLLERR
POLLFD_SIZEback to summary
private static final int POLLFD_SIZE
POLLHUPback to summary
pack-priv static final int POLLHUP
POLLINback to summary
pack-priv static final int POLLIN
POLLOUTback to summary
pack-priv static final int POLLOUT
regLockback to summary
private final Object regLock
REVENTS_OFFSETback to summary
private static final int REVENTS_OFFSET
selectedback to summary
private final Set<SelectionKey> selected

Constructor Detail

PollSelectorback to summary
public PollSelector(SelectorProvider provider)

Method Detail

addback to summary
private void add(PollSelectionKey k)
getPollEventsback to summary
private short getPollEvents(int idx)
getPollFDback to summary
private int getPollFD(int idx)
getPollReventsback to summary
private short getPollRevents(int idx)
implCloseSelectorback to summary
protected void implCloseSelector() throws IOException

Implements abstract java.nio.channels.spi.AbstractSelector.implCloseSelector.

Doc from java.nio.channels.spi.AbstractSelector.implCloseSelector.

Closes this selector.

This method is invoked by the close method in order to perform the actual work of closing the selector. This method is only invoked if the selector has not yet been closed, and it is never invoked more than once.

An implementation of this method must arrange for any other thread that is blocked in a selection operation upon this selector to return immediately as if by invoking the wakeup method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while closing the selector
interestOpsback to summary
pack-priv void interestOps(PollSelectionKey k, int ops)
keysback to summary
public Set<SelectionKey> keys()

Implements abstract java.nio.channels.Selector.keys.

Doc from java.nio.channels.Selector.keys.

Returns this selector's key set.

The key set is not directly modifiable. A key is removed only after it has been cancelled and its channel has been deregistered. Any attempt to modify the key set will cause an UnsupportedOperationException to be thrown.

The set is safe for use by multiple concurrent threads.

Returns:Set<SelectionKey>

This selector's key set

Annotations
@Override
pollback to summary
private int poll(long timeout) throws IOException
putPollEventsback to summary
private void putPollEvents(int idx, int events)
putPollFDback to summary
private void putPollFD(int idx, int fd)
putPollReventsback to summary
private void putPollRevents(int idx, int events)
registerback to summary
protected SelectionKey register(AbstractSelectableChannel ch, int ops, Object att)

Implements abstract java.nio.channels.spi.AbstractSelector.register.

Doc from java.nio.channels.spi.AbstractSelector.register.

Registers the given channel with this selector.

This method is invoked by a channel's register method in order to perform the actual work of registering the channel with this selector.

Parameters
ch:AbstractSelectableChannel

The channel to be registered

ops:int

The initial interest set, which must be valid

att:Object

The initial attachment for the resulting key

Returns:SelectionKey

A new key representing the registration of the given channel with this selector

Annotations
@Override
removeback to summary
private void remove(PollSelectionKey k)
selectback to summary
public int select(long timeout) throws IOException

Implements abstract java.nio.channels.Selector.select.

Doc from java.nio.channels.Selector.select.

Selects a set of keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, the current thread is interrupted, or the given timeout period expires, whichever comes first.

This method does not offer real-time guarantees: It schedules the timeout as if by invoking the Object#wait(long) method.

Parameters
timeout:long

If positive, block for up to timeout milliseconds, more or less, while waiting for a channel to become ready; if zero, block indefinitely; must not be negative

Returns:int

The number of keys, possibly zero, whose ready-operation sets now indicate readiness for at least one category of operations for which the channel was not previously detected to be ready

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
selectback to summary
public int select() throws IOException

Implements abstract java.nio.channels.Selector.select.

Doc from java.nio.channels.Selector.select.

Selects a set of keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first.

Returns:int

The number of keys, possibly zero, whose ready-operation sets now indicate readiness for at least one category of operations for which the channel was not previously detected to be ready

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
selectedKeysback to summary
public Set<SelectionKey> selectedKeys()

Implements abstract java.nio.channels.Selector.selectedKeys.

Doc from java.nio.channels.Selector.selectedKeys.

Returns this selector's selected-key set.

Keys may be removed from, but not directly added to, the selected-key set. Any attempt to add an object to the key set will cause an UnsupportedOperationException to be thrown.

The selected-key set is not thread-safe.

Returns:Set<SelectionKey>

This selector's selected-key set

Annotations
@Override
selectNowback to summary
public int selectNow() throws IOException

Implements abstract java.nio.channels.Selector.selectNow.

Doc from java.nio.channels.Selector.selectNow.

Selects a set of keys whose corresponding channels are ready for I/O operations.

This method performs a non-blocking selection operation. If no channels have become selectable since the previous selection operation then this method immediately returns zero.

Invoking this method clears the effect of any previous invocations of the wakeup method.

Returns:int

The number of keys, possibly zero, whose ready-operation sets now indicate readiness for at least one category of operations for which the channel was not previously detected to be ready

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
wakeupback to summary
public Selector wakeup()

Implements abstract java.nio.channels.Selector.wakeup.

Doc from java.nio.channels.Selector.wakeup.

Causes the first selection operation that has not yet returned to return immediately.

If another thread is currently blocked in a selection operation then that invocation will return immediately. If no selection operation is currently in progress then the next invocation of a selection operation will return immediately unless selectNow() or selectNow(Consumer) is invoked in the meantime. In any case the value returned by that invocation may be non-zero. Subsequent selection operations will block as usual unless this method is invoked again in the meantime.

Invoking this method more than once between two successive selection operations has the same effect as invoking it just once.

Returns:Selector

This selector

Annotations
@Override
wakeupReceivedback to summary
private void wakeupReceived() throws IOException