com.baidubce
Class BceClientConfiguration

java.lang.Object
  extended by com.baidubce.BceClientConfiguration
Direct Known Subclasses:
BccClientConfiguration, BosClientConfiguration, MolaDbClientConfiguration, SesClientConfiguration, SmsClientConfiguration, TagClientConfiguration

@NotThreadSafe
public class BceClientConfiguration
extends Object

Basic client configurations for BCE clients.


Field Summary
static int DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS
          The default timeout for creating new connections.
static int DEFAULT_MAX_CONNECTIONS
          The default max connection pool size.
static Protocol DEFAULT_PROTOCOL
          The default protocol.
static Region DEFAULT_REGION
          The default region.
static int DEFAULT_SOCKET_TIMEOUT_IN_MILLIS
          The default timeout for reading from a connected socket.
static String DEFAULT_USER_AGENT
          The default User-Agent header value when sending requests to the target service.
 
Constructor Summary
BceClientConfiguration()
          Constructs a new BceClientConfiguration instance with default settings.
BceClientConfiguration(BceClientConfiguration other)
          Constructs a new BceClientConfiguration instance with the same settings as the specified configuration.
BceClientConfiguration(BceClientConfiguration other, String endpoint)
          Constructs a new BceClientConfiguration instance with the same settings as the specified configuration.
 
