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(KeyedChannelPoolHandler<? super PoolKey> 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
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
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
initialHttp2ConnectionWindowSize(int initialHttp2ConnectionWindowSize)
ClientFactoryBuilder
initialHttp2StreamWindowSize(int initialHttp2StreamWindowSize)
Sets the SETTINGS_INITIAL_WINDOW_SIZE for HTTP/2 stream-level flow control.ClientFactoryBuilder
maxHttp1ChunkSize(int maxHttp1ChunkSize)
Sets the maximum length of each chunk in an HTTP/1 response content.ClientFactoryBuilder
maxHttp1HeaderSize(int maxHttp1HeaderSize)
Sets the maximum length of all headers in an HTTP/1 response.ClientFactoryBuilder
maxHttp1InitialLineLength(int maxHttp1InitialLineLength)
Sets the maximum length of an HTTP/1 response initial line.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
-
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.
-
initialHttp2ConnectionWindowSize
public ClientFactoryBuilder initialHttp2ConnectionWindowSize(int initialHttp2ConnectionWindowSize)
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 ifinitialHttp2ConnectionWindowSize
is set. Note that this setting affects the connection-level window size, not the window size of streams.- See Also:
initialHttp2StreamWindowSize(int)
-
initialHttp2StreamWindowSize
public ClientFactoryBuilder initialHttp2StreamWindowSize(int initialHttp2StreamWindowSize)
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:
initialHttp2ConnectionWindowSize(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.
-
maxHttp1InitialLineLength
public ClientFactoryBuilder maxHttp1InitialLineLength(int maxHttp1InitialLineLength)
Sets the maximum length of an HTTP/1 response initial line.
-
maxHttp1HeaderSize
public ClientFactoryBuilder maxHttp1HeaderSize(int maxHttp1HeaderSize)
Sets the maximum length of all headers in an HTTP/1 response.
-
maxHttp1ChunkSize
public ClientFactoryBuilder maxHttp1ChunkSize(int maxHttp1ChunkSize)
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 enabled by default.
-
connectionPoolListener
public ClientFactoryBuilder connectionPoolListener(KeyedChannelPoolHandler<? super PoolKey> 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.
-
-