public interface ILock extends Lock, AutoCloseable, ILockTemplate
定义了Redis 锁对外暴露的服务接口,支持 try-with-resource
Lock,
AutoCloseable,
ILockTemplate| 限定符和类型 | 方法和说明 |
|---|---|
default void |
close()
try-with-resource close
|
default <T> T |
execute(IDoCallback<T> callback,
IDoCallback<T> faultCallback,
IDoCallback<T> rollback,
int time,
TimeUnit unit)
执行需要锁的函数
|
String |
getKey()
获取锁的key
|
int |
getLockSeconds()
需要锁定的时间
|
RedisLockReleaseStatus |
getReleaseStatus()
获取 释放 状态
|
int |
getSleepMaxMills()
获取最大休眠时间
|
int |
getSleepMinMills()
获取最小休眠时间,毫秒
|
int |
getSpinTimes()
获取自旋次数
|
RedisLockStatus |
getStatus()
获取所的状态
|
boolean |
interrupted()
取消当前锁,只对 NEW 状态可用
|
default boolean |
isFinished()
流程结束
|
default boolean |
isLocked()
是否 以获取锁
|
default boolean |
isRollback()
是否需要 回滚, status=
RedisLockStatus.LOCKED && releaseStatus=RedisLockReleaseStatus.FAIL 时返回true |
default void |
lock()
锁定,此方法不支持
|
default void |
lockInterruptibly()
可重复线程锁,不支持
|
default Condition |
newCondition()
此方法不支持
|
RedisLockStatus getStatus()
RedisLockReleaseStatus getReleaseStatus()
int getSleepMinMills()
int getSleepMaxMills()
int getSpinTimes()
String getKey()
int getLockSeconds()
default boolean isFinished()
default boolean isLocked()
default boolean isRollback()
RedisLockStatus.LOCKED && releaseStatus=RedisLockReleaseStatus.FAIL 时返回trueboolean interrupted()
default <T> T execute(IDoCallback<T> callback, IDoCallback<T> faultCallback, IDoCallback<T> rollback, int time, TimeUnit unit) throws TimeoutLockException, Throwable
execute 在接口中 ILockTemplateT - 返回值类型callback - 获取锁成功执行的函数faultCallback - 获取所失败后降级参数,=null 时,获取失败将抛出 SharedLockTimeoutExceptionrollback - 释放资源失败回退操作time - 等待时间unit - 时间单位TimeoutLockException - 超时异常Throwable - 其他业务异常default void close()
throws Exception
close 在接口中 AutoCloseableException - 关闭失败异常default Condition newCondition()
newCondition 在接口中 Lockdefault void lockInterruptibly()
throws InterruptedException
lockInterruptibly 在接口中 LockInterruptedExceptionCopyright © 2020. All rights reserved.