Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
LOGGER |
static String |
version |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Modifier and Type | Method and Description |
|---|---|
Request |
acquireRequest()
获得一个请求对象
|
static Client |
create(int appId,
int zoneId,
String signature,
List<String> addresses,
int callbackPoolSize,
int timeout) |
static void |
destroy(Client client) |
GenericTableTraverser |
getGenericTableTraverser()
获取generic表的遍历器,需要调用
Traverser.setTableName(String)设置表名 |
GenericTableTraverser |
getGenericTableTraverser(String tableName)
获取generic表的遍历器
|
ListTableTraverser |
getListTableTraverser()
获取list表的遍历器,需要调用
Traverser.setTableName(String)设置表名 |
ListTableTraverser |
getListTableTraverser(String tableName)
获取list表的遍历器
|
String |
getVersion()
获得api版本号
|
void |
init(int appId,
int zoneId,
String signature,
List<String> addresses,
int callbackPoolSize,
int timeout)
初始化函数
|
Response |
poll(Request req)
同步访问方法
|
void |
post(Request req,
Future future)
异步访问方法
|
void |
run()
主循环线程
|
void |
shutdown()
停止主逻辑线程
|
String |
toString() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldpublic static String version
protected static final org.slf4j.Logger LOGGER
public static Client create(int appId, int zoneId, String signature, List<String> addresses, int callbackPoolSize, int timeout)
public void init(int appId,
int zoneId,
String signature,
List<String> addresses,
int callbackPoolSize,
int timeout)
throws TCaplusException
appId - 在网站注册相应服务以后,你可以得到该appIdzoneId - 业务所属的区服IDsignature - 签名/密码,在网站注册相应服务以后,你可以得到该字符串addresses - dir server 地址列表callbackPoolSize - 异步回调线程池数量timeout - 初始化proxy连接超时时间,必须大于0,单位msTCaplusExceptionpublic Request acquireRequest()
ClientacquireRequest in interface Clientpublic Response poll(Request req) throws TCaplusException
Client
List<String> dirAddr = new ArrayList<String>;
dirAddr.add("tcp://10.0.0.1:9999");
//创建client实例
Client client = ClientFactory.createClient(1, 1, "47CCA171EB3A288A", dirAddr);
//获得一个请求对象
Request req = client.acquireRequest();
//设置命令字、表名、要查询的value字段等信息
req.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_GET_REQ);
req.setTableName(TABLE_NAME);
req.addFieldName("value_name");
//设置key字段信息
Record record = req.addRecord();
record.setKeyInt("key_name", 1);
//执行阻塞调用
Response rsp = client.poll(req);
if (rsp.getResult() == TCapErrCode.GEN_ERR_SUC){
Record record = rsp.fetchRecord();
System.out.println(record.getValueInt("value_name"));
}
//销毁访问实例
ClientFactory.destroyClient(client);
poll in interface Clientreq - 请求对象TCaplusExceptionpublic void post(Request req, Future future) throws TCaplusException
Client例子:
List<String> dirAddr = new ArrayList<String>;
dirAddr.add("tcp://10.0.0.1:9999");
//创建client实例
Client client = ClientFactory.createClient(1, 1, "47CCA171EB3A288A", dirAddr);
//获得一个请求对象
Request req = client.acquireRequest();
//设置命令字、表名、要查询的value字段等信息
req.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_GET_REQ);
req.setTableName(TABLE_NAME);
req.addFieldName("value_name");
//设置key字段信息
Record record = req.addRecord();
record.setKeyInt("key_name", 1);
//执行异步调用接口
client.post(req, new Future() {
public void onResponse(Response res) {
if (rsp.getResult() == TCapErrCode.GEN_ERR_SUC) {
Record record = rsp.fetchRecord();
System.out.println(record.getValueInt("value_name"));
}
}
});
//等待异步回调完成
Thread.sleep(1000);
//销毁访问实例
ClientFactory.destroyClient(client);
post in interface Clientreq - 请求对象future - 异步回调对象TCaplusExceptionpublic void shutdown()
public GenericTableTraverser getGenericTableTraverser(String tableName)
ClientgetGenericTableTraverser in interface ClienttableName - 需要遍历的表的tableNamepublic GenericTableTraverser getGenericTableTraverser()
ClientTraverser.setTableName(String)设置表名getGenericTableTraverser in interface Clientpublic ListTableTraverser getListTableTraverser(String tableName)
ClientgetListTableTraverser in interface ClienttableName - 需要遍历的表的tableNamepublic ListTableTraverser getListTableTraverser()
ClientTraverser.setTableName(String)设置表名getListTableTraverser in interface Clientpublic String getVersion()
ClientgetVersion in interface Clientpublic static void destroy(Client client)
Copyright © 2026. All rights reserved.