asyncCheckAndSet

单HashKey数据的原子CAS操作。checkAndSet的异步版本。

  1. public static class CheckAndSetResult {
  2. /**
  3. * return value for checkAndSet
  4. *
  5. * @param setSucceed true if set value succeed.
  6. * @param checkValueReturned true if the check value is returned.
  7. * @param checkValueExist true if the check value is exist; can be used only when checkValueReturned is true.
  8. * @param checkValue return the check value if exist; can be used only when checkValueExist is true.
  9. */
  10. boolean setSucceed;
  11. boolean checkValueReturned;
  12. boolean checkValueExist;
  13. byte[] checkValue;
  14. }
  15.  
  16. public static interface CheckAndSetListener extends GenericFutureListener<Future<CheckAndSetResult>> {
  17. /**
  18. * This function will be called when listened asyncCheckAndSet future is done.
  19. *
  20. * @param future the listened future
  21. * @throws Exception throw exception if any error occurs.
  22. *
  23. * Notice: User shouldn't do any operations that may block or time-consuming
  24. */
  25. @Override
  26. public void operationComplete(Future<CheckAndSetResult> future) throws Exception;
  27. }
  28.  
  29. /**
  30. * atomically check and set value by key, async version.
  31. * if the check condition is satisfied, then apply to set value.
  32. *
  33. * @param hashKey the hash key to check and set.
  34. * @param checkSortKey the sort key to check.
  35. * @param checkType the check type.
  36. * @param checkOperand the check operand.
  37. * @param setSortKey the sort key to set value if check condition is satisfied.
  38. * @param setValue the value to set if check condition is satisfied.
  39. * @param options the check-and-set options.
  40. * @param timeout how long will the operation timeout in milliseconds.
  41. * if timeout > 0, it is a timeout value for current op,
  42. * else the timeout value in the configuration file will be used.
  43. * @return the future for current op
  44. * <p>
  45. * Future return:
  46. * On success: return CheckAndSetResult.
  47. * On failure: a throwable, which is an instance of PException
  48. * <p>
  49. * Thread safety:
  50. * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
  51. * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
  52. * But listeners for different tables are not guaranteed to be dispatched in the same thread.
  53. */
  54. public Future<CheckAndSetResult> asyncCheckAndSet(byte[] hashKey, byte[] checkSortKey, CheckType checkType,
  55. byte[] checkOperand, byte[] setSortKey, byte[] setValue,
  56. CheckAndSetOptions options, int timeout/*ms*/);

注: