release branch 0.0.3

This commit is contained in:
binbin.hou
2021-12-08 10:19:58 +08:00
parent d06effa306
commit ecd879763a
25 changed files with 232 additions and 43 deletions

View File

@@ -19,4 +19,10 @@
| 序号 | 变更类型 | 说明 | 时间 | 备注 | | 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:---|:---|:---|:--| |:---|:---|:---|:---|:--|
| 1 | A | 常见锁添加 | 2020-9-2 14:45:40 | | | 1 | A | 常见锁添加 | 2020-9-2 14:45:40 | |
# release_0.0.3
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:---|:---|:---|:--|
| 1 | A | redis 锁独立,便于使用 | 2021-12-08 14:45:40 | |

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>lock</artifactId> <artifactId>lock</artifactId>
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -1,9 +1,12 @@
package com.github.houbb.lock.redis.support.operator; package com.github.houbb.lock.api.support;
/** /**
* Redis 客户端 * 操作接口定义
*
* ps: 可以基于集中式数据库做操作
*
* @author binbin.hou * @author binbin.hou
* @since 0.0.1 * @since 0.0.3
*/ */
public interface IOperator { public interface IOperator {
@@ -14,7 +17,7 @@ public interface IOperator {
* @param requestId 请求标识 * @param requestId 请求标识
* @param expireTimeMills 超期时间 * @param expireTimeMills 超期时间
* @return 是否获取成功 * @return 是否获取成功
* @since 0.0.1 * @since 0.0.3
*/ */
boolean lock(String lockKey, String requestId, int expireTimeMills); boolean lock(String lockKey, String requestId, int expireTimeMills);
@@ -23,7 +26,7 @@ public interface IOperator {
* @param lockKey key * @param lockKey key
* @param requestId 请求标识 * @param requestId 请求标识
* @return 结果 * @return 结果
* @since 0.0.1 * @since 0.0.3
*/ */
boolean unlock(String lockKey, String requestId); boolean unlock(String lockKey, String requestId);

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>lock</artifactId> <artifactId>lock</artifactId>
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -37,11 +37,7 @@
<artifactId>log-integration</artifactId> <artifactId>log-integration</artifactId>
</dependency> </dependency>
<!--============================== OTHER ==============================-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -0,0 +1,28 @@
package com.github.houbb.lock.redis.constant;
/**
* 通用锁常量
*
* @author binbin.hou
* @since 0.0.3
*/
public final class LockConst {
private LockConst() {
}
/**
* 默认的失效时间
*
* 暂时定为 30min
* @since 0.0.1
*/
public static final int DEFAULT_EXPIRE_MILLS = 1000 * 60 * 30;
/**
* 默认锁为全局锁
* @since 0.0.1
*/
public static final String DEFAULT_KEY = "GLOBAL";
}

View File

@@ -1,7 +1,7 @@
package com.github.houbb.lock.redis.core; package com.github.houbb.lock.redis.core;
import com.github.houbb.lock.api.core.ILock; import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.constant.LockRedisConst; import com.github.houbb.lock.redis.constant.LockConst;
import com.github.houbb.wait.api.IWait; import com.github.houbb.wait.api.IWait;
import com.github.houbb.wait.core.Waits; import com.github.houbb.wait.core.Waits;
@@ -41,12 +41,12 @@ public abstract class AbstractLock implements ILock {
@Override @Override
public boolean tryLock() { public boolean tryLock() {
return tryLock(LockRedisConst.DEFAULT_KEY); return tryLock(LockConst.DEFAULT_KEY);
} }
@Override @Override
public void unlock() { public void unlock() {
unlock(LockRedisConst.DEFAULT_KEY); unlock(LockConst.DEFAULT_KEY);
} }
@Override @Override
@@ -81,7 +81,7 @@ public abstract class AbstractLock implements ILock {
@Override @Override
public synchronized boolean tryLock(long time, TimeUnit unit) throws InterruptedException { public synchronized boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
return tryLock(time, unit, LockRedisConst.DEFAULT_KEY); return tryLock(time, unit, LockConst.DEFAULT_KEY);
} }
@Override @Override

View File

@@ -0,0 +1,23 @@
package com.github.houbb.lock.redis.core;
import com.github.houbb.heaven.annotation.ThreadSafe;
/**
* 无任何锁的操作
*
* @author binbin.hou
* @since 0.0.3
*/
@ThreadSafe
public class LockNone extends AbstractLock {
@Override
public boolean tryLock(String key) {
return true;
}
@Override
public void unlock(String key) {
}
}

View File

@@ -17,12 +17,12 @@ public class LockReadWrite implements IReadWriteLock {
/** /**
* 读次数统计 * 读次数统计
*/ */
private int readCount = 0; private volatile int readCount = 0;
/** /**
* 写次数统计 * 写次数统计
*/ */
private int writeCount = 0; private volatile int writeCount = 0;
/** /**
* 获取读锁,读锁在写锁不存在的时候才能获取 * 获取读锁,读锁在写锁不存在的时候才能获取

View File

@@ -36,7 +36,7 @@ public class LockReadWriteOwner implements IReadWriteLock {
/** /**
* 写次数统计 * 写次数统计
*/ */
private int writeCount = 0; private volatile int writeCount = 0;
/** /**
* 获取读锁,读锁在写锁不存在的时候才能获取 * 获取读锁,读锁在写锁不存在的时候才能获取

View File

@@ -36,7 +36,7 @@ public class LockReadWriteRe implements IReadWriteLock {
/** /**
* 写次数统计 * 写次数统计
*/ */
private int writeCount = 0; private volatile int writeCount = 0;
/** /**
* 获取读锁,读锁在写锁不存在的时候才能获取 * 获取读锁,读锁在写锁不存在的时候才能获取
@@ -60,7 +60,7 @@ public class LockReadWriteRe implements IReadWriteLock {
* 尝试获取读锁 * 尝试获取读锁
* *
* 读锁之间是不互斥的,这里后续需要优化。 * 读锁之间是不互斥的,这里后续需要优化。
* *
* @return 是否成功 * @return 是否成功
* @since 0.0.2 * @since 0.0.2
*/ */

View File

@@ -0,0 +1,88 @@
package com.github.houbb.lock.redis.core;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.api.core.IReadWriteLock;
/**
* 锁工具
*
* @author binbin.hou
* @since 0.0.3
*/
public final class Locks {
private Locks(){}
/**
* 无锁
* @return 锁
* @since 0.0.3
*/
public static ILock none() {
return new LockNone();
}
/**
* 读写锁
* @return 锁
* @since 0.0.3
*/
public static IReadWriteLock readWrite() {
return new LockReadWrite();
}
/**
* 读写锁
* @return 锁
* @since 0.0.3
*/
public static IReadWriteLock readWriteOwner() {
return new LockReadWriteOwner();
}
/**
* 可重入读写锁
* @return 锁
* @since 0.0.3
*/
public static IReadWriteLock readWriteRe() {
return new LockReadWriteRe();
}
/**
* 自旋锁
* @return 锁
* @since 0.0.3
*/
public static ILock spin() {
return new LockSpin();
}
/**
* 可重入自旋锁
* @return 锁
* @since 0.0.3
*/
public static ILock spinRe() {
return new LockSpinRe();
}
/**
* 等待通知锁
* @return 锁
* @since 0.0.3
*/
public static ILock waitNotify() {
return new LockWaitNotify();
}
/**
* 可重入等待通知锁
* @return 锁
* @since 0.0.3
*/
public static ILock waitNotifyRe() {
return new LockWaitNotifyRe();
}
}

28
lock-redis/pom.xml Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>lock</artifactId>
<groupId>com.github.houbb</groupId>
<version>0.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lock-redis</artifactId>
<dependencies>
<!--============================== SELF ==============================-->
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>lock-core</artifactId>
</dependency>
<!--============================== OTHER ==============================-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -3,8 +3,8 @@ package com.github.houbb.lock.redis.bs;
import com.github.houbb.id.api.Id; import com.github.houbb.id.api.Id;
import com.github.houbb.id.core.core.Ids; import com.github.houbb.id.core.core.Ids;
import com.github.houbb.lock.api.core.ILock; import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockRedis; import com.github.houbb.lock.api.support.IOperator;
import com.github.houbb.lock.redis.support.operator.IOperator; import com.github.houbb.lock.redis.lock.LockRedis;
import com.github.houbb.wait.api.IWait; import com.github.houbb.wait.api.IWait;
import com.github.houbb.wait.core.Waits; import com.github.houbb.wait.core.Waits;
@@ -24,7 +24,7 @@ public final class LockRedisBs {
private IWait wait = Waits.threadSleep(); private IWait wait = Waits.threadSleep();
/** /**
* 等待实现 * ID 实现
* @since 0.0.1 * @since 0.0.1
*/ */
private Id id = Ids.uuid32(); private Id id = Ids.uuid32();

View File

@@ -2,9 +2,9 @@ package com.github.houbb.lock.redis.exception;
/** /**
* @author binbin.hou * @author binbin.hou
* @since 0.0.1 * @since 0.0.3
*/ */
public class LockRedisException extends RuntimeException { public class LockRedisException extends LockRuntimeException {
public LockRedisException() { public LockRedisException() {
} }

View File

@@ -0,0 +1 @@
package com.github.houbb.lock.redis.exception;

View File

@@ -1,11 +1,12 @@
package com.github.houbb.lock.redis.core; package com.github.houbb.lock.redis.lock;
import com.github.houbb.heaven.util.lang.StringUtil; import com.github.houbb.heaven.util.lang.StringUtil;
import com.github.houbb.id.api.Id; import com.github.houbb.id.api.Id;
import com.github.houbb.id.core.util.IdThreadLocalHelper; import com.github.houbb.id.core.util.IdThreadLocalHelper;
import com.github.houbb.lock.api.support.IOperator;
import com.github.houbb.lock.redis.constant.LockRedisConst; import com.github.houbb.lock.redis.constant.LockRedisConst;
import com.github.houbb.lock.redis.core.AbstractLock;
import com.github.houbb.lock.redis.exception.LockRedisException; import com.github.houbb.lock.redis.exception.LockRedisException;
import com.github.houbb.lock.redis.support.operator.IOperator;
import com.github.houbb.wait.api.IWait; import com.github.houbb.wait.api.IWait;
/** /**
@@ -57,4 +58,4 @@ public class LockRedis extends AbstractLock {
throw new LockRedisException("Unlock key " + key + " result is failed!"); throw new LockRedisException("Unlock key " + key + " result is failed!");
} }
} }
} }

View File

@@ -0,0 +1 @@
package com.github.houbb.lock.redis;

View File

@@ -1,7 +1,7 @@
package com.github.houbb.lock.redis.support.operator.impl; package com.github.houbb.lock.redis.support.operator;
import com.github.houbb.lock.api.support.IOperator;
import com.github.houbb.lock.redis.constant.LockRedisConst; import com.github.houbb.lock.redis.constant.LockRedisConst;
import com.github.houbb.lock.redis.support.operator.IOperator;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import java.util.Collections; import java.util.Collections;

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>lock</artifactId> <artifactId>lock</artifactId>
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -16,6 +16,10 @@
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<artifactId>lock-core</artifactId> <artifactId>lock-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>lock-redis</artifactId>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@@ -23,4 +27,4 @@
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -1,6 +1,7 @@
package com.github.houbb.lock.test; package com.github.houbb.lock.test.redis;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
@@ -8,6 +9,7 @@ import redis.clients.jedis.Jedis;
* @author binbin.hou * @author binbin.hou
* @since 0.0.1 * @since 0.0.1
*/ */
@Ignore
public class JedisTest { public class JedisTest {
@Test @Test

View File

@@ -1,9 +1,10 @@
package com.github.houbb.lock.test; package com.github.houbb.lock.test.redis;
import com.github.houbb.lock.api.core.ILock; import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.api.support.IOperator;
import com.github.houbb.lock.redis.bs.LockRedisBs; import com.github.houbb.lock.redis.bs.LockRedisBs;
import com.github.houbb.lock.redis.support.operator.IOperator; import com.github.houbb.lock.redis.support.operator.JedisOperator;
import com.github.houbb.lock.redis.support.operator.impl.JedisOperator; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
@@ -11,6 +12,7 @@ import redis.clients.jedis.Jedis;
* @author binbin.hou * @author binbin.hou
* @since 0.0.1 * @since 0.0.1
*/ */
@Ignore
public class LockRedisTest { public class LockRedisTest {
@Test @Test

10
pom.xml
View File

@@ -5,11 +5,12 @@
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<artifactId>lock</artifactId> <artifactId>lock</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>0.0.3-SNAPSHOT</version> <version>0.0.3</version>
<modules> <modules>
<module>lock-api</module> <module>lock-api</module>
<module>lock-core</module> <module>lock-core</module>
<module>lock-test</module> <module>lock-test</module>
<module>lock-redis</module>
</modules> </modules>
<properties> <properties>
@@ -33,7 +34,7 @@
<!--============================== INTER ==============================--> <!--============================== INTER ==============================-->
<plugin.gen.version>1.0.6</plugin.gen.version> <plugin.gen.version>1.0.6</plugin.gen.version>
<heaven.version>0.1.114</heaven.version> <heaven.version>0.1.148</heaven.version>
<id.version>0.0.6</id.version> <id.version>0.0.6</id.version>
<wait.version>0.0.1</wait.version> <wait.version>0.0.1</wait.version>
<log-integration.version>1.1.8</log-integration.version> <log-integration.version>1.1.8</log-integration.version>
@@ -56,6 +57,11 @@
<artifactId>lock-core</artifactId> <artifactId>lock-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>lock-redis</artifactId>
<version>${project.version}</version>
</dependency>
<!--============================== INTER ==============================--> <!--============================== INTER ==============================-->
<dependency> <dependency>

View File

@@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..."
:: 版本号信息(需要手动指定) :: 版本号信息(需要手动指定)
:::: 旧版本名称 :::: 旧版本名称
SET version=0.0.2 SET version=0.0.3
:::: 新版本名称 :::: 新版本名称
SET newVersion=0.0.3 SET newVersion=0.0.4
:::: 组织名称 :::: 组织名称
SET groupName=com.github.houbb SET groupName=com.github.houbb
:::: 项目名称 :::: 项目名称