The OTSClient is the client for Table Store. It provides callers with a series of methods for operating tables and reading/writing data from/to a single row or multiple rows. To use the Java SDK to initiate a request to Table Store, you must initialize an OTSClient instance and modify the default configurations of the ClientConfiguration as needed.
An endpoint is the domain of Alibaba Cloud Table Store in a region. It supports the following format.
||Accesses the sun instance in Hangzhou over the Internet using the HTTP protocol.|
||Accesses the sun instance in Hangzhou over the Internet using the HTTPS protocol.|
Note: Instances can also be accessed over the intranet.
To query the endpoint where your Table Store instance is located, follow these steps:
Log on to the Alibaba Cloud Table Store Console.
Go to the Instance Details page and locate the Instance Access URL, which is the endpoint of the instance.
To access the Alibaba Cloud Table Store service, you need a valid AccessKey for signature authentication. The following types of AccessKeys is supported:
AccessKeyID and AccessKeySecret of the primary account.
The creation process is as follows:
AccessKeyID and AccessKeySecret of the RAM user authorized to access Table Store.
The creation process is as follows:
Use the primary account to access RAM and create a RAM user or use an existing RAM user.
Use the primary account to authorize the RAM user to access Table Store.
After authorization, the AccessKeyID and AccessKeySecret of the RAM user can be used to access Table Store.
STS token for temporary access.
The token acquisition process is as follows:
The application server accesses the RAM/STS server to obtain a temporary AccessKeyID, AccessKeySecret, and token, and sends them to you.
Use the temporary AccessKeyID, AccessKeySecret, and token to access Table Store.
After you obtain the AccessKeyID and AccessKeySecret, you must initialize an OTSClient instance.
When using Table Store SDKs, you must construct a client and then call the client API to access the Table Store service. The client API functions are similar to the RESTful API provided by Table Store.
The latest versions of Table Store SDKs provide two types of clients: SyncClient and AsyncClient, which are designed for synchronous APIs and asynchronous APIs respectively.
Once a synchronous API call is completed, the request has been executed. You can call synchronous APIs to learn about the various functions of Table Store. Compared to synchronous APIs, asynchronous APIs provide greater flexibility. If you have high performance requirements, you can choose between the use of asynchronous APIs and multithreading, depending on your business needs.
Both SyncClient and AsyncClient are secure threads, which contain management threads and connection resources. We do not recommend creating too many clients. Generally, one global client is sufficient.
Use the default configuration to create a SyncClient.
final String endPoint = "";
final String accessKeyId = "";
final String accessKeySecret = "";
final String instanceName = "";
SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName);
Use custom configuration to create a SyncClient.
// ClientConfiguration provides multiple configuration items. Commonly used items are listed as follows.
ClientConfiguration clientConfiguration = new ClientConfiguration();
// Set the connection establishment time-out.
// Set the socket time-out.
// Set the retry policy. If this is not set, the default retry policy is used.
SyncClient client = new SyncClient(endPoint, accessId, accessKey,
Upgrade to Java 7 for HTTPS.
Multithreading is supported.
We recommend that multiple threads use the same OTSClient object.