U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)public abstract class PartitionedHttpClientBuilder<U,R>
extends java.lang.Object
StreamingHttpClient
instances which call the server associated with a partition
selected from a set of PartitionedServiceDiscovererEvent
s resolved from a single unresolved address.
Partition selection uses a function to infer PartitionAttributes
from the HttpRequestMetaData
.
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.
Constructor and Description |
---|
PartitionedHttpClientBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract PartitionedHttpClientBuilder<U,R> |
appendClientBuilderFilter(PartitionHttpClientBuilderConfigurator<U,R> clientFilterFunction)
Sets a function that allows customizing the
SingleAddressHttpClientBuilder used to create the client for
a given partition based on its PartitionAttributes . |
PartitionedHttpClientBuilder<U,R> |
appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate,
StreamingHttpClientFilterFactory factory)
Appends the filter to the chain of filters used to decorate the
HttpClient created by this
builder, for every request that passes the provided Predicate . |
abstract PartitionedHttpClientBuilder<U,R> |
appendClientFilter(StreamingHttpClientFilterFactory function)
Appends the filter to the chain of filters used to decorate the
HttpClient created by this
builder. |
abstract PartitionedHttpClientBuilder<U,R> |
appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
Appends the filter to the chain of filters used to decorate the
ConnectionFactory used by this
builder. |
PartitionedHttpClientBuilder<U,R> |
appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate,
StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate the
StreamingHttpConnection created by this
builder, for every request that passes the provided Predicate . |
abstract PartitionedHttpClientBuilder<U,R> |
appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
Appends the filter to the chain of filters used to decorate the
StreamingHttpConnection created by this
builder. |
abstract PartitionedHttpClientBuilder<U,R> |
autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
Updates the automatic retry strategy for the clients generated by this builder.
|
abstract PartitionedHttpClientBuilder<U,R> |
bufferAllocator(BufferAllocator allocator)
Sets the
BufferAllocator for all connections created from this builder. |
HttpClient |
build()
Builds a new
HttpClient , using a default ExecutionContext . |
BlockingHttpClient |
buildBlocking()
Creates a new
BlockingHttpClient , using a default ExecutionContext . |
BlockingStreamingHttpClient |
buildBlockingStreaming()
Creates a new
BlockingStreamingHttpClient , using a default ExecutionContext . |
abstract StreamingHttpClient |
buildStreaming()
Builds a new
StreamingHttpClient , using a default ExecutionContext . |
abstract PartitionedHttpClientBuilder<U,R> |
disableHostHeaderFallback()
Disables automatically setting
Host headers by inferring from the address or HttpMetaData . |
abstract PartitionedHttpClientBuilder<U,R> |
enableWireLogging(java.lang.String loggerName)
Enables wire-logging for connections created by this builder.
|
abstract PartitionedHttpClientBuilder<U,R> |
executionStrategy(HttpExecutionStrategy strategy)
Sets the
HttpExecutionStrategy for all connections created from this builder. |
abstract PartitionedHttpClientBuilder<U,R> |
ioExecutor(IoExecutor ioExecutor)
Sets the
IoExecutor for all connections created from this builder. |
abstract PartitionedHttpClientBuilder<U,R> |
loadBalancerFactory(LoadBalancerFactory<R,FilterableStreamingHttpLoadBalancedConnection> loadBalancerFactory,
java.util.function.Function<FilterableStreamingHttpConnection,FilterableStreamingHttpLoadBalancedConnection> protocolBinder)
Sets a
LoadBalancerFactory to generate LoadBalancer objects. |
abstract PartitionedHttpClientBuilder<U,R> |
partitionMapFactory(PartitionMapFactory partitionMapFactory)
Sets
PartitionMapFactory to use by all StreamingHttpClient s created by this builder. |
abstract PartitionedHttpClientBuilder<U,R> |
protocols(HttpProtocolConfig... protocols)
Configurations of various HTTP protocol versions.
|
abstract PartitionedHttpClientSecurityConfigurator<U,R> |
secure()
Initiates security configuration for this client.
|
abstract PartitionedHttpClientBuilder<U,R> |
serviceDiscoverer(ServiceDiscoverer<U,R,? extends PartitionedServiceDiscovererEvent<R>> serviceDiscoverer)
Sets a
ServiceDiscoverer to resolve addresses of remote servers to connect to. |
abstract PartitionedHttpClientBuilder<U,R> |
serviceDiscoveryMaxQueueSize(int serviceDiscoveryMaxQueueSize)
Sets the maximum amount of
ServiceDiscovererEvent objects that will be queued for each partition. |
abstract <T> PartitionedHttpClientBuilder<U,R> |
socketOption(java.net.SocketOption<T> option,
T value)
Adds a
SocketOption for all connections created by this builder. |
abstract PartitionedHttpClientBuilder<U,R> |
unresolvedAddressToHost(java.util.function.Function<U,java.lang.CharSequence> unresolvedAddressToHostFunction)
Provides a means to convert
U unresolved address type into a CharSequence . |
public abstract PartitionedHttpClientBuilder<U,R> ioExecutor(IoExecutor ioExecutor)
IoExecutor
for all connections created from this builder.ioExecutor
- IoExecutor
to use.this
.public abstract PartitionedHttpClientBuilder<U,R> executionStrategy(HttpExecutionStrategy strategy)
HttpExecutionStrategy
for all connections created from this builder.strategy
- HttpExecutionStrategy
to use.this
.public abstract PartitionedHttpClientBuilder<U,R> bufferAllocator(BufferAllocator allocator)
BufferAllocator
for all connections created from this builder.allocator
- BufferAllocator
to use.this
.public abstract <T> PartitionedHttpClientBuilder<U,R> socketOption(java.net.SocketOption<T> option, T value)
SocketOption
for all connections created by this builder.T
- the type of the value.option
- the option to apply.value
- the value.this
.StandardSocketOptions
,
ServiceTalkSocketOptions
public abstract PartitionedHttpClientBuilder<U,R> enableWireLogging(java.lang.String loggerName)
All wire events will be logged at TRACE
level.
loggerName
- The name of the logger to log wire events.this
.public abstract PartitionedHttpClientBuilder<U,R> protocols(HttpProtocolConfig... protocols)
Note: the order of specified protocols will reflect on priorities for ALPN in case the connections are secured.
protocols
- HttpProtocolConfig
for each protocol that should be supported.this
.public abstract PartitionedHttpClientBuilder<U,R> appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
StreamingHttpConnection
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
factory
- StreamingHttpConnectionFilterFactory
to decorate a StreamingHttpConnection
for the
purpose of filtering.this
public PartitionedHttpClientBuilder<U,R> appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory)
StreamingHttpConnection
created by this
builder, for every request that passes the provided Predicate
.
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
predicate
- the Predicate
to test if the filter must be applied.factory
- StreamingHttpConnectionFilterFactory
to decorate a StreamingHttpConnection
for the
purpose of filtering.this
public abstract PartitionedHttpClientBuilder<U,R> appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
ConnectionFactory
used by this
builder.
Filtering allows you to wrap a ConnectionFactory
and modify behavior of
ConnectionFactory.newConnection(Object)
.
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)Calling
ConnectionFactory
wrapped by this filter chain, the order of invocation of these filters will be:
filter1 => filter2 => filter3 => original connection factory
factory
- ConnectionFactoryFilter
to use.this
public abstract PartitionedHttpClientBuilder<U,R> disableHostHeaderFallback()
Host
headers by inferring from the address or HttpMetaData
.
This setting disables the default filter such that no Host
header will be manipulated.
this
MultiAddressHttpClientBuilder.unresolvedAddressToHost(Function)
public abstract PartitionedHttpClientBuilder<U,R> autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
AutoRetryStrategyProvider
. 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 using Single.retry(BiIntPredicate)
).autoRetryStrategyProvider
- AutoRetryStrategyProvider
for the automatic retry strategy.this
public abstract PartitionedHttpClientBuilder<U,R> serviceDiscoverer(ServiceDiscoverer<U,R,? extends PartitionedServiceDiscovererEvent<R>> serviceDiscoverer)
ServiceDiscoverer
to resolve addresses of remote servers to connect to.serviceDiscoverer
- The ServiceDiscoverer
to resolve addresses of remote servers to connect to.
Lifecycle of the provided ServiceDiscoverer
is managed externally and it should be
closed
after all built StreamingHttpClient
s will be closed and
this ServiceDiscoverer
is no longer needed.this
.public abstract PartitionedHttpClientBuilder<U,R> loadBalancerFactory(LoadBalancerFactory<R,FilterableStreamingHttpLoadBalancedConnection> loadBalancerFactory, java.util.function.Function<FilterableStreamingHttpConnection,FilterableStreamingHttpLoadBalancedConnection> protocolBinder)
LoadBalancerFactory
to generate LoadBalancer
objects.loadBalancerFactory
- The LoadBalancerFactory
which generates LoadBalancer
objects.protocolBinder
- The Function
that bridges the HTTP protocol to the FilterableStreamingHttpLoadBalancedConnection
which exposes a ScoreSupplier.score()
function
which may inform the LoadBalancer
created from the provided loadBalancerFactory
while making
connection selection decisions.this
.public abstract PartitionedHttpClientBuilder<U,R> unresolvedAddressToHost(java.util.function.Function<U,java.lang.CharSequence> unresolvedAddressToHostFunction)
U
unresolved address type into a CharSequence
.
An example of where this maybe used is to convert the U
to a default host header. It may also
be used in the event of proxying.unresolvedAddressToHostFunction
- invoked to convert the U
unresolved address type into a
CharSequence
suitable for use in
Host Header format.this
public abstract PartitionedHttpClientBuilder<U,R> appendClientFilter(StreamingHttpClientFilterFactory function)
HttpClient
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
function
- StreamingHttpClientFilterFactory
to decorate a HttpClient
for the purpose of
filtering.this
public PartitionedHttpClientBuilder<U,R> appendClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory)
HttpClient
created by this
builder, for every request that passes the provided Predicate
.
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
predicate
- the Predicate
to test if the filter must be applied.factory
- StreamingHttpClientFilterFactory
to decorate a HttpClient
for the purpose of
filtering.this
public abstract PartitionedHttpClientSecurityConfigurator<U,R> secure()
PartitionedHttpClientSecurityConfigurator.commit()
on the returned
PartitionedHttpClientSecurityConfigurator
will commit the configuration.PartitionHttpClientBuilderConfigurator
to configure security for this client. It is
mandatory to call commit
after all configuration is
done.public abstract PartitionedHttpClientBuilder<U,R> serviceDiscoveryMaxQueueSize(int serviceDiscoveryMaxQueueSize)
ServiceDiscovererEvent
objects that will be queued for each partition.
It is assumed that the PublisherSource.Subscriber
s will process events in a timely manner (typically synchronously)
so this typically doesn't need to be very large.
serviceDiscoveryMaxQueueSize
- the maximum amount of ServiceDiscovererEvent
objects that will be
queued for each partition.this
.public abstract PartitionedHttpClientBuilder<U,R> partitionMapFactory(PartitionMapFactory partitionMapFactory)
PartitionMapFactory
to use by all StreamingHttpClient
s created by this builder.partitionMapFactory
- PartitionMapFactory
to use.this
.public abstract PartitionedHttpClientBuilder<U,R> appendClientBuilderFilter(PartitionHttpClientBuilderConfigurator<U,R> clientFilterFunction)
SingleAddressHttpClientBuilder
used to create the client for
a given partition based on its PartitionAttributes
.clientFilterFunction
- BiFunction
used to customize the SingleAddressHttpClientBuilder
before creating the client for the partitionthis
public abstract StreamingHttpClient buildStreaming()
StreamingHttpClient
, using a default ExecutionContext
.StreamingHttpClient
public final HttpClient build()
HttpClient
, using a default ExecutionContext
.HttpClient
public final BlockingStreamingHttpClient buildBlockingStreaming()
BlockingStreamingHttpClient
, using a default ExecutionContext
.BlockingStreamingHttpClient
public final BlockingHttpClient buildBlocking()
BlockingHttpClient
, using a default ExecutionContext
.BlockingHttpClient