booblik
Wiki

booblik-net

Generated page

Model gemma-mtp, commit f508a4b65b3f, 2026-08-15, sources: 6. Edit the code or the hand-written documentation instead.

Diagram

BooblikServer

The network front end and server lifecycle management. It manages the ServerSocketChannel and orchestrates the startup of either a selector-based or virtual-thread-based transport (BooblikServer.kt:117-147).

More: BooblikServer

Transport

Comparison between SELECTOR and VIRTUAL_THREADS readiness mechanisms.

TransportDescription
SELECTOROwn selector loop, one coroutine per connection (BooblikServer.kt:26-27)
VIRTUAL_THREADSBlocking sockets, one virtual thread per connection (BooblikServer.kt:30-33)

More: Transport

FetchMode

The ZERO_COPY and HEAP strategies for response delivery.

FetchModeDescription
ZERO_COPYsendfile: page cache to socket buffer, never through the JVM (BooblikServer.kt:39)
HEAPRead into a heap buffer and write it (BooblikServer.kt:42)

More: FetchMode

Connection

The abstraction layer for SelectorConnection and BlockingConnection. It defines how data is read, written, and transferred from segments to the socket (Connection.kt:23-53).

SelectorLoop

The NIO readiness engine and the mechanism for queuing interest changes. It uses a dedicated thread to process SelectionKey readiness and handles interest changes via a ConcurrentLinkedQueue to avoid blocking the selector (SelectorLoop.kt:31-40).

Broker

Management of partitions, retention policies, and the partition registry. It is responsible for opening partitions from a directory and applying retention policies (Broker.kt:49-81).

Metrics

Telemetry for network counters, session failures, and partition snapshots. It provides a snapshot function to capture the current state of the broker and its partitions (Metrics.kt:29-145).

Key files

FileLinesWhat is there
…/net/BooblikServer.kt45-64ServerConfig definition
…/net/BooblikServer.kt67-70PartitionHandle definition
…/net/BooblikServer.kt79-107PartitionRegistry definition
…/net/BooblikServer.kt117-121BooblikServer class declaration
…/nio/Connection.kt23-53Connection interface
…/nio/Connection.kt56-97SelectorConnection class
…/nio/Connection.kt108-142BlockingConnection class
…/nio/SelectorLoop.kt31-40SelectorLoop class
…/net/Broker.kt19-28BrokerConfig definition
…/net/Broker.kt49-54Broker class declaration
…/net/Metrics.kt29-48Metrics class declaration

Public API

WhatWhereWhy
ServerConfigBooblikServer.kt:45Configuration for the server transport and fetch modes.
PartitionHandleBooblikServer.kt:67Holds the log and writer for a specific partition.
PartitionRegistryBooblikServer.kt:79A registry to find partition handles by topic and ID.
BooblikServerBooblikServer.kt:117The main server entry point for starting and closing the broker.
ConnectionConnection.kt:23Abstraction for reading and writing to a client.
SelectorConnectionConnection.kt:56A non-blocking connection implementation using a SelectorLoop.
BlockingConnectionConnection.kt:108A blocking connection implementation for virtual threads.
SelectorLoopSelectorLoop.kt:31The engine that manages NIO readiness.
BrokerConfigBroker.kt:19Configuration for segmenting and retention in the broker.
BrokerBroker.kt:49The high-level broker managing partitions and retention.
MetricsMetrics.kt:29Provides telemetry and snapshots of broker activity.

Behaviour that surprises

  • SelectorLoop uses a ConcurrentLinkedQueue to post interest changes because modifying SelectionKey.interestOps from a thread other than the selector thread can be ineffective or block (SelectorLoop.kt:26-28).
  • BlockingConnection's transferFrom method may enter a tight loop if segment.transferTo returns zero, as it treats zero as "try again immediately" rather than waiting (Connection.kt:134).
  • BooblikServer uses a SupervisorJob for its scope so that a failure in a single client session does not crash the entire server (BooblikServer.kt:185-186).

On this page