APIdia Launch Partner
Top Description Fields Constructors Methods
sun.nio.ch

pack-priv Class PollSelectorImpl

extends SelectorImpl
Class Inheritance
Imports
java.io.IOException, java.nio.channels.ClosedSelectorException, .SelectionKey, .Selector, java.nio.channels.spi.SelectorProvider, java.util.ArrayDeque, .ArrayList, .Deque, .List, java.util.concurrent.TimeUnit, java.util.function.Consumer, jdk.internal.misc.Blocker, .Unsafe

Selector implementation based on poll

Field Summary

Modifier and TypeField and Description
private static final short
private final int
private final int
private static final short
private static final int
private final Object
private boolean
private AllocatedNativeObject
private int
private int
private final List<SelectionKeyImpl>
private static final short
private static final short
private final Deque<SelectionKeyImpl>
private final Object

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
add(SelectionKeyImpl ski, int ops)

Adds a pollfd entry to the poll array, expanding the poll array if needed.

private void
protected int
doSelect(Consumer<SelectionKey> action, long timeout)

Implements abstract sun.nio.ch.SelectorImpl.doSelect.

Selects the keys for channels that are ready for I/O operations.

private void
private void
expandIfNeeded()

Expand poll array if at capacity

private int
private int
getEventOps(int i)

private int
getReventOps(int i)

protected void
implClose()

Implements abstract sun.nio.ch.SelectorImpl.implClose.

Invoked by implCloseSelector to close the selector.

protected void
implDereg(SelectionKeyImpl ski)

Implements abstract sun.nio.ch.SelectorImpl.implDereg.

Removes the key from the selector

protected void
implRegister(SelectionKeyImpl ski)

Overrides sun.nio.ch.SelectorImpl.implRegister.

Register the key in the selector.

private static native int
poll(long pollAddress, int numfds, int timeout)

private int
processEvents(Consumer<SelectionKey> action)

Process the polled events.

private void
processUpdateQueue()

Process changes to the interest ops.

private void
putDescriptor(int i, int fd)

private void
putEventOps(int i, int event)

private void
putReventOps(int i, int revent)

private void
remove(SelectionKeyImpl ski)

Removes a pollfd entry from the poll array

public void
setEventOps(SelectionKeyImpl ski)

Implements abstract sun.nio.ch.SelectorImpl.setEventOps.

Invoked by interestOps to ensure the interest ops are updated at the next selection operation.

private void
setFirst(int fd, int ops)

Sets the first pollfd entry in the poll array to the given fd

private void
update(SelectionKeyImpl ski, int ops)

Update the events of pollfd entry.

public Selector
wakeup()

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

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

Inherited from sun.nio.ch.SelectorImpl:
begincancelendimplCloseSelectorkeysprocessDeregisterQueueprocessReadyEventsregisterselectselectselectselectselectedKeysselectNowselectNow

Field Detail

EVENT_OFFSETback to summary
private static final short EVENT_OFFSET
fd0back to summary
private final int fd0
fd1back to summary
private final int fd1
FD_OFFSETback to summary
private static final short FD_OFFSET
INITIAL_CAPACITYback to summary
private static final int INITIAL_CAPACITY
interruptLockback to summary
private final Object interruptLock
interruptTriggeredback to summary
private boolean interruptTriggered
pollArrayback to summary
private AllocatedNativeObject pollArray
pollArrayCapacityback to summary
private int pollArrayCapacity
pollArraySizeback to summary
private int pollArraySize
pollKeysback to summary
private final List<SelectionKeyImpl> pollKeys
REVENT_OFFSETback to summary
private static final short REVENT_OFFSET
SIZE_POLLFDback to summary
private static final short SIZE_POLLFD
updateKeysback to summary
private final Deque<SelectionKeyImpl> updateKeys
updateLockback to summary
private final Object updateLock

Constructor Detail

PollSelectorImplback to summary
pack-priv PollSelectorImpl(SelectorProvider sp) throws IOException

Method Detail

addback to summary
private void add(SelectionKeyImpl ski, int ops)

Adds a pollfd entry to the poll array, expanding the poll array if needed.

clearInterruptback to summary
private void clearInterrupt() throws IOException
doSelectback to summary
protected int doSelect(Consumer<SelectionKey> action, long timeout) throws IOException

Implements abstract sun.nio.ch.SelectorImpl.doSelect.

Doc from sun.nio.ch.SelectorImpl.doSelect.

Selects the keys for channels that are ready for I/O operations.

Annotations
@Override
ensureOpenback to summary
private void ensureOpen()

Hides sun.nio.ch.SelectorImpl.ensureOpen.

expandIfNeededback to summary
private void expandIfNeeded()

Expand poll array if at capacity

getDescriptorback to summary
private int getDescriptor(int i)
getEventOpsback to summary
private int getEventOps(int i)
getReventOpsback to summary
private int getReventOps(int i)
implCloseback to summary
protected void implClose() throws IOException

Implements abstract sun.nio.ch.SelectorImpl.implClose.

Doc from sun.nio.ch.SelectorImpl.implClose.

Invoked by implCloseSelector to close the selector.

Annotations
@Override
implDeregback to summary
protected void implDereg(SelectionKeyImpl ski) throws IOException

Implements abstract sun.nio.ch.SelectorImpl.implDereg.

Doc from sun.nio.ch.SelectorImpl.implDereg.

Removes the key from the selector

Annotations
@Override
implRegisterback to summary
protected void implRegister(SelectionKeyImpl ski)

Overrides sun.nio.ch.SelectorImpl.implRegister.

Doc from sun.nio.ch.SelectorImpl.implRegister.

Register the key in the selector. The default implementation checks if the selector is open. It should be overridden by selector implementations as needed.

Annotations
@Override
pollback to summary
private static native int poll(long pollAddress, int numfds, int timeout)
processEventsback to summary
private int processEvents(Consumer<SelectionKey> action) throws IOException

Process the polled events. If the interrupt fd has been selected, drain it and clear the interrupt.

processUpdateQueueback to summary
private void processUpdateQueue()

Process changes to the interest ops.

putDescriptorback to summary
private void putDescriptor(int i, int fd)
putEventOpsback to summary
private void putEventOps(int i, int event)
putReventOpsback to summary
private void putReventOps(int i, int revent)
removeback to summary
private void remove(SelectionKeyImpl ski)

Removes a pollfd entry from the poll array

setEventOpsback to summary
public void setEventOps(SelectionKeyImpl ski)

Implements abstract sun.nio.ch.SelectorImpl.setEventOps.

Doc from sun.nio.ch.SelectorImpl.setEventOps.

Invoked by interestOps to ensure the interest ops are updated at the next selection operation.

Annotations
@Override
setFirstback to summary
private void setFirst(int fd, int ops)

Sets the first pollfd entry in the poll array to the given fd

updateback to summary
private void update(SelectionKeyImpl ski, int ops)

Update the events of pollfd entry.

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.

Annotations
@Override