public final class ClientFactoryBuilder extends Object
ClientFactory.
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();
| Constructor and Description |
|---|
ClientFactoryBuilder()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
ClientFactoryBuilder |
addressResolverGroupFactory(Function<? super io.netty.channel.EventLoopGroup,? extends io.netty.resolver.AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory)
Sets the factory that creates a
AddressResolverGroup which resolves remote addresses into
InetSocketAddresses. |
ClientFactory |
build()
Returns a newly-created
ClientFactory based on the properties of this builder. |
<T> ClientFactoryBuilder |
channelOption(io.netty.channel.ChannelOption<T> option,
T value)
Sets the options of sockets created by the
ClientFactory. |
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 specified
Consumer which customizes the given DnsNameResolverBuilder. |
ClientFactoryBuilder |
eventLoopSchedulerFactory(Function<? super io.netty.channel.EventLoopGroup,? extends EventLoopScheduler> eventLoopSchedulerFactory)
Sets the factory that creates an
EventLoopScheduler which is responsible for assigning an
EventLoop to handle a connection to the specified Endpoint. |
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 the
ToIntFunction which takes an Endpoint and produces the maximum number of
EventLoops which will be used to handle connections to the specified Endpoint. |
ClientFactoryBuilder |
maxNumEventLoopsPerEndpoint(int maxNumEventLoopsPerEndpoint)
Sets the maximum number of
EventLoops which will be used to handle HTTP/2 connections
except the ones specified by maxNumEventLoopsFunction(ToIntFunction). |
ClientFactoryBuilder |
maxNumEventLoopsPerHttp1Endpoint(int maxNumEventLoopsPerEndpoint)
Sets the maximum number of
EventLoops which will be used to handle HTTP/1.1 connections
except the ones specified by maxNumEventLoopsFunction(ToIntFunction). |
ClientFactoryBuilder |
meterRegistry(MeterRegistry meterRegistry)
Sets the
MeterRegistry which collects various stats. |
<T> ClientFactoryBuilder |
option(ClientFactoryOption<T> option,
T value)
Adds the specified
ClientFactoryOption and its value. |
<T> ClientFactoryBuilder |
option(ClientFactoryOptionValue<T> optionValue)
Adds the specified
ClientFactoryOptionValue. |
ClientFactoryBuilder |
options(ClientFactoryOptions options)
Adds the specified
ClientFactoryOptions. |
<T> ClientFactoryBuilder |
socketOption(io.netty.channel.ChannelOption<T> option,
T value)
Deprecated.
|
ClientFactoryBuilder |
sslContextCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> sslContextCustomizer)
Deprecated.
|
ClientFactoryBuilder |
tlsCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Adds the
Consumer which can arbitrarily configure the SslContextBuilder 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(io.netty.channel.EventLoopGroup workerGroup,
boolean shutdownOnClose)
Sets the worker
EventLoopGroup which is responsible for performing socket I/O and running
Client.execute(ClientRequestContext, Request). |
@Deprecated public ClientFactoryBuilder()
ClientFactory.builder().public ClientFactoryBuilder workerGroup(io.netty.channel.EventLoopGroup workerGroup, boolean shutdownOnClose)
EventLoopGroup which is responsible for performing socket I/O and running
Client.execute(ClientRequestContext, Request).
If not set, the common worker group is used.shutdownOnClose - whether to shut down the worker EventLoopGroup
when the ClientFactory is closedpublic ClientFactoryBuilder eventLoopSchedulerFactory(Function<? super io.netty.channel.EventLoopGroup,? extends EventLoopScheduler> eventLoopSchedulerFactory)
EventLoopScheduler which is responsible for assigning an
EventLoop to handle a connection to the specified Endpoint.public ClientFactoryBuilder maxNumEventLoopsPerHttp1Endpoint(int maxNumEventLoopsPerEndpoint)
EventLoops which will be used to handle HTTP/1.1 connections
except the ones specified by maxNumEventLoopsFunction(ToIntFunction).
is used by default.public ClientFactoryBuilder maxNumEventLoopsPerEndpoint(int maxNumEventLoopsPerEndpoint)
EventLoops which will be used to handle HTTP/2 connections
except the ones specified by maxNumEventLoopsFunction(ToIntFunction).
is used by default.public ClientFactoryBuilder maxNumEventLoopsFunction(ToIntFunction<Endpoint> maxNumEventLoopsFunction)
ToIntFunction which takes an Endpoint and produces the maximum number of
EventLoops which will be used to handle connections to the specified Endpoint.
The function should return 0 or a negative value for the Endpoints 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.
}
public ClientFactoryBuilder connectTimeout(Duration connectTimeout)
public ClientFactoryBuilder connectTimeoutMillis(long connectTimeoutMillis)
@Deprecated public <T> ClientFactoryBuilder socketOption(io.netty.channel.ChannelOption<T> option, T value)
channelOption(ChannelOption, Object).ClientFactory.public <T> ClientFactoryBuilder channelOption(io.netty.channel.ChannelOption<T> option, T value)
ClientFactory.@Deprecated public ClientFactoryBuilder sslContextCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> sslContextCustomizer)
tlsCustomizer(Consumer).Consumer which can arbitrarily configure the SslContextBuilder that will be
applied to the SSL session. For example, use SslContextBuilder.trustManager(java.io.File) to configure a
custom server CA or SslContextBuilder.keyManager(java.io.File, java.io.File) to configure a client certificate for SSL
authorization.public ClientFactoryBuilder tlsNoVerify()
tlsCustomizer(b -> b.trustManager(InsecureTrustManagerFactory.INSTANCE)).
Note: You should never use this in production but only for a testing purpose.InsecureTrustManagerFactory,
tlsCustomizer(Consumer)public ClientFactoryBuilder tlsCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Consumer which can arbitrarily configure the SslContextBuilder that will be
applied to the SSL session. For example, use SslContextBuilder.trustManager(TrustManagerFactory)
to configure a custom server CA or SslContextBuilder.keyManager(KeyManagerFactory) to configure
a client certificate for SSL authorization.public ClientFactoryBuilder addressResolverGroupFactory(Function<? super io.netty.channel.EventLoopGroup,? extends io.netty.resolver.AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory)
AddressResolverGroup which resolves remote addresses into
InetSocketAddresses.IllegalStateException - if domainNameResolverCustomizer(Consumer) was called already.public ClientFactoryBuilder domainNameResolverCustomizer(Consumer<? super DnsResolverGroupBuilder> dnsResolverGroupCustomizer)
Consumer which customizes the given DnsNameResolverBuilder.
This method is useful when you want to change the behavior of the default domain name resolver, such as
changing the DNS server list.IllegalStateException - if addressResolverGroupFactory(Function) was called already.public ClientFactoryBuilder http2InitialConnectionWindowSize(int http2InitialConnectionWindowSize)
http2InitialConnectionWindowSize is set.
Note that this setting affects the connection-level window size, not the window size of streams.http2InitialStreamWindowSize(int)public ClientFactoryBuilder http2InitialStreamWindowSize(int http2InitialStreamWindowSize)
http2InitialConnectionWindowSize(int)public ClientFactoryBuilder http2MaxFrameSize(int http2MaxFrameSize)
public ClientFactoryBuilder http2MaxHeaderListSize(long http2MaxHeaderListSize)
public ClientFactoryBuilder http1MaxInitialLineLength(int http1MaxInitialLineLength)
public ClientFactoryBuilder http1MaxHeaderSize(int http1MaxHeaderSize)
public ClientFactoryBuilder http1MaxChunkSize(int http1MaxChunkSize)
public ClientFactoryBuilder idleTimeout(Duration idleTimeout)
public ClientFactoryBuilder idleTimeoutMillis(long idleTimeoutMillis)
public ClientFactoryBuilder useHttp2Preface(boolean useHttp2Preface)
public ClientFactoryBuilder useHttp1Pipelining(boolean useHttp1Pipelining)
public ClientFactoryBuilder connectionPoolListener(ConnectionPoolListener connectionPoolListener)
public ClientFactoryBuilder meterRegistry(MeterRegistry meterRegistry)
MeterRegistry which collects various stats.public <T> ClientFactoryBuilder option(ClientFactoryOption<T> option, T value)
ClientFactoryOption and its value.public <T> ClientFactoryBuilder option(ClientFactoryOptionValue<T> optionValue)
ClientFactoryOptionValue.public ClientFactoryBuilder options(ClientFactoryOptions options)
ClientFactoryOptions.public ClientFactory build()
ClientFactory based on the properties of this builder.Copyright © 2020 LeanCloud. All rights reserved.