Class ListenerOptions.Builder
- Enclosing class:
ListenerOptions
build(). Each setter validates its value at once and throws
IllegalArgumentException with the setting's name and valid range. Not thread-safe; the
built options are immutable.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds immutable options.compression(boolean enabled) Decodes gzip and deflate request bodies and compresses eligible response bodies on this listener.compressionLevel(int level) Sets the deflater level for compressed responses.handshakeTimeout(Duration timeout) Sets how long a new connection may take to finish its TLS handshake.headTimeout(Duration timeout) Sets how long a request head may take from its first byte; a slower client receives 408.http2(boolean enabled) Accepts HTTP/2 on this listener in addition to HTTP/1.1.idleTimeout(Duration timeout) Sets the network inactivity (no read and no write progress) after which a connection closes.ioThreads(int threads) Sets the I/O threads of the listener.lingerQuietTimeout(Duration timeout) Sets the silence after which lingering ends because the client is taken to have finished.lingerTimeout(Duration timeout) Sets how long a connection may linger after its last response, reading and discarding input so a client that is still sending reads the whole response.maxConnections(int connections) Sets the open connections per listener.maxDiscardedInput(int bytes) Sets how many bytes a connection discards unread after an error or its last response before it is closed as abusive.maxHeaderBytes(int bytes) Sets the largest header section; a larger one is answered 431.maxInFlightBodyBytes(long bytes) Sets the request body bytes the listener holds at once, summed over all its connections: bodies being received, bodies of pipelined requests waiting behind a running one, and the bodies of requests whose handler is running.maxLingeringConnections(int connections) Sets how many lingering connections move to a separate pool and stop counting againstmaxConnections.maxPipelinedRequests(int requests) Sets the outstanding requests per connection, including the running one.maxRequestLine(int bytes) Sets the longest request line; a longer one is answered 414.Names the listener.rejectionObserver(RejectionObserver observer) Sets an observer called for each error response the listener generates itself, such as 413, 431 or 503, for metrics and logging.responseTimeout(Duration timeout) Sets how long writing one response may take, from handing it to the socket until the operating system has accepted its last byte; a slower reader loses the connection.shutdownGrace(Duration grace) Sets how long closing the listener lets running exchanges finish.shutdownLingerTimeout(Duration timeout) Sets the total linger bound once the listener is closing (the smaller of this andlingerTimeoutapplies).tls(TlsOptions options) Serves HTTPS instead of plain HTTP on this listener.transport(TransportKind kind) Sets the I/O mechanism of the listener.
-
Method Details
-
name
Names the listener. The name is the value of thelistenertag of the listener-level metrics (connections, bytes and answers given before admission), so listeners that share an application can be told apart. It is chosen by the operator, never by a client, and should come from a small fixed set.- Parameters:
name- lowercase letters, digits and underscores starting with a letter, at most 32 characters; the default isdefault- Returns:
- this builder
- Throws:
IllegalArgumentException- if invalid
-
shutdownGrace
Sets how long closing the listener lets running exchanges finish. After it, remaining connections close and their handlers are interrupted. Zero interrupts at once.- Parameters:
grace- from zero to one day; the default is 5 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
idleTimeout
Sets the network inactivity (no read and no write progress) after which a connection closes. It does not interrupt a waiting or running request.- Parameters:
timeout- 1 millisecond to one day; the default is 30 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
headTimeout
Sets how long a request head may take from its first byte; a slower client receives 408.- Parameters:
timeout- 1 millisecond to one day; the default is 10 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
responseTimeout
Sets how long writing one response may take, from handing it to the socket until the operating system has accepted its last byte; a slower reader loses the connection.- Parameters:
timeout- 1 millisecond to one day; the default is 30 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
lingerTimeout
Sets how long a connection may linger after its last response, reading and discarding input so a client that is still sending reads the whole response.- Parameters:
timeout- total bound, 1 millisecond to one day; the default is 2 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
lingerQuietTimeout
Sets the silence after which lingering ends because the client is taken to have finished. Each arriving byte restarts it; it never extendslingerTimeout.- Parameters:
timeout- 1 millisecond to one day; the default is 500 milliseconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
shutdownLingerTimeout
Sets the total linger bound once the listener is closing (the smaller of this andlingerTimeoutapplies).- Parameters:
timeout- 1 millisecond to one day; the default is 500 milliseconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
handshakeTimeout
Sets how long a new connection may take to finish its TLS handshake. A client that is slower, or that sends something other than TLS, loses the connection; until then it holds a connection slot (seemaxConnections(int)) but no admission capacity. Ignored withouttls(TlsOptions).- Parameters:
timeout- 1 millisecond to one day; the default is 10 seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
tls
Serves HTTPS instead of plain HTTP on this listener. The material is validated when the listener starts. Null serves plain HTTP, which is the default.- Parameters:
options- the TLS settings, or null- Returns:
- this builder
-
http2
Accepts HTTP/2 on this listener in addition to HTTP/1.1. Off by default, so a listener without this setting behaves exactly as before. With TLS, ALPN offersh2followed byhttp/1.1: a client that negotiatesh2speaks HTTP/2 and one that negotiates or falls back tohttp/1.1speaks HTTP/1.1. On a cleartext listener, a connection starting with the HTTP/2 client preface speaks HTTP/2; all other connections speak HTTP/1.1. An HTTP/1.1Upgradeto h2c is not supported.This is a transport choice only. Both protocols use the same routes, handlers, codecs, execution limits, body budgets, deadlines, error mapping and shutdown behavior. Requests keep the same shape, which has no HTTP version; HTTP/2 pseudo-headers become ordinary request headers. A
TestClientstays in-memory and HTTP/1-shaped regardless of this setting.- Parameters:
enabled- true to accept HTTP/2; false to accept HTTP/1.x only- Returns:
- this builder
-
compression
Decodes gzip and deflate request bodies and compresses eligible response bodies on this listener. Off by default, so a listener that does not opt in behaves exactly as before.This is a transport choice only: no application API or dependency changes. Request bodies are decoded before the handler sees them and are bounded by
maxInFlightBodyBytes(long)and the application's body limit after decoding as well as on the wire. Only one coding is decoded. Response compression is negotiated per request fromAccept-Encoding, applies only to buffered responses above a small size, and never changes a HEAD, streamed, partial or WebSocket upgrade response. An in-memoryTestClientstays uncompressed regardless of this setting.- Parameters:
enabled- true to enable request decompression and response compression- Returns:
- this builder
-
compressionLevel
Sets the deflater level for compressed responses. Lower levels spend less CPU per byte and produce larger bodies; higher levels spend more CPU and produce smaller ones. The setting has no effect unlesscompression(boolean)is enabled, and does not change request decompression, whose level the sender chose.The default, 6, is the JDK's default and a balanced choice. Compression still runs on the listener's I/O threads with a bounded, copy-free buffer: an offloaded pool would add a queue and extra copies, and at most
maxRequestBodybytes are compressed at a time. Theaxiom.http.compression.*metrics report the cost when tuning this value.- Parameters:
level- from 1 (fastest) to 9 (smallest); the default is 6- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxDiscardedInput
Sets how many bytes a connection discards unread after an error or its last response before it is closed as abusive.- Parameters:
bytes- from zero to 1 GiB; the default is 16 MiB- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxConnections
Sets the open connections per listener. A connection over the cap is closed at once without a response and without consuming a slot. Connections that only linger count againstmaxLingeringConnectionsinstead while that pool has room.Relation to admission: a connection carries at most
maxPipelinedRequestsoutstanding requests, but a client usually keeps one in flight, so the requests a listener can hold at once are roughly bounded by this cap. A cap below the application's admission capacity (active plus queued requests) leaves part of that capacity unreachable: clients are refused at the connection level before admission could queue or reject them with 503. Set the cap at or above that capacity, plus headroom for idle keep-alive connections.- Parameters:
connections- 1 to 1,000,000; the default is 128- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxLingeringConnections
Sets how many lingering connections move to a separate pool and stop counting againstmaxConnections. Beyond it a lingering connection keeps its regular slot, so a listener has at mostmaxConnections + maxLingeringConnectionsopen sockets. Zero keeps lingering connections on their regular slots.- Parameters:
connections- 0 to 1,000,000; the default is 32- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxPipelinedRequests
Sets the outstanding requests per connection, including the running one. A further request is answered 503 after the earlier responses and the connection closes.- Parameters:
requests- 1 to 1024; the default is 8- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxInFlightBodyBytes
Sets the request body bytes the listener holds at once, summed over all its connections: bodies being received, bodies of pipelined requests waiting behind a running one, and the bodies of requests whose handler is running. A declaredContent-Lengthis reserved in full when the request head arrives and a chunked body is counted as it arrives; the reservation is returned when the request's response is final or its connection ends. A request that does not fit is answered 503 and its connection closes after the earlier responses; the handler is never invoked. The default equals the largest configurablemaxRequestBody, so any permitted body fits when the listener is otherwise idle. A listener refuses to start when the budget is smaller than the application'smaxRequestBody, because no such body could ever be accepted.- Parameters:
bytes- 1 to 1 TiB; the default is 64 MiB- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxRequestLine
Sets the longest request line; a longer one is answered 414.- Parameters:
bytes- 256 to 65,536; the default is 4096- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
maxHeaderBytes
Sets the largest header section; a larger one is answered 431.- Parameters:
bytes- 256 to 1 MiB; the default is 8192- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
ioThreads
Sets the I/O threads of the listener. User handlers never run on them.- Parameters:
threads- 1 to 1024; the default is the number of available processors, at least 2- Returns:
- this builder
- Throws:
IllegalArgumentException- if out of range
-
transport
Sets the I/O mechanism of the listener. Behavior, limits and timeouts do not depend on it.TransportKind.AUTOuses a native transport when its library is on the class path and usable, and the JDK's NIO otherwise; naming a native kind that is not usable makes the listener fail to start with anIllegalStateException.- Parameters:
kind- the requested transport; the default isTransportKind.AUTO- Returns:
- this builder
- Throws:
NullPointerException- if null
-
rejectionObserver
Sets an observer called for each error response the listener generates itself, such as 413, 431 or 503, for metrics and logging. It is read-only; seeRejectionObserver.- Parameters:
observer- the observer; one is replaced by the next call- Returns:
- this builder
-
build
Builds immutable options.- Returns:
- the options
-