Package com.linecorp.armeria.client
Class ClientOptionsBuilder
java.lang.Object
com.linecorp.armeria.client.AbstractClientOptionsBuilder
com.linecorp.armeria.client.ClientOptionsBuilder
public final class ClientOptionsBuilder extends AbstractClientOptionsBuilder
Creates a new
ClientOptions
using the builder pattern.- See Also:
ClientBuilder
-
Method Summary
Modifier and Type Method Description ClientOptionsBuilder
addHeader(CharSequence name, Object value)
Adds the specified HTTP header.ClientOptionsBuilder
addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Adds the specified HTTP headers.ClientOptionsBuilder
auth(BasicToken token)
Sets the HTTP basic access authentication header usingHttpHeaderNames.AUTHORIZATION
.ClientOptionsBuilder
auth(OAuth1aToken token)
Sets the OAuth Core 1.0 Revision A header usingHttpHeaderNames.AUTHORIZATION
.ClientOptionsBuilder
auth(OAuth2Token token)
Sets the OAuth 2.0 header usingHttpHeaderNames.AUTHORIZATION
.ClientOptions
build()
Returns a newly-createdClientOptions
based on theClientOptionValue
s of this builder.ClientOptionsBuilder
clearDecorators()
Clears all HTTP-level and RPC-level decorators set so far.ClientOptionsBuilder
decorator(DecoratingHttpClientFunction decorator)
Adds the specified HTTP-leveldecorator
.ClientOptionsBuilder
decorator(Function<? super HttpClient,? extends HttpClient> decorator)
Adds the specified HTTP-leveldecorator
.ClientOptionsBuilder
endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)
ClientOptionsBuilder
factory(ClientFactory factory)
Sets theClientFactory
used for creating a client.ClientOptionsBuilder
maxResponseLength(long maxResponseLength)
Sets the maximum allowed length of a server response in bytes.<T> ClientOptionsBuilder
option(ClientOption<T> option, T value)
Adds the specifiedClientOption
and itsvalue
.<T> ClientOptionsBuilder
option(ClientOptionValue<T> optionValue)
Adds the specifiedClientOptionValue
.ClientOptionsBuilder
options(ClientOptions options)
Adds the specifiedClientOptions
.ClientOptionsBuilder
options(ClientOptionValue<?>... options)
Adds the specifiedClientOptionValue
s.ClientOptionsBuilder
options(Iterable<ClientOptionValue<?>> options)
Adds the specifiedClientOptionValue
s.ClientOptionsBuilder
requestIdGenerator(Supplier<RequestId> requestIdGenerator)
ClientOptionsBuilder
responseTimeout(Duration responseTimeout)
Sets the timeout of a response.ClientOptionsBuilder
responseTimeoutMillis(long responseTimeoutMillis)
Sets the timeout of a response in milliseconds.ClientOptionsBuilder
rpcDecorator(DecoratingRpcClientFunction decorator)
Adds the specified RPC-leveldecorator
.ClientOptionsBuilder
rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)
Adds the specified RPC-leveldecorator
.ClientOptionsBuilder
setHeader(CharSequence name, Object value)
Sets the specified HTTP header.ClientOptionsBuilder
setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Sets the specified HTTP headers.ClientOptionsBuilder
writeTimeout(Duration writeTimeout)
Sets the timeout of a socket write attempt.ClientOptionsBuilder
writeTimeoutMillis(long writeTimeoutMillis)
Sets the timeout of a socket write attempt in milliseconds.Methods inherited from class com.linecorp.armeria.client.AbstractClientOptionsBuilder
buildOptions, buildOptions
-
Method Details
-
build
Returns a newly-createdClientOptions
based on theClientOptionValue
s of this builder. -
options
Description copied from class:AbstractClientOptionsBuilder
Adds the specifiedClientOptions
.- Overrides:
options
in classAbstractClientOptionsBuilder
-
options
Description copied from class:AbstractClientOptionsBuilder
Adds the specifiedClientOptionValue
s.- Overrides:
options
in classAbstractClientOptionsBuilder
-
options
Description copied from class:AbstractClientOptionsBuilder
Adds the specifiedClientOptionValue
s.- Overrides:
options
in classAbstractClientOptionsBuilder
-
option
Description copied from class:AbstractClientOptionsBuilder
Adds the specifiedClientOption
and itsvalue
.- Overrides:
option
in classAbstractClientOptionsBuilder
-
option
Description copied from class:AbstractClientOptionsBuilder
Adds the specifiedClientOptionValue
.- Overrides:
option
in classAbstractClientOptionsBuilder
-
factory
Description copied from class:AbstractClientOptionsBuilder
Sets theClientFactory
used for creating a client. The default isClientFactory.ofDefault()
.- Overrides:
factory
in classAbstractClientOptionsBuilder
-
writeTimeout
Description copied from class:AbstractClientOptionsBuilder
Sets the timeout of a socket write attempt.- Overrides:
writeTimeout
in classAbstractClientOptionsBuilder
- Parameters:
writeTimeout
- the timeout.0
disables the timeout.
-
writeTimeoutMillis
Description copied from class:AbstractClientOptionsBuilder
Sets the timeout of a socket write attempt in milliseconds.- Overrides:
writeTimeoutMillis
in classAbstractClientOptionsBuilder
- Parameters:
writeTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
responseTimeout
Description copied from class:AbstractClientOptionsBuilder
Sets the timeout of a response.- Overrides:
responseTimeout
in classAbstractClientOptionsBuilder
- Parameters:
responseTimeout
- the timeout.0
disables the timeout.
-
responseTimeoutMillis
Description copied from class:AbstractClientOptionsBuilder
Sets the timeout of a response in milliseconds.- Overrides:
responseTimeoutMillis
in classAbstractClientOptionsBuilder
- Parameters:
responseTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
maxResponseLength
Description copied from class:AbstractClientOptionsBuilder
Sets the maximum allowed length of a server response in bytes.- Overrides:
maxResponseLength
in classAbstractClientOptionsBuilder
- Parameters:
maxResponseLength
- the maximum length in bytes.0
disables the limit.
-
requestIdGenerator
Description copied from class:AbstractClientOptionsBuilder
- Overrides:
requestIdGenerator
in classAbstractClientOptionsBuilder
-
endpointRemapper
public ClientOptionsBuilder endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)Description copied from class:AbstractClientOptionsBuilder
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.
- Overrides:
endpointRemapper
in classAbstractClientOptionsBuilder
- See Also:
ClientOptions.ENDPOINT_REMAPPER
,ClientOptions.endpointRemapper()
-
decorator
public ClientOptionsBuilder decorator(Function<? super HttpClient,? extends HttpClient> decorator)Description copied from class:AbstractClientOptionsBuilder
Adds the specified HTTP-leveldecorator
.- Overrides:
decorator
in classAbstractClientOptionsBuilder
- Parameters:
decorator
- theFunction
that transforms anHttpClient
to another
-
decorator
Description copied from class:AbstractClientOptionsBuilder
Adds the specified HTTP-leveldecorator
.- Overrides:
decorator
in classAbstractClientOptionsBuilder
- Parameters:
decorator
- theDecoratingHttpClientFunction
that intercepts an invocation
-
clearDecorators
Description copied from class:AbstractClientOptionsBuilder
Clears all HTTP-level and RPC-level decorators set so far.- Overrides:
clearDecorators
in classAbstractClientOptionsBuilder
-
rpcDecorator
public ClientOptionsBuilder rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)Description copied from class:AbstractClientOptionsBuilder
Adds the specified RPC-leveldecorator
.- Overrides:
rpcDecorator
in classAbstractClientOptionsBuilder
- Parameters:
decorator
- theFunction
that transforms anRpcClient
to another
-
rpcDecorator
Description copied from class:AbstractClientOptionsBuilder
Adds the specified RPC-leveldecorator
.- Overrides:
rpcDecorator
in classAbstractClientOptionsBuilder
- Parameters:
decorator
- theDecoratingRpcClientFunction
that intercepts an invocation
-
addHeader
Description copied from class:AbstractClientOptionsBuilder
Adds the specified HTTP header.- Overrides:
addHeader
in classAbstractClientOptionsBuilder
-
addHeaders
public ClientOptionsBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)Description copied from class:AbstractClientOptionsBuilder
Adds the specified HTTP headers.- Overrides:
addHeaders
in classAbstractClientOptionsBuilder
-
setHeader
Description copied from class:AbstractClientOptionsBuilder
Sets the specified HTTP header.- Overrides:
setHeader
in classAbstractClientOptionsBuilder
-
setHeaders
public ClientOptionsBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)Description copied from class:AbstractClientOptionsBuilder
Sets the specified HTTP headers.- Overrides:
setHeaders
in classAbstractClientOptionsBuilder
-
auth
Description copied from class:AbstractClientOptionsBuilder
Sets the HTTP basic access authentication header usingHttpHeaderNames.AUTHORIZATION
.- Overrides:
auth
in classAbstractClientOptionsBuilder
-
auth
Description copied from class:AbstractClientOptionsBuilder
Sets the OAuth Core 1.0 Revision A header usingHttpHeaderNames.AUTHORIZATION
.- Overrides:
auth
in classAbstractClientOptionsBuilder
-
auth
Description copied from class:AbstractClientOptionsBuilder
Sets the OAuth 2.0 header usingHttpHeaderNames.AUTHORIZATION
.- Overrides:
auth
in classAbstractClientOptionsBuilder
-