From 4cf94b55f42a90dc370f413268004f4968d6e676 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Wed, 16 Dec 2020 10:37:36 +0800 Subject: [PATCH 1/4] merge dev --- .DS_Store | Bin 0 -> 6148 bytes README.md | 2 +- doc/.DS_Store | Bin 0 -> 6148 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 doc/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..58c94748487ebd180cf65dba8125ae0fd94d8c36 GIT binary patch literal 6148 zcmeHK%S!A(5bYjEO{+)*7hZ4?aN)+qh>yWt81=3$Trr{xA7f&I69|bUJQhu#RXV3bcZxB_8|`qFF`F@Ffg)A}4DSfeqYg>M zc*X#^su3|6bc(AW$%3J1a*QGaxOWpwGN0w_k`3;xG#Q{3s4(>mW*Zlju51f9Jn^8Rf?qe2`@c1Zdk24&$iP zwCA_8RQhom<*J^padH%=Vb*D6?KCV@yeY2iJzutO5yK7tZ6=%J^ z(OYr4^?D8Lwas2nSk{l_pZjO+o7=nlKY#!Ie|Xfpz~O^cGH0+4PhboX5*8Op0ISD@ zfr)D`Pm?UY1b@F+zX%~QKnxHAqs@RhwXEsUUM8)M7$63|fB`%o98g5pV5w0Z9WbaC z0I&*fC17JOfjN#r*I=m;W05cgWoZ6uEA2HPG{USAKW~dn+}Dmr$c>5 zg){DIq>&gP1_l|x-Vema`+xW2{$B;rKnxHA-;)7e-SKuB@NVXA9ePW=YaP&YP!x

- +git ### 功能特点 - 主体框架:采用最新的Spring Cloud Hoxton SR8, Spring Boot 2.3.6.RELEASE, Spring Cloud Alibaba 2.2.3.RELEASE版本进行系统设计; diff --git a/doc/.DS_Store b/doc/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3157613b373deed0023543cc74924d89b8a58ec4 GIT binary patch literal 6148 zcmeH~&r94u6vt=WwI)_1f}nzjfgZfh z2m(~y^*)5bpkpm=CvonEagfUK)EGwxVeBV^R??6COvcmTvcB);T^PrFWp`{z(KO7C zwOka9Mzbb1w;IEmD4NZBO}yTGGaQ2gm)DyRKublj4oo&08-L+*IZ_}V<%9f)#63PLQI``& zfEI%Ba>CwQzpf^r3H*BkxIYMRRGYL^Dz^?Ox1QYrL+ag_?H zQaN2QxJrk1L2))|sZ^yiE@y^uXl70~6fS3nb|J$Vx0UKr6VL?i5~!$03(x=E$M64l zlk}4&pb0!H0=&B8?6lyM=xiPPI6P|w_%S#d#+6EC3KVo4%L*RF%iz+WPhbVqCM}gh R3z+^9kQj8K3H( Date: Wed, 16 Dec 2020 10:45:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4.DS=5FStore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 58c94748487ebd180cf65dba8125ae0fd94d8c36..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%S!A(5bYjEO{+)*7hZ4?aN)+qh>yWt81=3$Trr{xA7f&I69|bUJQhu#RXV3bcZxB_8|`qFF`F@Ffg)A}4DSfeqYg>M zc*X#^su3|6bc(AW$%3J1a*QGaxOWpwGN0w_k`3;xG#Q{3s4(>mW*Zlju51f9Jn^8Rf?qe2`@c1Zdk24&$iP zwCA_8RQhom<*J^padH%=Vb*D6?KCV@yeY2iJzutO5yK7tZ6=%J^ z(OYr4^?D8Lwas2nSk{l_pZjO+o7=nlKY#!Ie|Xfpz~O^cGH0+4PhboX5*8Op0ISD@ zfr)D`Pm?UY1b@F+zX%~QKnxHAqs@RhwXEsUUM8)M7$63|fB`%o98g5pV5w0Z9WbaC z0I&*fC17JOfjN#r*I=m;W05cgWoZ6uEA2HPG{USAKW~dn+}Dmr$c>5 zg){DIq>&gP1_l|x-Vema`+xW2{$B;rKnxHA-;)7e-SKuB@NVXA9ePW=YaP&YP!x Date: Sat, 16 Jan 2021 10:25:59 +0800 Subject: [PATCH 3/4] del .DS_Store --- doc/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 doc/.DS_Store diff --git a/doc/.DS_Store b/doc/.DS_Store deleted file mode 100644 index 3157613b373deed0023543cc74924d89b8a58ec4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~&r94u6vt=WwI)_1f}nzjfgZfh z2m(~y^*)5bpkpm=CvonEagfUK)EGwxVeBV^R??6COvcmTvcB);T^PrFWp`{z(KO7C zwOka9Mzbb1w;IEmD4NZBO}yTGGaQ2gm)DyRKublj4oo&08-L+*IZ_}V<%9f)#63PLQI``& zfEI%Ba>CwQzpf^r3H*BkxIYMRRGYL^Dz^?Ox1QYrL+ag_?H zQaN2QxJrk1L2))|sZ^yiE@y^uXl70~6fS3nb|J$Vx0UKr6VL?i5~!$03(x=E$M64l zlk}4&pb0!H0=&B8?6lyM=xiPPI6P|w_%S#d#+6EC3KVo4%L*RF%iz+WPhbVqCM}gh R3z+^9kQj8K3H( Date: Fri, 11 Jun 2021 11:56:03 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20=E6=8D=95=E8=8E=B7=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/RedissonLockException.java | 16 ++++++++ mate-core/mate-starter-lock/pom.xml | 7 +++- .../lock/aspect/DistributedLockHandler.java | 37 +++++++++---------- 3 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/RedissonLockException.java diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/RedissonLockException.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/RedissonLockException.java new file mode 100644 index 00000000..625f8502 --- /dev/null +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/RedissonLockException.java @@ -0,0 +1,16 @@ +package vip.mate.core.common.exception; + + +/** + * 获取锁处理异常 + * + * @author zhangyu + */ +public class RedissonLockException extends RuntimeException { + + private static final long serialVersionUID = -6422212844622271825L; + + public RedissonLockException(String message) { + super(message); + } +} diff --git a/mate-core/mate-starter-lock/pom.xml b/mate-core/mate-starter-lock/pom.xml index 65ec6995..edbf0a68 100644 --- a/mate-core/mate-starter-lock/pom.xml +++ b/mate-core/mate-starter-lock/pom.xml @@ -12,6 +12,11 @@ mate-starter-lock + + vip.mate + mate-starter-common + provided + org.redisson redisson @@ -31,4 +36,4 @@ - \ No newline at end of file + diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java index 5974c622..68bd202a 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java @@ -1,12 +1,13 @@ package vip.mate.core.lock.aspect; +import java.text.MessageFormat; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import vip.mate.core.common.exception.RedissonLockException; import vip.mate.core.lock.RedissonLock; import vip.mate.core.lock.annotation.DistributedLock; @@ -27,33 +28,29 @@ public class DistributedLockHandler { /** * 切面环绕通知 - * @param joinPoint ProceedingJoinPoint + * + * @param joinPoint ProceedingJoinPoint * @param distributedLock DistributedLock * @return Object */ @Around("@annotation(distributedLock)") - public Object around(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) { + public Object around(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) throws Throwable { log.info("[开始]执行RedisLock环绕通知,获取Redis分布式锁开始"); //获取锁名称 String lockName = distributedLock.value(); - //获取超时时间 - int expireSeconds = distributedLock.expireSeconds(); - - if (redissonLock.lock(lockName, expireSeconds)) { - try { - log.info("获取Redis分布式锁[成功],加锁完成,开始执行业务逻辑..."); - return joinPoint.proceed(); - } catch (Throwable throwable) { - log.error("获取Redis分布式锁[异常],加锁失败", throwable); - throwable.printStackTrace(); - } finally { - redissonLock.release(lockName); - } - log.info("释放Redis分布式锁[成功],解锁完成,结束业务逻辑..."); - } else { + //获取超时时间并获取锁 + if (!redissonLock.lock(lockName, distributedLock.expireSeconds())) { log.error("获取Redis分布式锁[失败]"); + throw new RedissonLockException(MessageFormat.format("获取Redis分布式失败:{0}", lockName)); + } + log.info("获取Redis分布式锁[成功],加锁完成,开始执行业务逻辑..."); + try { + return joinPoint.proceed(); + } finally { + redissonLock.release(lockName); + log.info("释放Redis分布式锁[成功],解锁完成,结束业务逻辑..."); + log.info("[结束]执行RedisLock环绕通知"); } - log.info("[结束]执行RedisLock环绕通知"); - return null; } + }