Class MultiAddressHttpClientBuilder<U,R>
- java.lang.Object
-
- io.servicetalk.http.api.MultiAddressHttpClientBuilder<U,R>
-
- Type Parameters:
U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)
public abstract class MultiAddressHttpClientBuilder<U,R> extends java.lang.Object
A builder ofStreamingHttpClient
instances which have a capacity to call any server based on the parsed absolute-form URL address information from eachStreamingHttpRequest
.It also provides a good set of default settings and configurations, which could be used by most users as-is or could be overridden to address specific use cases.
- See Also:
- absolute-form rfc7230#section-5.3.2
-
-
Constructor Summary
Constructors Constructor Description MultiAddressHttpClientBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract MultiAddressHttpClientBuilder<U,R>
appendClientFilter(MultiAddressHttpClientFilterFactory<U> factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpClient
created by this builder for a givenUnresolvedAddress
.abstract MultiAddressHttpClientBuilder<U,R>
appendClientFilter(StreamingHttpClientFilterFactory factory)
Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder.MultiAddressHttpClientBuilder<U,R>
appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, MultiAddressHttpClientFilterFactory<U> factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpClient
created by this builder for a givenUnresolvedAddress
, for every request that passes the providedPredicate
.MultiAddressHttpClientBuilder<U,R>
appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory)
Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder, for every request that passes the providedPredicate
.abstract MultiAddressHttpClientBuilder<U,R>
appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
Appends the filter to the chain of filters used to decorate theConnectionFactory
used by this builder.abstract MultiAddressHttpClientBuilder<U,R>
appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder.MultiAddressHttpClientBuilder<U,R>
appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder, for every request that passes the providedPredicate
.abstract MultiAddressHttpClientBuilder<U,R>
autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
Updates the automatic retry strategy for the clients generated by this builder.abstract MultiAddressHttpClientBuilder<U,R>
bufferAllocator(BufferAllocator allocator)
Sets theBufferAllocator
for all connections created from this builder.HttpClient
build()
Builds a newHttpClient
, using a defaultExecutionContext
.BlockingHttpClient
buildBlocking()
Creates a newBlockingHttpClient
, using a defaultExecutionContext
.BlockingStreamingHttpClient
buildBlockingStreaming()
Creates a newBlockingStreamingHttpClient
, using a defaultExecutionContext
.abstract StreamingHttpClient
buildStreaming()
Builds a newStreamingHttpClient
, using a defaultExecutionContext
.abstract MultiAddressHttpClientBuilder<U,R>
disableHostHeaderFallback()
Disables automatically settingHost
headers by inferring from the address orHttpMetaData
.abstract MultiAddressHttpClientBuilder<U,R>
enableWireLogging(java.lang.String loggerName)
Deprecated.abstract MultiAddressHttpClientBuilder<U,R>
enableWireLogging(java.lang.String loggerName, LogLevel logLevel, java.util.function.BooleanSupplier logUserData)
Enables wire-logging for connections created by this builder.abstract MultiAddressHttpClientBuilder<U,R>
executionStrategy(HttpExecutionStrategy strategy)
Sets theHttpExecutionStrategy
for all connections created from this builder.abstract MultiAddressHttpClientBuilder<U,R>
ioExecutor(IoExecutor ioExecutor)
Sets theIoExecutor
for all connections created from this builder.abstract MultiAddressHttpClientBuilder<U,R>
loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory)
Sets aHttpLoadBalancerFactory
to createLoadBalancer
instances.abstract MultiAddressHttpClientBuilder<U,R>
maxRedirects(int maxRedirects)
Sets a maximum number of redirects to follow.abstract MultiAddressHttpClientBuilder<U,R>
protocols(HttpProtocolConfig... protocols)
Configurations of various HTTP protocol versions.abstract MultiAddressHttpClientBuilder<U,R>
retryServiceDiscoveryErrors(ServiceDiscoveryRetryStrategy<R,ServiceDiscovererEvent<R>> retryStrategy)
Sets a retry strategy to retry errors emitted byServiceDiscoverer
.abstract MultiAddressHttpClientBuilder<U,R>
secure(java.util.function.BiConsumer<HostAndPort,ClientSecurityConfigurator> sslConfigFunction)
Sets a function that is used for configuring SSL/TLS for https requests.abstract MultiAddressHttpClientBuilder<U,R>
serviceDiscoverer(ServiceDiscoverer<U,R,ServiceDiscovererEvent<R>> serviceDiscoverer)
Sets aServiceDiscoverer
to resolve addresses of remote servers to connect to.abstract <T> MultiAddressHttpClientBuilder<U,R>
socketOption(java.net.SocketOption<T> option, T value)
Adds aSocketOption
for all connections created by this builder.abstract MultiAddressHttpClientBuilder<U,R>
unresolvedAddressToHost(java.util.function.Function<U,java.lang.CharSequence> unresolvedAddressToHostFunction)
Provides a means to convertHttpClientBuilder
unresolved address type into aCharSequence
.
-
-
-
Method Detail
-
ioExecutor
public abstract MultiAddressHttpClientBuilder<U,R> ioExecutor(IoExecutor ioExecutor)
Sets theIoExecutor
for all connections created from this builder.- Parameters:
ioExecutor
-IoExecutor
to use.- Returns:
this
.
-
executionStrategy
public abstract MultiAddressHttpClientBuilder<U,R> executionStrategy(HttpExecutionStrategy strategy)
Sets theHttpExecutionStrategy
for all connections created from this builder.- Parameters:
strategy
-HttpExecutionStrategy
to use.- Returns:
this
.
-
bufferAllocator
public abstract MultiAddressHttpClientBuilder<U,R> bufferAllocator(BufferAllocator allocator)
Sets theBufferAllocator
for all connections created from this builder.- Parameters:
allocator
-BufferAllocator
to use.- Returns:
this
.
-
socketOption
public abstract <T> MultiAddressHttpClientBuilder<U,R> socketOption(java.net.SocketOption<T> option, T value)
Adds aSocketOption
for all connections created by this builder.- Type Parameters:
T
- the type of the value.- Parameters:
option
- the option to apply.value
- the value.- Returns:
this
.- See Also:
StandardSocketOptions
,ServiceTalkSocketOptions
-
enableWireLogging
@Deprecated public abstract MultiAddressHttpClientBuilder<U,R> enableWireLogging(java.lang.String loggerName)
Deprecated.Enables wire-logging for connections created by this builder.- Parameters:
loggerName
- The name of the logger to log wire events.- Returns:
this
.
-
enableWireLogging
public abstract MultiAddressHttpClientBuilder<U,R> enableWireLogging(java.lang.String loggerName, LogLevel logLevel, java.util.function.BooleanSupplier logUserData)
Enables wire-logging for connections created by this builder.- Parameters:
loggerName
- The name of the logger to log wire events.logLevel
- The level to log at.logUserData
-true
to include user data (e.g. data, headers, etc.).false
to exclude user data and log only network events.- Returns:
this
.
-
protocols
public abstract MultiAddressHttpClientBuilder<U,R> protocols(HttpProtocolConfig... protocols)
Configurations of various HTTP protocol versions.Note: the order of specified protocols will reflect on priorities for ALPN in case the connections are secured.
- Parameters:
protocols
-HttpProtocolConfig
for each protocol that should be supported.- Returns:
this
.
-
disableHostHeaderFallback
public abstract MultiAddressHttpClientBuilder<U,R> disableHostHeaderFallback()
Disables automatically settingHost
headers by inferring from the address orHttpMetaData
.This setting disables the default filter such that no
Host
header will be manipulated.- Returns:
this
- See Also:
unresolvedAddressToHost(Function)
-
secure
public abstract MultiAddressHttpClientBuilder<U,R> secure(java.util.function.BiConsumer<HostAndPort,ClientSecurityConfigurator> sslConfigFunction)
Sets a function that is used for configuring SSL/TLS for https requests.- Parameters:
sslConfigFunction
- The function to use for configuring SSL/TLS for https requests.- Returns:
this
-
appendConnectionFilter
public abstract MultiAddressHttpClientBuilder<U,R> appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder.Filtering allows you to wrap a
StreamingHttpConnection
and modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => connection
- Parameters:
factory
-StreamingHttpConnectionFilterFactory
to decorate aStreamingHttpConnection
for the purpose of filtering.- Returns:
this
-
appendConnectionFilter
public MultiAddressHttpClientBuilder<U,R> appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder, for every request that passes the providedPredicate
.Filtering allows you to wrap a
StreamingHttpConnection
and modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => connection
- Parameters:
predicate
- thePredicate
to test if the filter must be applied.factory
-StreamingHttpConnectionFilterFactory
to decorate aStreamingHttpConnection
for the purpose of filtering.- Returns:
this
-
appendConnectionFactoryFilter
public abstract MultiAddressHttpClientBuilder<U,R> appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
Appends the filter to the chain of filters used to decorate theConnectionFactory
used by this builder.Filtering allows you to wrap a
ConnectionFactory
and modify behavior ofConnectionFactory.newConnection(Object, TransportObserver)
. Some potential candidates for filtering include logging and metrics.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
CallingConnectionFactory
wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3 => original connection factory
- Parameters:
factory
-ConnectionFactoryFilter
to use.- Returns:
this
-
autoRetryStrategy
public abstract MultiAddressHttpClientBuilder<U,R> autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
Updates the automatic retry strategy for the clients generated by this builder. Automatic retries are done by the clients automatically when allowed by the passedAutoRetryStrategyProvider
. These retries are not a substitute for user level retries which are designed to infer retry decisions based on request/error information. Typically such user level retries are done using filters (eg:appendClientFilter(StreamingHttpClientFilterFactory)
) but can also be done differently per request (eg: by usingSingle.retry(BiIntPredicate)
).- Parameters:
autoRetryStrategyProvider
-AutoRetryStrategyProvider
for the automatic retry strategy.- Returns:
this
-
serviceDiscoverer
public abstract MultiAddressHttpClientBuilder<U,R> serviceDiscoverer(ServiceDiscoverer<U,R,ServiceDiscovererEvent<R>> serviceDiscoverer)
Sets aServiceDiscoverer
to resolve addresses of remote servers to connect to.- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. Lifecycle of the providedServiceDiscoverer
is managed externally and it should beclosed
after all builtStreamingHttpClient
s will be closed and thisServiceDiscoverer
is no longer needed.- Returns:
this
.
-
retryServiceDiscoveryErrors
public abstract MultiAddressHttpClientBuilder<U,R> retryServiceDiscoveryErrors(ServiceDiscoveryRetryStrategy<R,ServiceDiscovererEvent<R>> retryStrategy)
Sets a retry strategy to retry errors emitted byServiceDiscoverer
.- Parameters:
retryStrategy
- a retry strategy to retry errors emitted byServiceDiscoverer
.- Returns:
this
.
-
loadBalancerFactory
public abstract MultiAddressHttpClientBuilder<U,R> loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory)
Sets aHttpLoadBalancerFactory
to createLoadBalancer
instances.- Parameters:
loadBalancerFactory
-HttpLoadBalancerFactory
to createLoadBalancer
instances.- Returns:
this
.
-
unresolvedAddressToHost
public abstract MultiAddressHttpClientBuilder<U,R> unresolvedAddressToHost(java.util.function.Function<U,java.lang.CharSequence> unresolvedAddressToHostFunction)
Provides a means to convertHttpClientBuilder
unresolved address type into aCharSequence
. An example of where this maybe used is to convert theHttpClientBuilder
to a default host header. It may also be used in the event of proxying.- Parameters:
unresolvedAddressToHostFunction
- invoked to convert theHttpClientBuilder
unresolved address type into aCharSequence
suitable for use in Host Header format.- Returns:
this
-
appendClientFilter
public abstract MultiAddressHttpClientBuilder<U,R> appendClientFilter(StreamingHttpClientFilterFactory factory)
Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder.Note this method will be used to decorate the result of
build()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => client
- Parameters:
factory
-StreamingHttpClientFilterFactory
to decorate aHttpClient
for the purpose of filtering.- Returns:
this
-
appendClientFilter
public MultiAddressHttpClientBuilder<U,R> appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory)
Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder, for every request that passes the providedPredicate
.Note this method will be used to decorate the result of
build()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => client
- Parameters:
predicate
- thePredicate
to test if the filter must be applied.factory
-StreamingHttpClientFilterFactory
to decorate aHttpClient
for the purpose of filtering.- Returns:
this
-
appendClientFilter
public abstract MultiAddressHttpClientBuilder<U,R> appendClientFilter(MultiAddressHttpClientFilterFactory<U> factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpClient
created by this builder for a givenUnresolvedAddress
.Note this method will be used to decorate the result of
buildStreaming()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
Making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => client
- Parameters:
factory
-MultiAddressHttpClientFilterFactory
to decorate aStreamingHttpClient
for the purpose of filtering.- Returns:
this
-
appendClientFilter
public MultiAddressHttpClientBuilder<U,R> appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, MultiAddressHttpClientFilterFactory<U> factory)
Appends the filter to the chain of filters used to decorate theStreamingHttpClient
created by this builder for a givenUnresolvedAddress
, for every request that passes the providedPredicate
.Note this method will be used to decorate the result of
buildStreaming()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)
Making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 => filter2 => filter3 => client
- Parameters:
predicate
- thePredicate
to test if the filter must be applied.factory
-MultiAddressHttpClientFilterFactory
to decorate aStreamingHttpClient
for the purpose of filtering.- Returns:
this
-
maxRedirects
public abstract MultiAddressHttpClientBuilder<U,R> maxRedirects(int maxRedirects)
Sets a maximum number of redirects to follow.- Parameters:
maxRedirects
- A maximum number of redirects to follow.0
disables redirects.- Returns:
this
.
-
buildStreaming
public abstract StreamingHttpClient buildStreaming()
Builds a newStreamingHttpClient
, using a defaultExecutionContext
.- Returns:
- A new
StreamingHttpClient
-
build
public final HttpClient build()
Builds a newHttpClient
, using a defaultExecutionContext
.- Returns:
- A new
HttpClient
-
buildBlockingStreaming
public final BlockingStreamingHttpClient buildBlockingStreaming()
Creates a newBlockingStreamingHttpClient
, using a defaultExecutionContext
.- Returns:
BlockingStreamingHttpClient
-
buildBlocking
public final BlockingHttpClient buildBlocking()
Creates a newBlockingHttpClient
, using a defaultExecutionContext
.- Returns:
BlockingHttpClient
-
-