-
Notifications
You must be signed in to change notification settings - Fork 0
API
NAMAN JAIN edited this page Aug 3, 2026
·
1 revision
Because zThread is an event loop library, its API consists of Java interfaces rather than REST endpoints. This page outlines the core public interfaces developers use to interact with the runtime.
ZRuntime is the primary interface for starting the loop, posting events, and registering handlers.
- Purpose: Starts the background event loop thread.
-
Side effects: Spawns a new thread that will block in native code (
epoll_wait) until events occur.
- Purpose: Signals the event loop to stop processing and exit gracefully.
- Purpose: Registers a callback handler for a specific event class.
-
Parameters:
-
eventType: The class type of the event. -
handler: The consumer function to execute when the event is processed by the loop.
-
- Purpose: Inserts an event into the MPSC ring buffer and wakes up the event loop if it is sleeping.
-
Parameters:
-
event: The object to pass to the registered handler.
-
-
Return value:
trueif the event was successfully queued,falseif the buffer is full (or throws an exception depending on backpressure configuration).
-
Purpose: A non-blocking variant of
postthat returnsfalseimmediately if the ring buffer is at capacity, allowing the caller to handle backpressure without exceptions.
A fluent builder accessed via ZRuntime.builder().
-
threadName(String name): Sets the name of the background thread. -
bufferSize(int size): Sets the capacity of the MPSC ring buffer (must be a power of two). -
maxEventsPerPoll(int max): Configures how many eventsepoll_waitcan retrieve in a single wakeup. -
metricsEnabled(boolean enabled): Toggles internal JMX/micrometer metrics. -
build(): UsesServiceLoaderto locate thezthread-linuximplementation and returns a configuredZRuntime.
Provides integration with Project Reactor.
-
Purpose: Creates a reactive
Fluxthat emits items whenever the underlyingZRuntimeprocesses an event ofeventType.