KQueueIoHandler Class — netty Architecture
Architecture documentation for the KQueueIoHandler class in KQueueIoHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 75a3ba71_0590_fec0_e352_8a91c916c5af["KQueueIoHandler"] 9eae14e2_0d94_eb0d_11d0_56314543bdff["KQueueIoHandler.java"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|defined in| 9eae14e2_0d94_eb0d_11d0_56314543bdff 1e534e9f_8b22_00aa_747f_67b7cb133621["generateNextId()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 1e534e9f_8b22_00aa_747f_67b7cb133621 e76a479d_e4dc_86c7_5b16_190a25a43e9a["IoHandlerFactory()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| e76a479d_e4dc_86c7_5b16_190a25a43e9a 341642d9_c89a_70ac_148e_ccaf2c44d4af["KQueueIoHandler()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 341642d9_c89a_70ac_148e_ccaf2c44d4af 22d22a93_4930_1c25_d832_877e2ee987af["wakeup()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 22d22a93_4930_1c25_d832_877e2ee987af 8470ab15_e624_678a_adf0_3cfeeb5354c6["wakeup0()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 8470ab15_e624_678a_adf0_3cfeeb5354c6 bcc78562_0103_1a86_1771_83c771b0359c["kqueueWait()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| bcc78562_0103_1a86_1771_83c771b0359c ca6401ff_3419_7724_1b24_ecfcdf566e0b["kqueueWaitNow()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| ca6401ff_3419_7724_1b24_ecfcdf566e0b 7640e0e3_85f5_efbd_4f2c_d9c5ed5c87a0["processReady()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 7640e0e3_85f5_efbd_4f2c_d9c5ed5c87a0 fa6e02de_7726_4944_12b6_ecd3e40bbdcb["run()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| fa6e02de_7726_4944_12b6_ecd3e40bbdcb 87233553_29d8_ea69_ab7a_ba11b941aba3["processCancelledRegistrations()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 87233553_29d8_ea69_ab7a_ba11b941aba3 44b232a5_58da_6028_3b56_d62005405bbc["numRegisteredChannels()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 44b232a5_58da_6028_3b56_d62005405bbc 765598fe_6b13_b92a_330b_2477642539ca["registeredChannelsList()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 765598fe_6b13_b92a_330b_2477642539ca 9096967a_5239_54dc_5c93_bfaffd5857cb["handleLoopException()"] 75a3ba71_0590_fec0_e352_8a91c916c5af -->|method| 9096967a_5239_54dc_5c93_bfaffd5857cb
Relationship Graph
Source Code
transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueIoHandler.java lines 52–518
public final class KQueueIoHandler implements IoHandler {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(KQueueIoHandler.class);
private static final AtomicIntegerFieldUpdater<KQueueIoHandler> WAKEN_UP_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(KQueueIoHandler.class, "wakenUp");
private static final int KQUEUE_WAKE_UP_IDENT = 0;
// `kqueue()` may return EINVAL when a large number such as Integer.MAX_VALUE is specified as timeout.
// 24 hours would be a large enough value.
// https://man.freebsd.org/cgi/man.cgi?query=kevent&apropos=0&sektion=0&manpath=FreeBSD+6.1-RELEASE&format=html#end
private static final int KQUEUE_MAX_TIMEOUT_SECONDS = 86399; // 24 hours - 1 second
{
KQueue.ensureAvailability();
}
private final boolean allowGrowing;
private final FileDescriptor kqueueFd;
private final KQueueEventArray changeList;
private final KQueueEventArray eventList;
private final SelectStrategy selectStrategy;
private final NativeArrays nativeArrays;
private final IntSupplier selectNowSupplier = new IntSupplier() {
@Override
public int get() throws Exception {
return kqueueWaitNow();
}
};
private final ThreadAwareExecutor executor;
private final Queue<DefaultKqueueIoRegistration> cancelledRegistrations = new ArrayDeque<>();
private final LongObjectMap<DefaultKqueueIoRegistration> registrations = new LongObjectHashMap<>(4096);
private int numChannels;
private long nextId;
private volatile int wakenUp;
private long generateNextId() {
boolean reset = false;
for (;;) {
if (nextId == Long.MAX_VALUE) {
if (reset) {
throw new IllegalStateException("All possible ids in use");
}
reset = true;
}
nextId++;
if (nextId == KQUEUE_WAKE_UP_IDENT) {
continue;
}
if (!registrations.containsKey(nextId)) {
return nextId;
}
}
}
/**
* Returns a new {@link IoHandlerFactory} that creates {@link KQueueIoHandler} instances.
*/
public static IoHandlerFactory newFactory() {
return newFactory(0, DefaultSelectStrategyFactory.INSTANCE);
}
/**
* Returns a new {@link IoHandlerFactory} that creates {@link KQueueIoHandler} instances.
*/
public static IoHandlerFactory newFactory(final int maxEvents,
final SelectStrategyFactory selectStrategyFactory) {
KQueue.ensureAvailability();
ObjectUtil.checkPositiveOrZero(maxEvents, "maxEvents");
ObjectUtil.checkNotNull(selectStrategyFactory, "selectStrategyFactory");
return new IoHandlerFactory() {
@Override
public IoHandler newHandler(ThreadAwareExecutor executor) {
return new KQueueIoHandler(executor, maxEvents, selectStrategyFactory.newSelectStrategy());
}
@Override
public boolean isChangingThreadSupported() {
return true;
}
};
}
Source
Frequently Asked Questions
What is the KQueueIoHandler class?
KQueueIoHandler is a class in the netty codebase, defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueIoHandler.java.
Where is KQueueIoHandler defined?
KQueueIoHandler is defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueIoHandler.java at line 52.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free