asyncCheckAndSet
单HashKey数据的原子CAS操作。checkAndSet的异步版本。
- public static class CheckAndSetResult {
- /**
- * return value for checkAndSet
- *
- * @param setSucceed true if set value succeed.
- * @param checkValueReturned true if the check value is returned.
- * @param checkValueExist true if the check value is exist; can be used only when checkValueReturned is true.
- * @param checkValue return the check value if exist; can be used only when checkValueExist is true.
- */
- boolean setSucceed;
- boolean checkValueReturned;
- boolean checkValueExist;
- byte[] checkValue;
- }
- public static interface CheckAndSetListener extends GenericFutureListener<Future<CheckAndSetResult>> {
- /**
- * This function will be called when listened asyncCheckAndSet future is done.
- *
- * @param future the listened future
- * @throws Exception throw exception if any error occurs.
- *
- * Notice: User shouldn't do any operations that may block or time-consuming
- */
- @Override
- public void operationComplete(Future<CheckAndSetResult> future) throws Exception;
- }
- /**
- * atomically check and set value by key, async version.
- * if the check condition is satisfied, then apply to set value.
- *
- * @param hashKey the hash key to check and set.
- * @param checkSortKey the sort key to check.
- * @param checkType the check type.
- * @param checkOperand the check operand.
- * @param setSortKey the sort key to set value if check condition is satisfied.
- * @param setValue the value to set if check condition is satisfied.
- * @param options the check-and-set options.
- * @param timeout how long will the operation timeout in milliseconds.
- * if timeout > 0, it is a timeout value for current op,
- * else the timeout value in the configuration file will be used.
- * @return the future for current op
- * <p>
- * Future return:
- * On success: return CheckAndSetResult.
- * On failure: a throwable, which is an instance of PException
- * <p>
- * Thread safety:
- * All the listeners for the same table are guaranteed to be dispatched in the same thread, so all the
- * listeners for the same future are guaranteed to be executed as the same order as the listeners added.
- * But listeners for different tables are not guaranteed to be dispatched in the same thread.
- */
- public Future<CheckAndSetResult> asyncCheckAndSet(byte[] hashKey, byte[] checkSortKey, CheckType checkType,
- byte[] checkOperand, byte[] setSortKey, byte[] setValue,
- CheckAndSetOptions options, int timeout/*ms*/);
注:
- 参数和返回值:参见同步接口checkAndSet。