Main execution lifecycle
Generated page
Model gemma-mtp, commit ef58254ca7be, 2026-08-16, sources: 6. Edit the code or the hand-written documentation instead.
Diagram
BooblikServer startup and transport selection
The server initialization begins by binding a ServerSocketChannel to the configured address and port BooblikServer.kt:134-140. Once bound, the server selects a transport mechanism based on the Transport enum BooblikServer.kt:25-34:
| Transport | Description |
|---|---|
SELECTOR | Uses a dedicated selector loop with one coroutine per connection. |
VIRTUAL_THREADS | Uses blocking sockets with one virtual thread per connection. |
The acceptor loop and connection handling
The acceptor mechanism differs by transport. In SELECTOR mode, a coroutine runs a loop that calls serverChannel.accept() BooblikServer.kt:164-175, where transient exceptions are caught and logged to metrics to prevent the loop from dying. In VIRTUAL_THREADS mode, a platform thread runs the acceptor loop BooblikServer.kt:204-224. To ensure that a single failing client session does not crash the entire server, BooblikServer uses a SupervisorJob BooblikServer.kt:123, which isolates failures to the specific coroutine scope of that session.
Session lifecycle and FetchMode execution
A Session is established when a connection is accepted and configured BooblikServer.kt:182. The FetchMode determines how data is transferred from the log to the client BooblikServer.kt:37-43:
| FetchMode | Mechanism |
|---|---|
ZERO_COPY | Uses transferTo to move data from the page cache directly to the socket. |
HEAP | Reads data into a heap buffer before writing. |
Graceful shutdown and the order of closure
The shutdown process is triggered by a JVM shutdown hook that ensures a specific sequence of closure to prevent data loss Main.kt:91-100. The order is strictly:
server.close()to stop accepting new connections.background.cancel()to stop background tasks like retention.broker.close()to ensure all writers finish flushing batches to disk before the underlying log is closed.
Smoke tests and distribution verification
The ci/smoke.sh script performs a full end-to-end verification of the distribution smoke.sh:30-34. It builds the installDist distribution, starts the broker, and uses a Python script to perform PRODUCE and FETCH operations over the wire. This verifies that the broker can recover its state from disk after a restart smoke.sh:130-142 and that the wire format (including CRC32C checksums) is correctly implemented.
Key files
| File | Lines | What is there |
|---|---|---|
…/app/Main.kt | 33-104 | The main entry point, orchestration of server/broker, and shutdown hooks. |
…/net/BooblikServer.kt | 117-260 | The network server implementation, transport selection, and session management. |
ci/smoke.sh | 30-144 | The smoke test script for distribution and protocol verification. |
Behaviour that surprising
- The
BooblikServeruses aSupervisorJobBooblikServer.kt:123specifically so that a client sending "nonsense" only kills its own session and not the entire server. - The
applyRetentionfunctionMain.kt:135is the only place that decides when retention happens, as theBrokeritself has no internal clock. - The
booblik.metrics.interval.millissettingMain.kt:118allows disabling metrics by setting it to0, which results in silent operation rather than an error.