Package com.linecorp.armeria.client
Class ClientFactoryBuilder
java.lang.Object
com.linecorp.armeria.client.ClientFactoryBuilder
public final class ClientFactoryBuilder extends Object
Builds a new
ClientFactory
.
Example
final ClientFactory factory =
ClientFactory.builder()
// Set the connection timeout to 5 seconds.
.connectTimeoutMillis(5000)
// Set the socket send buffer to 1 MiB.
.socketOption(ChannelOption.SO_SNDBUF, 1048576)
// Disable certificate verification; never do this in production!
.tlsNoVerify()
.build();
-
Method Summary
Modifier and Type Method Description ClientFactoryBuilder
addressResolverGroupFactory(Function<? super EventLoopGroup,? extends AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory)
Sets the factory that creates aAddressResolverGroup
which resolves remote addresses intoInetSocketAddress
es.ClientFactory
build()
Returns a newly-createdClientFactory
based on the properties of this builder.<T> ClientFactoryBuilder
channelOption(ChannelOption<T> option, T value)
Sets the options of sockets created by theClientFactory
.ClientFactoryBuilder
connectionPoolListener(ConnectionPoolListener connectionPoolListener)
Sets the listener which is notified on a connection pool event.ClientFactoryBuilder
connectTimeout(Duration connectTimeout)
Sets the timeout of a socket connection attempt.ClientFactoryBuilder
connectTimeoutMillis(long connectTimeoutMillis)
Sets the timeout of a socket connection attempt in milliseconds.ClientFactoryBuilder
domainNameResolverCustomizer(Consumer<? super DnsResolverGroupBuilder> dnsResolverGroupCustomizer)
Adds the specifiedConsumer
which customizes the givenDnsNameResolverBuilder
.ClientFactoryBuilder
eventLoopSchedulerFactory(Function<? super EventLoopGroup,? extends EventLoopScheduler> eventLoopSchedulerFactory)
Sets the factory that creates anEventLoopScheduler
which is responsible for assigning anEventLoop
to handle a connection to the specifiedEndpoint
.ClientFactoryBuilder
http1MaxChunkSize(int http1MaxChunkSize)
Sets the maximum length of each chunk in an HTTP/1 response content.ClientFactoryBuilder
http1MaxHeaderSize(int http1MaxHeaderSize)
Sets the maximum length of all headers in an HTTP/1 response.ClientFactoryBuilder
http1MaxInitialLineLength(int http1MaxInitialLineLength)
Sets the maximum length of an HTTP/1 response initial line.ClientFactoryBuilder
http2InitialConnectionWindowSize(int http2InitialConnectionWindowSize)
ClientFactoryBuilder
http2InitialStreamWindowSize(int http2InitialStreamWindowSize)
Sets the SETTINGS_INITIAL_WINDOW_SIZE for HTTP/2 stream-level flow control.ClientFactoryBuilder
http2MaxFrameSize(int http2MaxFrameSize)
Sets the SETTINGS_MAX_FRAME_SIZE that indicates the size of the largest frame payload that this client is willing to receive.ClientFactoryBuilder
http2MaxHeaderListSize(long http2MaxHeaderListSize)
Sets the SETTINGS_MAX_HEADER_LIST_SIZE that indicates the maximum size of header list that the client is prepared to accept, in octets.ClientFactoryBuilder
idleTimeout(Duration idleTimeout)
Sets the idle timeout of a socket connection.ClientFactoryBuilder
idleTimeoutMillis(long idleTimeoutMillis)
Sets the idle timeout of a socket connection in milliseconds.ClientFactoryBuilder
maxNumEventLoopsFunction(ToIntFunction<Endpoint> maxNumEventLoopsFunction)
Sets theToIntFunction
which takes anEndpoint
and produces the maximum number ofEventLoop
s which will be used to handle connections to the specifiedEndpoint
.ClientFactoryBuilder
maxNumEventLoopsPerEndpoint(int maxNumEventLoopsPerEndpoint)
Sets the maximum number ofEventLoop
s which will be used to handle HTTP/2 connections except the ones specified bymaxNumEventLoopsFunction(ToIntFunction)
.ClientFactoryBuilder
maxNumEventLoopsPerHttp1Endpoint(int maxNumEventLoopsPerEndpoint)
Sets the maximum number ofEventLoop
s which will be used to handle HTTP/1.1 connections except the ones specified bymaxNumEventLoopsFunction(ToIntFunction)
.ClientFactoryBuilder
meterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
which collects various stats.<T> ClientFactoryBuilder
option(ClientFactoryOption<T> option, T value)
Adds the specifiedClientFactoryOption
and itsvalue
.<T> ClientFactoryBuilder
option(ClientFactoryOptionValue<T> optionValue)
Adds the specifiedClientFactoryOptionValue
.ClientFactoryBuilder
options(ClientFactoryOptions options)
Adds the specifiedClientFactoryOptions
.ClientFactoryBuilder
pingInterval(Duration pingInterval)
Sets the PING interval.ClientFactoryBuilder
pingIntervalMillis(long pingIntervalMillis)
Sets the PING interval in milliseconds.ClientFactoryBuilder
proxyConfig(ProxyConfig proxyConfig)
TheProxyConfig
which contains proxy related configuration.ClientFactoryBuilder
tlsCustomizer(Consumer<? super SslContextBuilder> tlsCustomizer)
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session.ClientFactoryBuilder
tlsNoVerify()
Disables the verification of server's key certificate chain.String
toString()
ClientFactoryBuilder
useHttp1Pipelining(boolean useHttp1Pipelining)
Sets whether to use HTTP pipelining for HTTP/1 connections.ClientFactoryBuilder
useHttp2Preface(boolean useHttp2Preface)
Sets whether to send an HTTP/2 preface string instead of an HTTP/1 upgrade request to negotiate the protocol version of a cleartext HTTP connection.ClientFactoryBuilder
workerGroup(EventLoopGroup workerGroup, boolean shutdownOnClose)
Sets the workerEventLoopGroup
which is responsible for performing socket I/O and runningClient.execute(ClientRequestContext, Request)
.
-
Method Details
-
workerGroup
Sets the workerEventLoopGroup
which is responsible for performing socket I/O and runningClient.execute(ClientRequestContext, Request)
. If not set, the common worker group is used.- Parameters:
shutdownOnClose
- whether to shut down the workerEventLoopGroup
when theClientFactory
is closed
-
eventLoopSchedulerFactory
public ClientFactoryBuilder eventLoopSchedulerFactory(Function<? super EventLoopGroup,? extends EventLoopScheduler> eventLoopSchedulerFactory)Sets the factory that creates anEventLoopScheduler
which is responsible for assigning anEventLoop
to handle a connection to the specifiedEndpoint
. -
maxNumEventLoopsPerHttp1Endpoint
Sets the maximum number ofEventLoop
s which will be used to handle HTTP/1.1 connections except the ones specified bymaxNumEventLoopsFunction(ToIntFunction)
. 1 is used by default. -
maxNumEventLoopsPerEndpoint
Sets the maximum number ofEventLoop
s which will be used to handle HTTP/2 connections except the ones specified bymaxNumEventLoopsFunction(ToIntFunction)
. 1 is used by default. -
maxNumEventLoopsFunction
public ClientFactoryBuilder maxNumEventLoopsFunction(ToIntFunction<Endpoint> maxNumEventLoopsFunction)Sets theToIntFunction
which takes anEndpoint
and produces the maximum number ofEventLoop
s which will be used to handle connections to the specifiedEndpoint
. The function should return0
or a negative value for theEndpoint
s which it doesn't want to handle. For example:ToIntFunction<Endpoint> function = endpoint -> { if (endpoint.equals(Endpoint.of("foo.com"))) { return 5; } if (endpoint.host().contains("bar.com")) { return Integer.MAX_VALUE; // The value will be clamped at the number of event loops. } return -1; // Should return 0 or a negative value to use the default value. }
-
connectTimeout
Sets the timeout of a socket connection attempt. -
connectTimeoutMillis
Sets the timeout of a socket connection attempt in milliseconds. -
channelOption
Sets the options of sockets created by theClientFactory
. -
tlsNoVerify
Disables the verification of server's key certificate chain. This method is a shortcut for:tlsCustomizer(b -> b.trustManager(InsecureTrustManagerFactory.INSTANCE))
. Note: You should never use this in production but only for a testing purpose. -
tlsCustomizer
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session. For example, useSslContextBuilder.trustManager(TrustManagerFactory)
to configure a custom server CA orSslContextBuilder.keyManager(KeyManagerFactory)
to configure a client certificate for SSL authorization. -
addressResolverGroupFactory
public ClientFactoryBuilder addressResolverGroupFactory(Function<? super EventLoopGroup,? extends AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory)Sets the factory that creates aAddressResolverGroup
which resolves remote addresses intoInetSocketAddress
es.- Throws:
IllegalStateException
- ifdomainNameResolverCustomizer(Consumer)
was called already.
-
domainNameResolverCustomizer
public ClientFactoryBuilder domainNameResolverCustomizer(Consumer<? super DnsResolverGroupBuilder> dnsResolverGroupCustomizer)Adds the specifiedConsumer
which customizes the givenDnsNameResolverBuilder
. This method is useful when you want to change the behavior of the default domain name resolver, such as changing the DNS server list.- Throws:
IllegalStateException
- ifaddressResolverGroupFactory(Function)
was called already.
-
http2InitialConnectionWindowSize
Sets the initial connection flow-control window size. The HTTP/2 connection is first established with 65535 bytes of connection flow-control window size, and it is changed if and only ifhttp2InitialConnectionWindowSize
is set. Note that this setting affects the connection-level window size, not the window size of streams.- See Also:
http2InitialStreamWindowSize(int)
-
http2InitialStreamWindowSize
Sets the SETTINGS_INITIAL_WINDOW_SIZE for HTTP/2 stream-level flow control. Note that this setting affects the window size of all streams, not the connection-level window size.- See Also:
http2InitialConnectionWindowSize(int)
-
http2MaxFrameSize
Sets the SETTINGS_MAX_FRAME_SIZE that indicates the size of the largest frame payload that this client is willing to receive. -
http2MaxHeaderListSize
Sets the SETTINGS_MAX_HEADER_LIST_SIZE that indicates the maximum size of header list that the client is prepared to accept, in octets. -
http1MaxInitialLineLength
Sets the maximum length of an HTTP/1 response initial line. -
http1MaxHeaderSize
Sets the maximum length of all headers in an HTTP/1 response. -
http1MaxChunkSize
Sets the maximum length of each chunk in an HTTP/1 response content. The content or a chunk longer than this value will be split into smaller chunks so that their lengths never exceed it. -
idleTimeout
Sets the idle timeout of a socket connection. The connection is closed if there is no request in progress for this amount of time. -
idleTimeoutMillis
Sets the idle timeout of a socket connection in milliseconds. The connection is closed if there is no request in progress for this amount of time. -
pingIntervalMillis
Sets the PING interval in milliseconds. When neither read nor write was performed for the givenpingIntervalMillis
, a PING frame is sent for HTTP/2 or an OPTIONS request with an asterisk ("*") is sent for HTTP/1.Note that this settings is only in effect when
idleTimeoutMillis(long)
} oridleTimeout(Duration)
is greater than the specified PING interval.The minimum allowed PING interval is 10000L milliseconds.
0
means the client will not send a PING.- Throws:
IllegalArgumentException
- if the specifiedpingIntervalMillis
is smaller than 10000L milliseconds.
-
pingInterval
Sets the PING interval. When neither read nor write was performed for the givenpingInterval
, a PING frame is sent for HTTP/2 or an OPTIONS request with an asterisk ("*") is sent for HTTP/1.Note that this settings is only in effect when
idleTimeoutMillis(long)
} oridleTimeout(Duration)
is greater than the specified PING interval.The minimum allowed PING interval is 10000L milliseconds.
0
means the client will not send a PING.- Throws:
IllegalArgumentException
- if the specifiedpingInterval
is smaller than 10000L milliseconds.
-
useHttp2Preface
Sets whether to send an HTTP/2 preface string instead of an HTTP/1 upgrade request to negotiate the protocol version of a cleartext HTTP connection. -
useHttp1Pipelining
Sets whether to use HTTP pipelining for HTTP/1 connections. This does not affect HTTP/2 connections. This option is disabled by default. -
connectionPoolListener
Sets the listener which is notified on a connection pool event. -
meterRegistry
Sets theMeterRegistry
which collects various stats. -
proxyConfig
TheProxyConfig
which contains proxy related configuration. -
option
Adds the specifiedClientFactoryOption
and itsvalue
. -
option
Adds the specifiedClientFactoryOptionValue
. -
options
Adds the specifiedClientFactoryOptions
. -
build
Returns a newly-createdClientFactory
based on the properties of this builder. -
toString
-