public final class WebSocketClientBuilder extends Object
CloseableWebSocketClient instances.
This builder assembles a WebSocket client on top of the asynchronous HTTP/1.1 requester and connection pool infrastructure provided by HttpComponents Core. Unless otherwise specified, sensible defaults are used for all components.
The resulting CloseableWebSocketClient manages its own I/O
reactor and connection pool and must be closed when no longer needed.
Builders are mutable and not thread-safe. Configure the instance
on a single thread and then call build().
| Modifier and Type | Method and Description |
|---|---|
CloseableWebSocketClient |
build()
Builds a new
CloseableWebSocketClient instance using the
current builder configuration. |
static WebSocketClientBuilder |
create()
Creates a new
WebSocketClientBuilder instance. |
WebSocketClientBuilder |
defaultConfig(WebSocketClientConfig defaultConfig)
Sets the default configuration applied to WebSocket connections
created by the resulting client.
|
WebSocketClientBuilder |
setCharCodingConfig(CharCodingConfig charCodingConfig)
Sets the character coding configuration for HTTP message processing.
|
WebSocketClientBuilder |
setConnectionReuseStrategy(ConnectionReuseStrategy connStrategy)
Sets the connection reuse strategy for persistent HTTP connections.
|
WebSocketClientBuilder |
setConnPoolListener(ConnPoolListener<HttpHost> connPoolListener)
Sets a listener for connection pool events.
|
WebSocketClientBuilder |
setDefaultMaxPerRoute(int defaultMaxPerRoute)
Sets the default maximum number of connections per route.
|
WebSocketClientBuilder |
setExceptionCallback(Callback<Exception> exceptionCallback)
Sets a callback to be notified of fatal I/O exceptions.
|
WebSocketClientBuilder |
setH2Config(H2Config h2Config)
Sets the HTTP/2 configuration for the underlying H2 requester.
|
WebSocketClientBuilder |
setH2HttpProcessor(HttpProcessor h2HttpProcessor)
Sets a custom
HttpProcessor for the HTTP/2 requester. |
WebSocketClientBuilder |
setHttp1Config(Http1Config http1Config)
Sets the HTTP/1.1 configuration for the underlying requester.
|
WebSocketClientBuilder |
setHttpProcessor(HttpProcessor httpProcessor)
Sets a custom
HttpProcessor for HTTP/1.1 requests. |
WebSocketClientBuilder |
setIOReactorConfig(IOReactorConfig ioReactorConfig)
Sets the I/O reactor configuration.
|
WebSocketClientBuilder |
setIOSessionDecorator(Decorator<IOSession> ioSessionDecorator)
Sets a decorator for low-level I/O sessions created by the reactor.
|
WebSocketClientBuilder |
setIOSessionListener(IOSessionListener sessionListener)
Sets a listener for I/O session lifecycle events.
|
WebSocketClientBuilder |
setMaxPendingCommandsPerConnection(int maxPendingCommandsPerConnection)
Sets the maximum number of pending commands per HTTP/1.1 connection.
|
WebSocketClientBuilder |
setMaxTotal(int maxTotal)
Sets the maximum total number of connections in the pool.
|
WebSocketClientBuilder |
setPoolConcurrencyPolicy(PoolConcurrencyPolicy poolConcurrencyPolicy)
Sets the concurrency policy for the connection pool.
|
WebSocketClientBuilder |
setPoolReusePolicy(PoolReusePolicy poolReusePolicy)
Sets the reuse policy for connections in the pool.
|
WebSocketClientBuilder |
setReactorMetricsListener(IOReactorMetricsListener reactorMetricsListener)
Sets a metrics listener for the I/O reactor.
|
WebSocketClientBuilder |
setStreamListener(Http1StreamListener streamListener)
Sets a listener for HTTP/1.1 stream events.
|
WebSocketClientBuilder |
setThreadFactory(ThreadFactory threadFactory)
Sets the thread factory used to create the main I/O reactor thread.
|
WebSocketClientBuilder |
setTimeToLive(Timeout timeToLive)
Sets the time-to-live for persistent connections in the pool.
|
WebSocketClientBuilder |
setTlsHandshakeTimeout(Timeout handshakeTimeout)
Sets the timeout for the TLS handshake.
|
WebSocketClientBuilder |
setTlsStrategy(TlsStrategy tlsStrategy)
Sets the TLS strategy used to establish HTTPS or WSS connections.
|
public static WebSocketClientBuilder create()
WebSocketClientBuilder instance.public WebSocketClientBuilder defaultConfig(WebSocketClientConfig defaultConfig)
defaultConfig - default WebSocket configuration; if null
the existing default is retained.public WebSocketClientBuilder setIOReactorConfig(IOReactorConfig ioReactorConfig)
ioReactorConfig - I/O reactor configuration, or null
to use IOReactorConfig.DEFAULT.public WebSocketClientBuilder setHttp1Config(Http1Config http1Config)
http1Config - HTTP/1.1 configuration, or null
to use Http1Config.DEFAULT.public WebSocketClientBuilder setCharCodingConfig(CharCodingConfig charCodingConfig)
charCodingConfig - character coding configuration, or null
to use CharCodingConfig.DEFAULT.public WebSocketClientBuilder setHttpProcessor(HttpProcessor httpProcessor)
HttpProcessor for HTTP/1.1 requests.httpProcessor - HTTP processor, or null to use
HttpProcessors.client().public WebSocketClientBuilder setH2HttpProcessor(HttpProcessor h2HttpProcessor)
HttpProcessor for the HTTP/2 requester.h2HttpProcessor - HTTP/2 processor, or null to use
H2Processors.client().public WebSocketClientBuilder setConnectionReuseStrategy(ConnectionReuseStrategy connStrategy)
connStrategy - connection reuse strategy, or null
to use DefaultClientConnectionReuseStrategy.public WebSocketClientBuilder setDefaultMaxPerRoute(int defaultMaxPerRoute)
defaultMaxPerRoute - maximum connections per route; values
≤ 0 cause the default of 20
to be used.public WebSocketClientBuilder setMaxTotal(int maxTotal)
maxTotal - maximum total connections; values ≤ 0 cause
the default of 50 to be used.public WebSocketClientBuilder setTimeToLive(Timeout timeToLive)
timeToLive - connection time-to-live, or null to use
Timeout.DISABLED.public WebSocketClientBuilder setPoolReusePolicy(PoolReusePolicy poolReusePolicy)
poolReusePolicy - reuse policy, or null to use
PoolReusePolicy.LIFO.public WebSocketClientBuilder setPoolConcurrencyPolicy(PoolConcurrencyPolicy poolConcurrencyPolicy)
poolConcurrencyPolicy - concurrency policy, or null
to use PoolConcurrencyPolicy.STRICT.public WebSocketClientBuilder setMaxPendingCommandsPerConnection(int maxPendingCommandsPerConnection)
This setting only applies to the HTTP/1.1 requester used for WebSocket upgrade handshakes. It has no effect on HTTP/2 streams.
maxPendingCommandsPerConnection - maximum pending commands; values < 0
cause the default of 0 to be used.public WebSocketClientBuilder setTlsStrategy(TlsStrategy tlsStrategy)
tlsStrategy - TLS strategy, or null to use
BasicClientTlsStrategy.public WebSocketClientBuilder setTlsHandshakeTimeout(Timeout handshakeTimeout)
handshakeTimeout - handshake timeout, or null for no
specific timeout.public WebSocketClientBuilder setIOSessionDecorator(Decorator<IOSession> ioSessionDecorator)
ioSessionDecorator - decorator, or null for none.public WebSocketClientBuilder setExceptionCallback(Callback<Exception> exceptionCallback)
exceptionCallback - exception callback, or null to use
WsLoggingExceptionCallback.INSTANCE.public WebSocketClientBuilder setIOSessionListener(IOSessionListener sessionListener)
sessionListener - session listener, or null for none.public WebSocketClientBuilder setH2Config(H2Config h2Config)
h2Config - HTTP/2 configuration, or null
to use H2Config.DEFAULT.public WebSocketClientBuilder setStreamListener(Http1StreamListener streamListener)
streamListener - stream listener, or null for none.public WebSocketClientBuilder setConnPoolListener(ConnPoolListener<HttpHost> connPoolListener)
connPoolListener - pool listener, or null for none.public WebSocketClientBuilder setThreadFactory(ThreadFactory threadFactory)
threadFactory - thread factory, or null to use a
DefaultThreadFactory named
"websocket-main".public WebSocketClientBuilder setReactorMetricsListener(IOReactorMetricsListener reactorMetricsListener)
reactorMetricsListener - metrics listener, or null for none.public CloseableWebSocketClient build()
CloseableWebSocketClient instance using the
current builder configuration.
The returned client owns its underlying I/O reactor and connection pool and must be closed to release system resources.
CloseableWebSocketClient.Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.