Method Summary
 int getConnectionTimeoutInMillis()
          Returns the connection timeout in milliseconds.
 BceCredentials getCredentials()
          Returns the BCE credentials used by the client to sign HTTP requests.
 String getEndpoint()
          Returns the service endpoint URL to which the client will connect.
 InetAddress getLocalAddress()
          Returns the optional local address to bind when connecting to BCE services.
 int getMaxConnections()
          Returns the maximum number of open HTTP connections.
 Protocol getProtocol()
          Returns the protocol (HTTP/HTTPS) to use when connecting to BCE services.
 String getProxyDomain()
          Returns the optional Windows domain to use when connecting through a Windows NTLM proxy.
 String getProxyHost()
          Returns the optional proxy host the client will connect through.
 String getProxyPassword()
          Returns the optional password to use when connecting through a proxy.
 int getProxyPort()
          Returns the optional proxy port the client will connect through.
 String getProxyUsername()
          Returns the optional user name to use when connecting through a proxy.
 String getProxyWorkstation()
          Returns the optional Windows workstation to use when connecting through a Windows NTLM proxy.
 Region getRegion()
          Returns the region of service.
 RetryPolicy getRetryPolicy()
          Returns the retry policy for failed requests.
 int getSocketBufferSizeInBytes()
          Returns the optional size (in bytes) for the low level TCP socket buffer.
 int getSocketTimeoutInMillis()
          Returns the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets.
 String getUserAgent()
          Returns the User-Agent header value to use when sending requests to BCE services.
 boolean isProxyPreemptiveAuthenticationEnabled()
          Returns whether to enable proxy preemptive authentication.
 void setConnectionTimeoutInMillis(int connectionTimeoutInMillis)
          Sets the connection timeout in milliseconds.
 void setCredentials(BceCredentials credentials)
          Sets the BCE credentials used by the client to sign HTTP requests.
 void setEndpoint(String endpoint)
          Sets the service endpoint URL to which the client will connect.
 void setLocalAddress(InetAddress localAddress)
          Sets the optional local address to bind when connecting to BCE services.
 void setMaxConnections(int maxConnections)
          Sets the maximum number of open HTTP connections.
 void setProtocol(Protocol protocol)
          Sets the protocol (HTTP/HTTPS) to use when connecting to BCE services.
 void setProxyDomain(String proxyDomain)
          Sets the optional Windows domain to use when connecting through a Windows NTLM proxy.
 void setProxyHost(String proxyHost)
          Sets the optional proxy host the client will connect through.
 void setProxyPassword(String proxyPassword)
          Sets the optional password to use when connecting through a proxy.
 void setProxyPort(int proxyPort)
          Sets the optional proxy port the client will connect through.
 void setProxyPreemptiveAuthenticationEnabled(boolean proxyPreemptiveAuthenticationEnabled)
          Sets whether to enable proxy preemptive authentication.
 void setProxyUsername(String proxyUsername)
          Sets the optional user name to use when connecting through a proxy.
 void setProxyWorkstation(String proxyWorkstation)
          Sets the optional Windows workstation to use when connecting through a Windows NTLM proxy.
 void setRegion(Region region)
          Sets the region of service.
 void setRetryPolicy(RetryPolicy retryPolicy)
          Sets the retry policy for failed requests.
 void setSocketBufferSizeInBytes(int socketBufferSizeInBytes)
          Sets the optional size (in bytes) for the low level TCP socket buffer.
 void setSocketTimeoutInMillis(int socketTimeoutInMillis)
          Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets.
 void setUserAgent(String userAgent)
          Sets the User-Agent header value to use when sending requests to BCE services.
 String toString()
           
 BceClientConfiguration withConnectionTimeoutInMillis(int connectionTimeoutInMillis)
          Sets the connection timeout in milliseconds, and returns the updated configuration instance.
 BceClientConfiguration withCredentials(BceCredentials credentials)
          Sets the BCE credentials used by the client to sign HTTP requests, and returns the updated configuration instance.
 BceClientConfiguration withEndpoint(String endpoint)
          Sets the service endpoint URL to which the client will connect, and returns the updated configuration instance.
 BceClientConfiguration withLocalAddress(InetAddress localAddress)
          Sets the optional local address to bind when connecting to BCE services, and returns the updated configuration instance.
 BceClientConfiguration withMaxConnections(int maxConnections)
          Sets the maximum number of open HTTP connections, and returns the updated configuration instance.
 BceClientConfiguration withProtocol(Protocol protocol)
          Sets the protocol (HTTP/HTTPS) to use when connecting to BCE services, and returns the updated configuration instance.
 BceClientConfiguration withProxyDomain(String proxyDomain)
          Sets the optional Windows domain to use when connecting through a Windows NTLM proxy, and returns the updated configuration instance.
 BceClientConfiguration withProxyHost(String proxyHost)
          Sets the optional proxy host the client will connect through, and returns the updated configuration instance.
 BceClientConfiguration withProxyPassword(String proxyPassword)
          Sets the optional password to use when connecting through a proxy, and returns the updated configuration instance.
 BceClientConfiguration withProxyPort(int proxyPort)
          Sets the optional proxy port the client will connect through, and returns the updated configuration instance.
 BceClientConfiguration withProxyPreemptiveAuthenticationEnabled(boolean proxyPreemptiveAuthenticationEnabled)
          Sets whether to enable proxy preemptive authentication, and returns the updated configuration instance.
 BceClientConfiguration withProxyUsername(String proxyUsername)
          Sets the optional user name to use when connecting through a proxy, and returns the updated configuration instance.
 BceClientConfiguration withProxyWorkstation(String proxyWorkstation)
          Sets the optional Windows workstation to use when connecting through a Windows NTLM proxy, and returns the updated configuration instance.
 BceClientConfiguration withRegion(Region region)
          Sets the region of service, and returns the updated configuration instance.
 BceClientConfiguration withRetryPolicy(RetryPolicy retryPolicy)
          Sets the retry policy for failed requests, and returns the updated configuration instance.
 BceClientConfiguration withSocketBufferSizeInBytes(int socketBufferSizeInBytes)
          Sets the optional size (in bytes) for the low level TCP socket buffer, and returns the updated configuration instance.
 BceClientConfiguration withSocketTimeoutInMillis(int socketTimeoutInMillis)
          Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets, and returns the updated configuration instance.
 BceClientConfiguration withUserAgent(String userAgent)
          Sets the User-Agent header value to use when sending requests to BCE services, and returns the updated configuration instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS

public static final int DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS
The default timeout for creating new connections.

See Also:
Constant Field Values

DEFAULT_SOCKET_TIMEOUT_IN_MILLIS

public static final int DEFAULT_SOCKET_TIMEOUT_IN_MILLIS
The default timeout for reading from a connected socket.

See Also:
Constant Field Values

