Help Center> Object Storage Service> Android> Initialization> Configuring an Instance of ObsClient
Updated on 2024-05-09 GMT+08:00

Configuring an Instance of ObsClient

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

When you call the ObsConfiguration configuration class to create an instance of ObsClient, you can configure the agent, timeout duration, maximum allowed number of connections, and some other parameters listed in the following table.

Parameter

Description

Method

Recommended Value

connectionTimeout

Timeout period for establishing an HTTP/HTTPS connection, in ms. The default value is 60000.

ObsConfiguration.setConnectionTimeout

[10000, 60000]

socketTimeout

Timeout duration for transmitting data at the Socket layer, in ms. The default value is 60000.

ObsConfiguration.setSocketTimeout

[10000, 60000]

idleConnectionTime

Allowed connection idle time, in ms. If a connection exceeds the specified value, the connection will be closed. The default value is 30000.

ObsConfiguration.setIdleConnectionTime

Default value

maxIdleConnections

Maximum number of allowed idle connections in the connection pool. The default value is 1000.

ObsConfiguration.setMaxIdleConnections

N/A

maxConnections

Maximum number of concurrent HTTP requests. The default value is 1000.

ObsConfiguration.setMaxConnections

Default value

maxErrorRetry

Maximum number of retry attempts (caused by abnormal requests, 500, 503, and other errors). The default value is 3.

NOTE:

This parameter is invalid in object upload and download APIs if an interruption occurs after an upload or download task enters the data flow processing phase. In this case, no retry is performed.

ObsConfiguration.setMaxErrorRetry

[0, 5]

endPoint

Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port number. For example, https://your-endpoint:443.

For security purposes, you are advised to use HTTPS.

ObsConfiguration.setEndPoint

N/A

httpProxy

HTTP proxy configuration. This parameter is left blank by default.

ObsConfiguration.setHttpProxy

N/A

validateCertificate

Whether to verify the server certificate. The default value is false.

ObsConfiguration.setValidateCertificate

N/A

verifyResponseContentType

Whether to verify ContentType of the response header. The default value is true.

ObsConfiguration.setVerifyResponseContentType

Default value

uploadStreamRetryBufferSize

Size of the cache used for uploading a stream object, in bytes. The default size is 512 KB.

ObsConfiguration.setUploadStreamRetryBufferSize

N/A

readBufferSize

Cache size for downloading the object from socket streams, in bytes. Value -1 indicates that cache is not configured. The default value is -1.

ObsConfiguration.setReadBufferSize

N/A

writeBufferSize

Cache size for uploading the object to socket streams, in bytes. Value -1 indicates that cache is not configured. The default value is -1.

ObsConfiguration.setWriteBufferSize

N/A

socketWriteBufferSize

Buffer size for sending a socket, in bytes. This parameter corresponds to java.net.SocketOptions.SO_SNDBUF. The default value is -1, which indicates no limitation.

ObsConfiguration.setSocketWriteBufferSize

Default value

socketReadBufferSize

Buffer size for receiving a socket, in bytes. This parameter corresponds to java.net.SocketOptions.SO_RCVBUF. The default value is -1, which indicates no limitation.

ObsConfiguration.setSocketReadBufferSize

Default value

keyManagerFactory

Factory used for generating javax.net.ssl.KeyManager. This parameter is left blank by default.

ObsConfiguration.setKeyManagerFactory

N/A

trustManagerFactory

Factory used for generating javax.net.ssl.TrustManager. This parameter is left blank by default.

ObsConfiguration.setTrustManagerFactory

N/A

isStrictHostnameVerification

Whether to strictly verify the server-side host name. The default value is false.

ObsConfiguration.setIsStrictHostnameVerification

N/A

keepAlive

Whether to use persistent connections to access OBS. The default value is true.

ObsConfiguration.setKeepAlive

N/A

cname

Whether to use self-defined domain name to access OBS. The default value is false.

ObsConfiguration.setCname

N/A

sslProvider

Provider of SSLContext. The SSLContext provided by JDK is used by default.

ObsConfiguration.setSslProvider

N/A

httpProtocolType

HTTP protocol type used for accessing OBS servers. The default protocol is HTTP 1.1.

ObsConfiguration.setHttpProtocolType

N/A

httpDispatcher

Customized dispatcher

ObsConfiguration.setHttpDispatcher

N/A

  • Parameters whose recommended value is N/A need to be set according to the actual conditions.
  • To improve the upload and download performance of large files in the case that the network bandwidth meets the requirements, you can tune the socketWriteBufferSize, sockeReadBufferSize, readBufferSize, and writeBufferSize parameters.
  • If the network is unstable, you are advised to set larger values for connectionTimeout and socketTimeout.
  • If the value of endPoint does not contain any protocol, HTTPS is used by default.
  • For the sake of high DNS resolution performance and OBS reliability, you can set endPoint only to the domain name of OBS, instead of the IP address.