Top Description Inners Fields Constructors Methods
jnr.enxio.channels

pack-priv Class KQSelector

extends AbstractSelector
Class Inheritance
Imports
jnr.constants.platform.Errno, jnr.ffi.Memory, .Pointer, .StructLayout, .TypeAlias, .Platform, jnr.ffi.provider.jffi.NativeRuntime, java.io.IOException, java.nio.channels.SelectionKey, .Selector, java.nio.channels.spi.AbstractSelectableChannel, java.util.*, java.util.concurrent.ConcurrentHashMap, .TimeUnit

An implementation of a java.nio.channels.Selector that uses the BSD (including MacOS) kqueue(2) mechanism

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private abstract static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final Pointer
private static final boolean
private final Map<Integer, KQSelector.Descriptor>
private static final int
private static final int
private static final int
private static final int
private static final int
private final Pointer
private static final int
private static final int
private final KQSelector.EventIO
private int
private static final int
private final int[]
private final Object
private final Runtime
private final Set<SelectionKey>
private final Native.Timespec

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private int
private void
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)

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.
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

changebufback to summary
private final Pointer changebuf
DEBUGback to summary
private static final boolean DEBUG
descriptorsback to summary
private final Map<Integer, KQSelector.Descriptor> descriptors
EV_ADDback to summary
private static final int EV_ADD
EV_CLEARback to summary
private static final int EV_CLEAR
EV_DELETEback to summary
private static final int EV_DELETE
EV_DISABLEback to summary
private static final int EV_DISABLE
EV_ENABLEback to summary
private static final int EV_ENABLE
eventbufback to summary
private final Pointer eventbuf
EVFILT_READback to summary
private static final int EVFILT_READ
EVFILT_WRITEback to summary
private static final int EVFILT_WRITE
ioback to summary
private final KQSelector.EventIO io
kqfdback to summary
private int kqfd
MAX_EVENTSback to summary
private static final int MAX_EVENTS
pipefdback to summary
private final int[] pipefd
regLockback to summary
private final Object regLock
runtimeback to summary
private final Runtime runtime
selectedback to summary
private final Set<SelectionKey> selected
ZERO_TIMESPECback to summary
private final Native.Timespec ZERO_TIMESPEC

Constructor Detail

KQSelectorback to summary
public KQSelector(NativeSelectorProvider provider)

Method Detail

handleCancelledKeysback to summary
private int handleCancelledKeys()
handleChangedKeyback to summary
private void handleChangedKey(KQSelector.Descriptor changed)
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(KQSelectionKey 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)
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
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()
jnr.enxio.channels back to summary

private Class KQSelector.Descriptor

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
private final Set<KQSelectionKey>
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
Descriptor(int fd)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fdback to summary
private final int fd
keysback to summary
private final Set<KQSelectionKey> keys
readback to summary
private boolean read
writeback to summary
private boolean write

Constructor Detail

Descriptorback to summary
public Descriptor(int fd)
jnr.enxio.channels back to summary

private final Class KQSelector.EventIO

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final KQSelector.EventIO
private final KQSelector.EventLayout
private final Type

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv int
getFD(Pointer ptr, int index)

public final int
getFilter(Pointer buf, int index)

public static KQSelector.EventIO
public final void
put(Pointer buf, int index, int fd, int filt, int flags)

public final void
putFilter(Pointer buf, int index, int filter)

public final void
putFlags(Pointer buf, int index, int flags)

public final int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final KQSelector.EventIO INSTANCE
layoutback to summary
private final KQSelector.EventLayout layout
uintptr_tback to summary
private final Type uintptr_t

Constructor Detail

EventIOback to summary
private EventIO()

Method Detail

getFDback to summary
pack-priv int getFD(Pointer ptr, int index)
getFilterback to summary
public final int getFilter(Pointer buf, int index)
getInstanceback to summary
public static KQSelector.EventIO getInstance()
putback to summary
public final void put(Pointer buf, int index, int fd, int filt, int flags)
putFilterback to summary
public final void putFilter(Pointer buf, int index, int filter)
putFlagsback to summary
public final void putFlags(Pointer buf, int index, int flags)
sizeback to summary
public final int size()
jnr.enxio.channels back to summary

private abstract Class KQSelector.EventLayout

extends StructLayout
Class Inheritance
Known Direct Subclasses
jnr.enxio.channels.KQSelector.LegacyEventLayout, jnr.enxio.channels.KQSelector.FreeBSD12EventLayout

Field Summary

Modifier and TypeField and Description
public final StructLayout.u_int32_t
public final StructLayout.int16_t
public final StructLayout.u_int16_t
public final StructLayout.uintptr_t

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from jnr.ffi.StructLayout:
addFieldaddFieldaddFieldaddFieldalignmentarrayarrayBeginarrayEndatfunctionfunctiongetNativeTypegetRuntimeinneroffsetsizetoString

Field Detail

fflagsback to summary
public final StructLayout.u_int32_t fflags
filterback to summary
public final StructLayout.int16_t filter
flagsback to summary
public final StructLayout.u_int16_t flags
identback to summary
public final StructLayout.uintptr_t ident

Constructor Detail

EventLayoutback to summary
private EventLayout(Runtime runtime)
jnr.enxio.channels back to summary

private Class KQSelector.FreeBSD12EventLayout

extends EventLayout
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final StructLayout.int64_t
public final StructLayout.u_int64_t[]
public final StructLayout.Pointer
Inherited from jnr.enxio.channels.KQSelector.EventLayout:
fflagsfilterflagsident

Constructor Summary

AccessConstructor and Description
private

Field Detail

databack to summary
public final StructLayout.int64_t data
extback to summary
public final StructLayout.u_int64_t[] ext
udataback to summary
public final StructLayout.Pointer udata

Constructor Detail

FreeBSD12EventLayoutback to summary
private FreeBSD12EventLayout(Runtime runtime)
jnr.enxio.channels back to summary

private Class KQSelector.LegacyEventLayout

extends EventLayout
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final StructLayout.intptr_t
public final StructLayout.Pointer
Inherited from jnr.enxio.channels.KQSelector.EventLayout:
fflagsfilterflagsident

Constructor Summary

AccessConstructor and Description
private

Field Detail

databack to summary
public final StructLayout.intptr_t data
udataback to summary
public final StructLayout.Pointer udata

Constructor Detail

LegacyEventLayoutback to summary
private LegacyEventLayout(Runtime runtime)