batchMultiGet2
对multiGet函数的批量封装。该函数并发地向server发送异步请求,并等待结果。但与上面batchMultiGet不同的是,无论请求成功还是失败,它都会等待所有请求结束。
用户可以根据results中的PException是否设置来判断请求成功还是失败,并可以选择只使用成功的结果。
- /**
- * Batch get multiple values under the same hash key.
- * Will wait for all requests done even if some error occurs.
- * @param tableName table name
- * @param keys List{hashKey,List{sortKey}}; if List{sortKey} is null or empty, means fetch all
- * sortKeys under the hashKey.
- * @param results output results; should be created by caller; after call done, the size of results will
- * be same with keys; the results[i] is a Pair:
- * - if Pair.left != null : means query keys[i] failed, Pair.left is the exception.
- * - if Pair.left == null : means query keys[i] succeed, Pair.right is the result value.
- * @return succeed count.
- * @throws PException
- *
- * Notice: the method is not atomic, that means, maybe some keys succeed but some keys failed.
- */
- public int batchMultiGet2(String tableName, List<Pair<byte[], List<byte[]>>> keys, List<Pair<PException, HashKeyData>> results) throws PException;
注:
- 参数:
- 传入参数:TableName、Keys。Keys是一个Pair列表,Pair的左值是hashKey,右值是sortKey列表;如果Pair的右值为null或者空列表,则获取该hashKey下的所有数据。
- 传出参数:Results。该变量需由调用者创建;Results[i]中存放Keys[i]对应的结果;如果Results[i].left不为null(PException已设置),表示对Keys[i]的请求失败。
- 返回值:请求成功的个数。
- 异常:如果出现异常,譬如参数错误、表名不存在等,会抛出 PException。
- 注意:该方法不是原子的,有可能出现部分成功部分失败的情况,用户可以选择只使用成功的结果。