release branch 1.1.0
This commit is contained in:
@@ -12,13 +12,33 @@ public interface ILock {
|
||||
/**
|
||||
* 尝试加锁,如果失败,会一直尝试。
|
||||
*
|
||||
* @param time 时间
|
||||
* @param unit 当为
|
||||
* @param key key
|
||||
* @param timeUnit 时间单位
|
||||
* @param waitLockTime 等待锁时间
|
||||
* @param lockTime 加锁时间
|
||||
* @return 返回
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean tryLock(long time, TimeUnit unit, String key);
|
||||
boolean tryLock(String key, TimeUnit timeUnit, long lockTime, long waitLockTime);
|
||||
|
||||
/**
|
||||
* 尝试加锁,只加锁一次
|
||||
* @param key key
|
||||
* @param timeUnit 时间单位
|
||||
* @param lockTime 加锁时间
|
||||
* @return 返回
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean tryLock(String key, TimeUnit timeUnit, long lockTime);
|
||||
|
||||
/**
|
||||
* 尝试加锁,只加锁一次
|
||||
* @param key key
|
||||
* @param lockTime 加锁时间
|
||||
* @return 返回
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean tryLock(String key, long lockTime);
|
||||
|
||||
/**
|
||||
* 尝试加锁,只加锁一次
|
||||
@@ -32,6 +52,7 @@ public interface ILock {
|
||||
* 解锁
|
||||
* @param key key
|
||||
* @since 0.0.1
|
||||
* @return 是否释放锁成功
|
||||
*/
|
||||
boolean unlock(String key);
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.houbb.lock.api.core;
|
||||
|
||||
/**
|
||||
* 分布式锁 KEY 格式化处理
|
||||
*
|
||||
* @author binbin.hou
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public interface ILockKeyFormat {
|
||||
|
||||
/**
|
||||
* 对 key 进行格式化处理,避免缓存命名空间处理等问题
|
||||
*
|
||||
* @param formatContext 上下文
|
||||
* @return 返回
|
||||
* @since 1.2.0
|
||||
*/
|
||||
String format(ILockKeyFormatContext formatContext);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.houbb.lock.api.core;
|
||||
|
||||
/**
|
||||
* 分布式锁 KEY 格式化处理上下文
|
||||
*
|
||||
* @author binbin.hou
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public interface ILockKeyFormatContext {
|
||||
|
||||
/**
|
||||
* 原始的 key
|
||||
*
|
||||
* @return 返回
|
||||
* @since 1.2.0
|
||||
*/
|
||||
String rawKey();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.houbb.lock.api.core;
|
||||
|
||||
/**
|
||||
* 释放锁失败处理类
|
||||
*
|
||||
* @author binbin.hou
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public interface ILockReleaseFailHandler {
|
||||
|
||||
/**
|
||||
* 处理
|
||||
* @param context 上下文
|
||||
* @since 1.2.0
|
||||
*/
|
||||
void handle(ILockReleaseFailHandlerContext context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.houbb.lock.api.core;
|
||||
|
||||
/**
|
||||
* 释放锁失败处理类
|
||||
*
|
||||
* @author binbin.hou
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public interface ILockReleaseFailHandlerContext {
|
||||
|
||||
/**
|
||||
* 释放锁对应的 key
|
||||
* @return 结果
|
||||
* @since 1.2.0
|
||||
*/
|
||||
String key();
|
||||
|
||||
}
|
||||
@@ -12,30 +12,21 @@ public interface ILockSupport {
|
||||
/**
|
||||
* 尝试加锁,如果失败,会一直尝试。
|
||||
*
|
||||
* @param time 时间
|
||||
* @param unit 单位
|
||||
* @param key key
|
||||
* 1. 如果等待时间小于等于0,则直接执行加锁
|
||||
* 2. 如果等待时间大于等于0,则尝试循环等待。
|
||||
*
|
||||
* @param context 上下文
|
||||
* @return 返回
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean tryLock(long time, TimeUnit unit, String key, final ILockSupportContext context);
|
||||
|
||||
/**
|
||||
* 尝试加锁,只加锁一次
|
||||
* @param key key
|
||||
* @param context 上下文
|
||||
* @return 返回
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean tryLock(String key, final ILockSupportContext context);
|
||||
boolean tryLock(final ILockSupportContext context);
|
||||
|
||||
/**
|
||||
* 解锁
|
||||
* @param key key
|
||||
* @param context 上下文
|
||||
* @since 0.0.1
|
||||
* @return 结果
|
||||
*/
|
||||
boolean unlock(String key, final ILockSupportContext context);
|
||||
boolean unlock(final ILockSupportContext context);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.github.houbb.lock.api.core;
|
||||
import com.github.houbb.common.cache.api.service.ICommonCacheService;
|
||||
import com.github.houbb.id.api.Id;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 分布式锁接口定义
|
||||
* @author binbin.hou
|
||||
@@ -11,21 +13,60 @@ import com.github.houbb.id.api.Id;
|
||||
public interface ILockSupportContext {
|
||||
|
||||
/**
|
||||
* 标识
|
||||
*
|
||||
* @return 标识策略
|
||||
* @since 0.0.4
|
||||
*/
|
||||
Id id();
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
* @return 缓存策略
|
||||
* @since 0.0.4
|
||||
*/
|
||||
ICommonCacheService cache();
|
||||
|
||||
/**
|
||||
* 锁的过期时间
|
||||
* @return 结果
|
||||
* 时间单位
|
||||
* @return 时间单位
|
||||
*/
|
||||
int lockExpireMills();
|
||||
TimeUnit timeUnit();
|
||||
|
||||
/**
|
||||
* 加锁时间
|
||||
* @return 时间
|
||||
* @since 1.2.0
|
||||
*/
|
||||
long lockTime();
|
||||
|
||||
/**
|
||||
* 等待加锁时间
|
||||
* @return 等待时间
|
||||
* @since 1.2.0
|
||||
*/
|
||||
long waitLockTime();
|
||||
|
||||
/**
|
||||
* 缓存对应的 key
|
||||
* @return 结果
|
||||
* @since 1.2.0
|
||||
*/
|
||||
String key();
|
||||
|
||||
/**
|
||||
* 锁 key 格式化
|
||||
* @since 1.2.0
|
||||
* @return 格式化
|
||||
*/
|
||||
ILockKeyFormat lockKeyFormat();
|
||||
|
||||
/**
|
||||
* 锁释放失败处理类
|
||||
* @since 1.2.0
|
||||
* @return 失败处理
|
||||
*/
|
||||
ILockReleaseFailHandler lockReleaseFailHandler();
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user