Package com.linecorp.armeria.client
Class AbstractClientOptionsBuilder
java.lang.Object
com.linecorp.armeria.client.AbstractClientOptionsBuilder
- Direct Known Subclasses:
AbstractWebClientBuilder
,ArmeriaRetrofitBuilder
,ClientBuilder
,ClientOptionsBuilder
A skeletal builder implementation for
ClientOptions
.-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new instance.protected
AbstractClientOptionsBuilder(ClientOptions options)
Creates a new instance with the specified base options. -
Method Summary
Modifier and TypeMethodDescriptionaddHeader(CharSequence name, Object value)
Adds the specified HTTP header.addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Adds the specified HTTP headers.auth(BasicToken token)
Sets the HTTP basic access authentication header usingHttpHeaderNames.AUTHORIZATION
.auth(OAuth1aToken token)
Sets the OAuth Core 1.0 Revision A header usingHttpHeaderNames.AUTHORIZATION
.auth(OAuth2Token token)
Sets the OAuth 2.0 header usingHttpHeaderNames.AUTHORIZATION
.protected ClientOptions
BuildsClientOptions
with the given options and the default options.protected ClientOptions
buildOptions(@Nullable ClientOptions baseOptions)
BuildsClientOptions
with the specifiedbaseOptions
and the options which were set to this builder.Clears all HTTP-level and RPC-level decorators set so far.decorator(DecoratingHttpClientFunction decorator)
Adds the specified HTTP-leveldecorator
.decorator(Function<? super HttpClient,? extends HttpClient> decorator)
Adds the specified HTTP-leveldecorator
.endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)
factory(ClientFactory factory)
Sets theClientFactory
used for creating a client.Enables automatic redirection.followRedirects(RedirectConfig redirectConfig)
Sets theRedirectConfig
to enable automatic redirection.maxResponseLength(long maxResponseLength)
Sets the maximum allowed length of a server response in bytes.option(ClientOption<T> option, T value)
Adds the specifiedClientOption
and itsvalue
.option(ClientOptionValue<T> optionValue)
Adds the specifiedClientOptionValue
.options(ClientOptions options)
Adds the specifiedClientOptions
.options(ClientOptionValue<?>... options)
Adds the specifiedClientOptionValue
s.options(Iterable<ClientOptionValue<?>> options)
Adds the specifiedClientOptionValue
s.requestIdGenerator(Supplier<RequestId> requestIdGenerator)
responseTimeout(Duration responseTimeout)
Sets the timeout of a response.responseTimeoutMillis(long responseTimeoutMillis)
Sets the timeout of a response in milliseconds.rpcDecorator(DecoratingRpcClientFunction decorator)
Adds the specified RPC-leveldecorator
.rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)
Adds the specified RPC-leveldecorator
.setHeader(CharSequence name, Object value)
Sets the specified HTTP header.setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Sets the specified HTTP headers.writeTimeout(Duration writeTimeout)
Sets the timeout of a socket write attempt.writeTimeoutMillis(long writeTimeoutMillis)
Sets the timeout of a socket write attempt in milliseconds.
-
Constructor Details
-
AbstractClientOptionsBuilder
protected AbstractClientOptionsBuilder()Creates a new instance. -
AbstractClientOptionsBuilder
Creates a new instance with the specified base options.
-
-
Method Details
-
options
Adds the specifiedClientOptions
. -
options
Adds the specifiedClientOptionValue
s. -
options
Adds the specifiedClientOptionValue
s. -
option
Adds the specifiedClientOption
and itsvalue
. -
option
Adds the specifiedClientOptionValue
. -
factory
Sets theClientFactory
used for creating a client. The default isClientFactory.ofDefault()
. -
writeTimeout
Sets the timeout of a socket write attempt.- Parameters:
writeTimeout
- the timeout.0
disables the timeout.
-
writeTimeoutMillis
Sets the timeout of a socket write attempt in milliseconds.- Parameters:
writeTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
responseTimeout
Sets the timeout of a response.- Parameters:
responseTimeout
- the timeout.0
disables the timeout.
-
responseTimeoutMillis
Sets the timeout of a response in milliseconds.- Parameters:
responseTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
maxResponseLength
Sets the maximum allowed length of a server response in bytes.- Parameters:
maxResponseLength
- the maximum length in bytes.0
disables the limit.
-
requestIdGenerator
-
endpointRemapper
public AbstractClientOptionsBuilder endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)Sets aFunction
that remaps anEndpoint
into anEndpointGroup
. ThisClientOption
is useful when you need to override a single target host into a group of hosts to enable client-side load-balancing, e.g.MyService.Iface client = Clients.newClient("tbinary+http://example.com/api", MyService.Iface.class); EndpointGroup myGroup = EndpointGroup.of(Endpoint.of("node-1.example.com")), Endpoint.of("node-2.example.com"))); MyService.Iface derivedClient = Clients.newDerivedClient(client, options -> { return options.toBuilder() .endpointRemapper(endpoint -> { if (endpoint.host().equals("example.com")) { return myGroup; } else { return endpoint; } }) .build(); }); // This request goes to 'node-1.example.com' or 'node-2.example.com'. derivedClient.call();
Note that the remapping does not occur recursively but only once.
-
decorator
public AbstractClientOptionsBuilder decorator(Function<? super HttpClient,? extends HttpClient> decorator)Adds the specified HTTP-leveldecorator
.- Parameters:
decorator
- theFunction
that transforms anHttpClient
to another
-
decorator
Adds the specified HTTP-leveldecorator
.- Parameters:
decorator
- theDecoratingHttpClientFunction
that intercepts an invocation
-
clearDecorators
Clears all HTTP-level and RPC-level decorators set so far. -
rpcDecorator
public AbstractClientOptionsBuilder rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)Adds the specified RPC-leveldecorator
. -
rpcDecorator
Adds the specified RPC-leveldecorator
.- Parameters:
decorator
- theDecoratingRpcClientFunction
that intercepts an invocation
-
addHeader
Adds the specified HTTP header. -
addHeaders
public AbstractClientOptionsBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)Adds the specified HTTP headers. -
setHeader
Sets the specified HTTP header. -
setHeaders
public AbstractClientOptionsBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)Sets the specified HTTP headers. -
auth
Sets the HTTP basic access authentication header usingHttpHeaderNames.AUTHORIZATION
. -
auth
Sets the OAuth Core 1.0 Revision A header usingHttpHeaderNames.AUTHORIZATION
. -
auth
Sets the OAuth 2.0 header usingHttpHeaderNames.AUTHORIZATION
. -
followRedirects
Enables automatic redirection. -
followRedirects
Sets theRedirectConfig
to enable automatic redirection. -
buildOptions
BuildsClientOptions
with the given options and the default options. -
buildOptions
BuildsClientOptions
with the specifiedbaseOptions
and the options which were set to this builder.
-