batchMultiSet2

对multiSet函数的批量封装。该函数并发地向server发送异步请求,并等待结果。但与上面batchMultiSet不同的是,无论请求成功还是失败,它都会等待所有请求结束。

  1. /**
  2. * Batch set multiple value under the same hash key.
  3. * Will wait for all requests done even if some error occurs.
  4. * @param tableName table name
  5. * @param items list of items.
  6. * @param ttl_seconds time to live in seconds,
  7. * 0 means no ttl. default value is 0.
  8. * @param results output results; should be created by caller; after call done, the size of results will
  9. * be same with items; the results[i] is a PException:
  10. * - if results[i] != null : means set items[i] failed, results[i] is the exception.
  11. * - if results[i] == null : means set items[i] succeed.
  12. * @return succeed count.
  13. * @throws PException
  14. *
  15. * Notice: the method is not atomic, that means, maybe some keys succeed but some keys failed.
  16. */
  17. public int batchMultiSet2(String tableName, List<HashKeyData> items, int ttl_seconds, List<PException> results) throws PException;
  18. public int batchMultiSet2(String tableName, List<HashKeyData> items, List<PException> results) throws PException;

注:

  • 提供了两个版本的接口,其中第一个接口可以指定TTL时间。
  • 参数:
    • 传入参数:TableName、Items;选择性传入TTL。
    • 传出参数:Results。该变量需由调用者创建;Results[i]中存放Items[i]对应的结果;如果Results[i]不为null(PException已设置),表示对Items[i]的请求失败。
  • 返回值:请求成功的个数。
  • 异常:如果出现异常,譬如参数错误、表名不存在等,会抛出 PException。
  • 注意:该方法不是原子的,有可能出现部分成功部分失败的情况,用户可以选择只使用成功的结果。