DEFAULT_MAX_CONNECTIONS

public static final int DEFAULT_MAX_CONNECTIONS
The default max connection pool size.

See Also:
Constant Field Values

DEFAULT_USER_AGENT

public static final String DEFAULT_USER_AGENT
The default User-Agent header value when sending requests to the target service. Initialized in the static initializer.


DEFAULT_REGION

public static Region DEFAULT_REGION
The default region.


DEFAULT_PROTOCOL

public static Protocol DEFAULT_PROTOCOL
The default protocol.

Constructor Detail

BceClientConfiguration

public BceClientConfiguration()
Constructs a new BceClientConfiguration instance with default settings.


BceClientConfiguration

public BceClientConfiguration(BceClientConfiguration other)
Constructs a new BceClientConfiguration instance with the same settings as the specified configuration.

Parameters:
other - the configuration to copy settings from.

BceClientConfiguration

public BceClientConfiguration(BceClientConfiguration other,
                              String endpoint)
Constructs a new BceClientConfiguration instance with the same settings as the specified configuration. This constructor is used to create a client configuration from one SDK to another SDK. e.g. from VOD to BOS. In this case endpoint should be changed while other attributes keep same.

Parameters:
other - the configuration to copy settings from.
endpoint - the endpoint
Method Detail

getProtocol

public Protocol getProtocol()
Returns the protocol (HTTP/HTTPS) to use when connecting to BCE services.

Returns:
the protocol (HTTP/HTTPS) to use when connecting to BCE services.

setProtocol

public void setProtocol(Protocol protocol)
Sets the protocol (HTTP/HTTPS) to use when connecting to BCE services.

Parameters:
protocol - the protocol (HTTP/HTTPS) to use when connecting to BCE services.

withProtocol

public BceClientConfiguration withProtocol(Protocol protocol)
Sets the protocol (HTTP/HTTPS) to use when connecting to BCE services, and returns the updated configuration instance.

Parameters:
protocol - the protocol (HTTP/HTTPS) to use when connecting to BCE services.
Returns:
the updated configuration instance.

getMaxConnections

public int getMaxConnections()
Returns the maximum number of open HTTP connections.

Returns:
the maximum number of open HTTP connections.

setMaxConnections

public void setMaxConnections(int maxConnections)
Sets the maximum number of open HTTP connections.

Parameters:
maxConnections - the maximum number of open HTTP connections.
Throws:
IllegalArgumentException - if maxConnections is negative.

withMaxConnections

public BceClientConfiguration withMaxConnections(int maxConnections)
Sets the maximum number of open HTTP connections, and returns the updated configuration instance.

Parameters:
maxConnections - the maximum number of open HTTP connections.
Returns:
the updated configuration instance.
Throws:
IllegalArgumentException - if maxConnections is negative.

getUserAgent

public String getUserAgent()
Returns the User-Agent header value to use when sending requests to BCE services.

Returns:
the User-Agent header value to use when sending requests to BCE services.

setUserAgent

public void setUserAgent(String userAgent)
Sets the User-Agent header value to use when sending requests to BCE services.

If the specified value is null, DEFAULT_USER_AGENT is used. If the specified value does not end with DEFAULT_USER_AGENT, DEFAULT_USER_AGENT is appended.

Parameters:
userAgent - the User-Agent header value to use when sending requests to BCE services.

withUserAgent

public BceClientConfiguration withUserAgent(String userAgent)
Sets the User-Agent header value to use when sending requests to BCE services, and returns the updated configuration instance.

If the specified value is null, DEFAULT_USER_AGENT is used. If the specified value does not end with DEFAULT_USER_AGENT, DEFAULT_USER_AGENT is appended.

Parameters:
userAgent - the User-Agent header value to use when sending requests to BCE services.
Returns:
the updated configuration instance.

getLocalAddress

public InetAddress getLocalAddress()
Returns the optional local address to bind when connecting to BCE services.

Returns:
the optional local address to bind when connecting to BCE services.

setLocalAddress

public void setLocalAddress(InetAddress localAddress)
Sets the optional local address to bind when connecting to BCE services.

