$ show sunng87/ring-jetty9-adapter
This repository provides a Ring adapter for Jetty web servers, enabling Clojure/Ring applications to run on Jetty 11 and 12 with support for modern web protocols. Despite its 'jetty9' name, it tracks recent Jetty releases and adds features like HTTP/2, HTTP/3, and WebSocket support that aren't in the official Ring Jetty adapter. The architecture centers around a core adapter that creates and configures Jetty Server instances, with separate implementations for synchronous and asynchronous Ring handlers. It cleanly separates concerns: connection handling (HTTP/HTTPS/HTTP/2/HTTP/3), request/response translation between Jetty and Ring models, and protocol-specific upgrades (WebSocket). The adapter supports virtual threads, SSL/TLS configuration, and serves as a drop-in replacement for the official ring-jetty-adapter while offering more recent Jetty versions and additional features. Notable for its quality implementation are the WebSocket bridge that properly translates between Jetty's WebSocketListener and Ring's WebSocket protocols, and the asynchronous handler implementation that correctly manages the race condition between handler completion and timeout using atomic state and Jetty's scheduling facilities. The optional HTTP/2 and HTTP/3 modules demonstrate good practices for extending the core adapter with dynamically loaded dependencies.
The LLM identified 2 files worth highlighting for reuse:
Implements a clean bridge between Jetty's WebSocket API and Ring's WebSocket protocols. Handles WebSocket upgrade requests, translates Jetty WebSocket events (open, message, close, ping, pong, error) to Ring WebSocket callbacks, and supports both synchronous and asynchronous message sending. Demonstrates proper encapsulation of state (using an atom for the session) and clean separation of concerns.
Implements asynchronous Ring handler support using Jetty's non-blocking API. Properly manages the race condition between handler completion and timeout using an AtomicBoolean to ensure only one path (handler response, timeout, or error) completes the callback. Uses Jetty's scheduler for timeouts and executes handlers on Jetty's thread pool to avoid blocking connector dispatch threads - critical for HTTP/2 and HTTP/3 where a single thread multiplexes many streams. Shows expert-level concurrent programming practices.