Class Reactor
java.lang.Object
com.codename1.backend.Reactor
Readiness notification over epoll (Linux) or kqueue (macOS/BSD).
Level-triggered: the poller hands a ready descriptor to a worker and forgets about it until the worker gives it back. Edge-triggered would require draining every descriptor to EAGAIN on each wake-up, which is the opposite of that.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeliver an event for this descriptor ONCE and then disarm it, untilmodify(int, int)re-arms it.static final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int fd, int events) intawait(int[] readyFds, int timeoutMillis) Blocks until something is ready, then fills readyFds and returns how many.voidclose()static Reactorcreate()static int[]A non-blocking pipe,{readEnd, writeEnd}, for waking a thread that polls: register the read end, andwake(int)the write end from any thread.static voiddrainWake(int readFd) Empties the pipe once its poller has woken.voidmodify(int fd, int events) voidremove(int fd) static voidwake(int writeFd) Wakes whoever polls the pipe's read end.
-
Field Details
-
READ
public static final int READ- See Also:
-
WRITE
public static final int WRITE- See Also:
-
ONESHOT
public static final int ONESHOTDeliver an event for this descriptor ONCE and then disarm it, until
modify(int, int)re-arms it.This is what lets the worker threads poll the same set directly rather than a reactor thread dispatching to them: the kernel guarantees exactly one waiter is handed a given descriptor, so two workers cannot land on one connection. Without it a level-triggered set reports the same descriptor ready to every waiter at once.
- See Also:
-
-
Method Details
-
create
- Throws:
IOException
-
add
- Throws:
IOException
-
modify
- Throws:
IOException
-
remove
public void remove(int fd) -
await
Blocks until something is ready, then fills readyFds and returns how many. A timeout below zero waits forever.- Throws:
IOException
-
close
public void close() -
createWakePipe
public static int[] createWakePipe()A non-blocking pipe,{readEnd, writeEnd}, for waking a thread that polls: register the read end, andwake(int)the write end from any thread. Null where there is none (Windows, which has no virtual threads to wake either). -
wake
public static void wake(int writeFd) Wakes whoever polls the pipe's read end. Safe from any thread. -
drainWake
public static void drainWake(int readFd) Empties the pipe once its poller has woken.
-