Parameters:
localAddress - the optional local address to bind when connecting to BCE services.

withLocalAddress

public BceClientConfiguration withLocalAddress(InetAddress localAddress)
Sets the optional local address to bind when connecting to BCE services, and returns the updated configuration instance.

Parameters:
localAddress - the optional local address to bind when connecting to BCE services.
Returns:
the updated configuration instance.

getProxyHost

public String getProxyHost()
Returns the optional proxy host the client will connect through.

Returns:
the optional proxy host the client will connect through.

setProxyHost

public void setProxyHost(String proxyHost)
Sets the optional proxy host the client will connect through.

The client will connect through the proxy only if the host is not null and the port is positive.

Parameters:
proxyHost - the optional proxy host the client will connect through.

withProxyHost

public BceClientConfiguration withProxyHost(String proxyHost)
Sets the optional proxy host the client will connect through, and returns the updated configuration instance.

The client will connect through the proxy only if the host is not null and the port is positive.

Parameters:
proxyHost - the optional proxy host the client will connect through.
Returns:
the updated configuration instance.

getProxyPort

public int getProxyPort()
Returns the optional proxy port the client will connect through.

Returns:
the optional proxy port the client will connect through.

setProxyPort

public void setProxyPort(int proxyPort)
Sets the optional proxy port the client will connect through.

The client will connect through the proxy only if the host is not null and the port is positive.

Parameters:
proxyPort - the optional proxy port the client will connect through.

withProxyPort

public BceClientConfiguration withProxyPort(int proxyPort)
Sets the optional proxy port the client will connect through, and returns the updated configuration instance.

The client will connect through the proxy only if the host is not null and the port is positive.

Parameters:
proxyPort - the optional proxy port the client will connect through.
Returns:
the updated configuration instance.

getProxyUsername

public String getProxyUsername()
Returns the optional user name to use when connecting through a proxy.

Returns:
the optional user name to use when connecting through a proxy.

setProxyUsername

public void setProxyUsername(String proxyUsername)
Sets the optional user name to use when connecting through a proxy.

Parameters:
proxyUsername - the optional user name to use when connecting through a proxy.

withProxyUsername

public BceClientConfiguration withProxyUsername(String proxyUsername)
Sets the optional user name to use when connecting through a proxy, and returns the updated configuration instance.

Parameters:
proxyUsername - the optional user name to use when connecting through a proxy.
Returns:
the updated configuration instance.

getProxyPassword

public String getProxyPassword()
Returns the optional password to use when connecting through a proxy.

Returns:
the optional password to use when connecting through a proxy.

setProxyPassword

public void setProxyPassword(String proxyPassword)
Sets the optional password to use when connecting through a proxy.

Parameters:
proxyPassword - the optional password to use when connecting through a proxy.

withProxyPassword

public BceClientConfiguration withProxyPassword(String proxyPassword)
Sets the optional password to use when connecting through a proxy, and returns the updated configuration instance.

Parameters:
proxyPassword - the optional password to use when connecting through a proxy.
Returns:
the updated configuration instance.

getProxyDomain

public String getProxyDomain()
Returns the optional Windows domain to use when connecting through a Windows NTLM proxy.

Returns:
the optional Windows domain to use when connecting through a Windows NTLM proxy.

setProxyDomain

public void setProxyDomain(String proxyDomain)
Sets the optional Windows domain to use when connecting through a Windows NTLM proxy.

Parameters:
proxyDomain - the optional Windows domain to use when connecting through a Windows NTLM proxy.

withProxyDomain

public BceClientConfiguration withProxyDomain(String proxyDomain)
Sets the optional Windows domain to use when connecting through a Windows NTLM proxy, and returns the updated configuration instance.

Parameters:
proxyDomain - the optional Windows domain to use when connecting through a Windows NTLM proxy.
Returns:
the updated configuration instance.

getProxyWorkstation

public String getProxyWorkstation()
Returns the optional Windows workstation to use when connecting through a Windows NTLM proxy.

Returns:
the optional Windows workstation to use when connecting through a Windows NTLM proxy.

setProxyWorkstation

public void setProxyWorkstation(String proxyWorkstation)
Sets the optional Windows workstation to use when connecting through a Windows NTLM proxy.

Parameters:
proxyWorkstation - the optional Windows workstation to use when connecting through a Windows NTLM proxy.

withProxyWorkstation

public BceClientConfiguration withProxyWorkstation(String proxyWorkstation)
Sets the optional Windows workstation to use when connecting through a Windows NTLM proxy, and returns the updated configuration instance.

Parameters:
proxyWorkstation - the optional Windows workstation to use when connecting through a Windows NTLM proxy.
Returns:
the updated configuration instance.

isProxyPreemptiveAuthenticationEnabled

public boolean isProxyPreemptiveAuthenticationEnabled()
Returns whether to enable proxy preemptive authentication. If it is true, the client will send the basic authentication response even before the proxy server gives an unauthorized response in certain situations, thus reducing the overhead of making the connection.

Returns:
whether to enable proxy preemptive authentication.

setProxyPreemptiveAuthenticationEnabled

public void setProxyPreemptiveAuthenticationEnabled(boolean proxyPreemptiveAuthenticationEnabled)
Sets whether to enable proxy preemptive authentication. If it is true, the client will send the basic authentication response even before the proxy server gives an unauthorized response in certain situations, thus reducing the overhead of making the connection.

Parameters:
proxyPreemptiveAuthenticationEnabled - whether to enable proxy preemptive authentication.

withProxyPreemptiveAuthenticationEnabled

public BceClientConfiguration withProxyPreemptiveAuthenticationEnabled(boolean proxyPreemptiveAuthenticationEnabled)
Sets whether to enable proxy preemptive authentication, and returns the updated configuration instance. If it is true, the client will send the basic authentication response even before the proxy server gives an unauthorized response in certain situations, thus reducing the overhead of making the connection.

Parameters:
proxyPreemptiveAuthenticationEnabled - whether to enable proxy preemptive authentication.
Returns:
the updated configuration instance.

getRetryPolicy

public RetryPolicy getRetryPolicy()
Returns the retry policy for failed requests.

Returns:
the retry policy for failed requests.

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)
Sets the retry policy for failed requests.

Parameters:
retryPolicy - the retry policy for failed requests.

withRetryPolicy

public BceClientConfiguration withRetryPolicy(RetryPolicy retryPolicy)
Sets the retry policy for failed requests, and returns the updated configuration instance.

Parameters:
retryPolicy - the retry policy for failed requests.
Returns:
the updated configuration instance.

getSocketTimeoutInMillis

public int getSocketTimeoutInMillis()
Returns the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets.

Returns:
the socket timeout (SO_TIMEOUT) in milliseconds.

setSocketTimeoutInMillis

public void setSocketTimeoutInMillis(int socketTimeoutInMillis)
Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets. A value of 0 means infinity, and is not recommended.

Parameters:
socketTimeoutInMillis - the socket timeout (SO_TIMEOUT) in milliseconds.
Throws:
IllegalArgumentException - if socketTimeoutInMillis is negative.

withSocketTimeoutInMillis

public BceClientConfiguration withSocketTimeoutInMillis(int socketTimeoutInMillis)
Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets, and returns the updated configuration instance. A value of 0 means infinity, and is not recommended.

Parameters:
socketTimeoutInMillis - the socket timeout (SO_TIMEOUT) in milliseconds.
Returns:
the updated configuration instance.
Throws:
IllegalArgumentException - if socketTimeoutInMillis is negative.

getConnectionTimeoutInMillis

public int getConnectionTimeoutInMillis()
Returns the connection timeout in milliseconds.

Returns:
the connection timeout in milliseconds.

setConnectionTimeoutInMillis

public void setConnectionTimeoutInMillis(int connectionTimeoutInMillis)
Sets the connection timeout in milliseconds. A value of 0 means infinity, and is not recommended.

Parameters:
connectionTimeoutInMillis - the connection timeout in milliseconds.
Throws:
IllegalArgumentException - if connectionTimeoutInMillis is negative.

