Package com.linecorp.armeria.client
Class ClientFactoryBuilder
- java.lang.Object
-
- com.linecorp.armeria.client.ClientFactoryBuilder
-
public final class ClientFactoryBuilder extends Object
Builds a newClientFactory
.Example
final ClientFactory factory = new ClientFactoryBuilder(); // 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! .sslContextCustomizer(b -> b.trustManager(InsecureTrustManagerFactory.INSTANCE)) .build();
-
-
Constructor Summary
Constructors Constructor Description ClientFactoryBuilder()
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods 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 DnsNameResolverBuilder> domainNameResolverCustomizer)
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
socketOption(ChannelOption<T> option, T value)
Deprecated.ClientFactoryBuilder
sslContextCustomizer(Consumer<? super SslContextBuilder> sslContextCustomizer)
Sets theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session.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 Detail
-
workerGroup
public ClientFactoryBuilder workerGroup(EventLoopGroup workerGroup, boolean shutdownOnClose)
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
public 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)
. 1 is used by default.
-
maxNumEventLoopsPerEndpoint
public 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)
. 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
public ClientFactoryBuilder connectTimeout(Duration connectTimeout)
Sets the timeout of a socket connection attempt.
-
connectTimeoutMillis
public ClientFactoryBuilder connectTimeoutMillis(long connectTimeoutMillis)
Sets the timeout of a socket connection attempt in milliseconds.
-
socketOption
@Deprecated public <T> ClientFactoryBuilder socketOption(ChannelOption<T> option, T value)
Deprecated.Sets the options of sockets created by theClientFactory
.
-
channelOption
public <T> ClientFactoryBuilder channelOption(ChannelOption<T> option, T value)
Sets the options of sockets created by theClientFactory
.
-
sslContextCustomizer
public ClientFactoryBuilder sslContextCustomizer(Consumer<? super SslContextBuilder> sslContextCustomizer)
Sets theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session. For example, useSslContextBuilder.trustManager(java.io.File)
to configure a custom server CA orSslContextBuilder.keyManager(java.io.File, java.io.File)
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 DnsNameResolverBuilder> domainNameResolverCustomizer)
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
public ClientFactoryBuilder http2InitialConnectionWindowSize(int 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
public ClientFactoryBuilder 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
public 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.
-
http2MaxHeaderListSize
public 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.
-
http1MaxInitialLineLength
public ClientFactoryBuilder http1MaxInitialLineLength(int http1MaxInitialLineLength)
Sets the maximum length of an HTTP/1 response initial line.
-
http1MaxHeaderSize
public ClientFactoryBuilder http1MaxHeaderSize(int http1MaxHeaderSize)
Sets the maximum length of all headers in an HTTP/1 response.
-
http1MaxChunkSize
public ClientFactoryBuilder http1MaxChunkSize(int 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
public ClientFactoryBuilder idleTimeout(Duration 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
public ClientFactoryBuilder idleTimeoutMillis(long 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.
-
useHttp2Preface
public 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.
-
useHttp1Pipelining
public ClientFactoryBuilder useHttp1Pipelining(boolean 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
public ClientFactoryBuilder connectionPoolListener(ConnectionPoolListener connectionPoolListener)
Sets the listener which is notified on a connection pool event.
-
meterRegistry
public ClientFactoryBuilder meterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
which collects various stats.
-
build
public ClientFactory build()
Returns a newly-createdClientFactory
based on the properties of this builder.
-
-