Java NIO Systems Engineering

NioFlow: A Configurable Java Micro-Framework.

NioFlow is a minimalistic Java HTTP framework focusing on explicit programmatic configuration. It utilizes a hybrid architecture: NIO Selector for connection acceptance and a bounded thread pool for blocking request processing.

nioflow_server — bash

$ ./scripts/run.ps1

[INFO] Bootstrap: Initializing Server Components...

[INFO] Security: Loaded keystore.jks, enabling Native TLS

[INFO] Database: JDBC pool active on Async Executor ThreadPool

[INFO] NIO: Registering ServerSocketChannel on 0.0.0.0:443

[READY] Selector Event Loop started successfully.

$ curl -X GET https://localhost/api/health

HTTP/1.1 200 OK

Content-Type: application/json

{ "status": "UP", "uptime": "0ms" }

Under the Hood: System Mechanics

Built on Java NIO and robust architectural patterns, NioFlow provides an incredibly fast, non-blocking foundation for building scalable web applications and RESTful APIs.

NIO

Hybrid NIO Architecture

Built on Java's java.nio. Connection tracking and event loops use efficient Selectors, while request processing is handled by a bounded worker pool.

TLS

Native HTTPS Security

Direct SSLContext integration allows raw SocketChannel handoffs to SSLSocketFactory, dropping the requirement for Nginx proxies entirely for HTTPS.

DMA

Zero-Copy Memory

Hardware-accelerated Direct Memory Access via FileChannel.transferTo(). Static files hit the socket without crossing into JVM user-space memory.

DB

Async Database Offload

Prevent worker thread blocking using CompletableFuture. Operations hit HikariCP and PostgreSQL on a dedicated secondary loop, ensuring maximum throughput.

ERR

Global Error Handling

Uncaught runtime exceptions are cleanly intercepted. Configure custom JSON fallback responses to guarantee you never leak a raw stack trace to the public internet.

SIG

Graceful Shutdown

Built for containerized environments. Using drainAndStop(), NioFlow safely completes all active TCP requests before permitting SIGTERM termination.

Clean Controller Abstraction

While the engine is complex at the socket layer, registering business logic remains declarative and heavily typed. Look at how easy it is to spin up new HTTP endpoints.

ServerApp.java
1public class ServerApp {
2 public static void main(String[] args) {
3 NioFlowApp app = new NioFlowApp();
4
5 // Middleware Stack
6 app.use(new LoggerMiddleware());
7 app.use(new RateLimitMiddleware(100, Duration.ofMinutes(1)));
8
9 // Handlers & Async DB offload
10 app.get("/api/orders", new OrderController()::list);
11
12 // Global Error Intercept
13 app.onError((err, ctx) -> ctx.status(500).json("Fail"));
14
15 // Graceful Shutdown
16 Runtime.getRuntime().addShutdownHook(new Thread(() -> {
17 app.drainAndStop(30, TimeUnit.SECONDS);
18 }));
19
20 // Native TLS Integration
21 app.listenSecure(443, "keystore.jks", "password");
22 }
23}
Available on GitHub

The Final Piece of the Architecture Puzzle.

The framework avoids reflection and hidden dependency injection containers. All route logic, exception handling, and middleware flows are wired manually, ensuring completely predictable code execution.

Stack Manifest
Core EngineNative java.nio
Data PipelineFileChannel DMA
PersistencePostgreSQL 15+
CryptographyBCrypt / JWT
LicenseMIT