withConnectionTimeoutInMillis

public BceClientConfiguration withConnectionTimeoutInMillis(int connectionTimeoutInMillis)
Sets the connection timeout in milliseconds, and returns the updated configuration instance. A value of 0 means infinity, and is not recommended.

Parameters:
connectionTimeoutInMillis - the connection timeout in milliseconds.
Returns:
the updated configuration instance.
Throws:
IllegalArgumentException - if connectionTimeoutInMillis is negative.

getSocketBufferSizeInBytes

public int getSocketBufferSizeInBytes()
Returns the optional size (in bytes) for the low level TCP socket buffer. This is an advanced option for advanced users who want to tune low level TCP parameters to try and squeeze out more performance. Ignored if not positive.

Returns:
the optional size (in bytes) for the low level TCP socket buffer.

setSocketBufferSizeInBytes

public void setSocketBufferSizeInBytes(int socketBufferSizeInBytes)
Sets the optional size (in bytes) for the low level TCP socket buffer. This is an advanced option for advanced users who want to tune low level TCP parameters to try and squeeze out more performance. Ignored if not positive.

Parameters:
socketBufferSizeInBytes - the optional size (in bytes) for the low level TCP socket buffer.

withSocketBufferSizeInBytes

public BceClientConfiguration withSocketBufferSizeInBytes(int socketBufferSizeInBytes)
Sets the optional size (in bytes) for the low level TCP socket buffer, and returns the updated configuration instance. This is an advanced option for advanced users who want to tune low level TCP parameters to try and squeeze out more performance. Ignored if not positive.

Parameters:
socketBufferSizeInBytes - the optional size (in bytes) for the low level TCP socket buffer.
Returns:
the updated configuration instance.

getEndpoint

public String getEndpoint()
Returns the service endpoint URL to which the client will connect.

Returns:
the service endpoint URL to which the client will connect.

setEndpoint

public void setEndpoint(String endpoint)
Sets the service endpoint URL to which the client will connect.

Parameters:
endpoint - the service endpoint URL to which the client will connect.
Throws:
IllegalArgumentException - if endpoint is not a valid URL.
NullPointerException - if endpoint is null.

withEndpoint

public BceClientConfiguration withEndpoint(String endpoint)
Sets the service endpoint URL to which the client will connect, and returns the updated configuration instance.

Parameters:
endpoint - the service endpoint URL to which the client will connect.
Returns:
the updated configuration instance.
Throws:
IllegalArgumentException - if endpoint is not a valid URL.
NullPointerException - if endpoint is null.

getRegion

public Region getRegion()
Returns the region of service. This value is used by the client to construct the endpoint URL automatically, and is ignored if endpoint is not null.

Returns:
the region of service.

setRegion

public void setRegion(Region region)
Sets the region of service. This value is used by the client to construct the endpoint URL automatically, and is ignored if endpoint is not null.

If the specified region is null, sets to DEFAULT_REGION.

Parameters:
region - the region of service.

withRegion

public BceClientConfiguration withRegion(Region region)
Sets the region of service, and returns the updated configuration instance. This value is used by the client to construct the endpoint URL automatically, and is ignored if endpoint is not null.

If the specified region is null, sets to DEFAULT_REGION.

Parameters:
region - the region of service.
Returns:
the updated configuration instance.

getCredentials

public BceCredentials getCredentials()
Returns the BCE credentials used by the client to sign HTTP requests.

Returns:
the BCE credentials used by the client to sign HTTP requests.

setCredentials

public void setCredentials(BceCredentials credentials)
Sets the BCE credentials used by the client to sign HTTP requests.

Parameters:
credentials - the BCE credentials used by the client to sign HTTP requests.
Throws:
NullPointerException - if credentials is null.

withCredentials

public BceClientConfiguration withCredentials(BceCredentials credentials)
Sets the BCE credentials used by the client to sign HTTP requests, and returns the updated configuration instance.

Parameters:
credentials - the BCE credentials used by the client to sign HTTP requests.
Returns:
the updated configuration instance.
Throws:
NullPointerException - if credentials is null.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2018. All rights reserved.