mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
chore(v0.11): 全路径纳入版本库与走查整改
- .gitignore:显式放行全部 maven-*、scripts、dev-support、frontend、反1、artifacts、历史导出目录 - 新增跟踪:device-manager/device-sdk/legacy-public、davinci-manager、cwos-*、cwos-resource 等源码与附属资源 - davinci FileStorageManagerImpl:Feign Response 关闭、绝对 URL 拉流 SSRF 校验(协议/主机/解析地址) - davinci OuterCallFeignClient:补充契约说明 - cwos-common-aks AksConstant:final 类 + 私有构造防误实例化 - device-manager DeviceConstant:沿用 DEFAULT_APPLICATIONID 拼写修正 Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.18.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>cn.cloudwalk.intelligent</groupId>
|
||||
<artifactId>cloudwalk-intelligent-component-lock</artifactId>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>cloudwalk-intelligent-component-lock</name>
|
||||
<description>源码来自 反1 zip。Redisson 2.x 与 Spring Boot 2.1 由显式版本约束。</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<redisson.version>2.15.2</redisson.version>
|
||||
<guava.version>28.2-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package cn.cloudwalk.intelligent.lock;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.locks.LockFactory;
|
||||
import cn.cloudwalk.intelligent.lock.properties.LockProperties;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({LockProperties.class})
|
||||
@ConditionalOnProperty(prefix = "intelligent.lock", name = {"enable"}, havingValue = "true")
|
||||
public class IntelligentLockConfiguration
|
||||
{
|
||||
@Bean
|
||||
public LockFactory lockFactory() {
|
||||
return new LockFactory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package cn.cloudwalk.intelligent.lock.annotation;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.enums.LockType;
|
||||
import cn.cloudwalk.intelligent.lock.locks.handler.LockAcquireTimeoutStrategy;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface RequiredLock {
|
||||
String name() default "DEFAULT-LOCK";
|
||||
|
||||
LockType lockType() default LockType.REENTRANT;
|
||||
|
||||
long lockWaitTime() default -1L;
|
||||
|
||||
long leaseTime() default -1L;
|
||||
|
||||
LockAcquireTimeoutStrategy lockAcquireTimeoutStrategy() default LockAcquireTimeoutStrategy.FAIL_FAST;
|
||||
|
||||
String customAcquireTimeoutHandleMethod() default "";
|
||||
}
|
||||
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
package cn.cloudwalk.intelligent.lock.aop;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.annotation.RequiredLock;
|
||||
import cn.cloudwalk.intelligent.lock.common.exception.AcquireLockTimeoutException;
|
||||
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
|
||||
import cn.cloudwalk.intelligent.lock.common.util.ExpressionParseUtil;
|
||||
import cn.cloudwalk.intelligent.lock.locks.Lock;
|
||||
import cn.cloudwalk.intelligent.lock.locks.LockFactory;
|
||||
import cn.cloudwalk.intelligent.lock.properties.LockProperties;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(-999)
|
||||
public class LockAspect
|
||||
{
|
||||
/* 37 */ private static final Logger logger = LoggerFactory.getLogger(LockAspect.class);
|
||||
|
||||
@Autowired
|
||||
private LockFactory lockFactory;
|
||||
|
||||
@Autowired
|
||||
private LockProperties lockProperties;
|
||||
|
||||
/* 45 */ private ThreadLocal<Lock> currentThreadLock = new ThreadLocal<>();
|
||||
/* 46 */ private ThreadLocal<LockResult> currentThreadLockResult = new ThreadLocal<>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Around("@annotation(requiredLock)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, RequiredLock requiredLock) throws Throwable {
|
||||
/* 58 */ LockInfo lockInfo = getLockInfo(joinPoint, requiredLock);
|
||||
/* 59 */ this.currentThreadLockResult.set(new LockResult(lockInfo, Boolean.valueOf(false)));
|
||||
/* 60 */ Lock lock = this.lockFactory.create(lockInfo);
|
||||
/* 61 */ boolean isAcquired = lock.acquire();
|
||||
|
||||
/* 63 */ if (!isAcquired) {
|
||||
/* 64 */ if (logger.isWarnEnabled()) {
|
||||
/* 65 */ logger.warn("获取锁等待超时({})", lockInfo.getName());
|
||||
}
|
||||
|
||||
/* 68 */ if (StringUtils.isEmpty(requiredLock.customAcquireTimeoutHandleMethod()))
|
||||
{
|
||||
|
||||
|
||||
/* 72 */ requiredLock.lockAcquireTimeoutStrategy().handle(lockInfo, lock, (JoinPoint)joinPoint);
|
||||
}
|
||||
|
||||
/* 75 */ throw new AcquireLockTimeoutException(String.format("获取锁(%s)超时(%dms)", new Object[] { lockInfo.getName(),
|
||||
/* 76 */ Long.valueOf(lockInfo.getLockWaitTime()) }));
|
||||
}
|
||||
|
||||
|
||||
/* 80 */ this.currentThreadLock.set(lock);
|
||||
/* 81 */ ((LockResult)this.currentThreadLockResult.get()).setLocked(Boolean.valueOf(true));
|
||||
|
||||
/* 83 */ return joinPoint.proceed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@AfterReturning("@annotation(requiredLock)")
|
||||
public void afterReturning(JoinPoint joinPoint, RequiredLock requiredLock) throws Throwable {
|
||||
/* 95 */ releaseLock();
|
||||
/* 96 */ flushThreadLocal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@AfterThrowing(value = "@annotation(requiredLock)", throwing = "throwable")
|
||||
public void afterThrowing(JoinPoint joinPoint, RequiredLock requiredLock, Throwable throwable) throws Throwable {
|
||||
releaseLock();
|
||||
flushThreadLocal();
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
private void flushThreadLocal() {
|
||||
this.currentThreadLock.remove();
|
||||
this.currentThreadLockResult.remove();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private LockInfo getLockInfo(ProceedingJoinPoint joinPoint, RequiredLock lock) {
|
||||
long lockWaitTime = (lock.lockWaitTime() < 0L) ? this.lockProperties.getDefaultWaitTime().longValue() : lock.lockWaitTime();
|
||||
|
||||
|
||||
long leaseTime = (lock.leaseTime() <= 0L) ? -1L : lock.leaseTime();
|
||||
String lockName = parseLockName(joinPoint, lock.name());
|
||||
return new LockInfo(lock.lockType(), lockName, lockWaitTime, leaseTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String parseLockName(ProceedingJoinPoint joinPoint, String name) {
|
||||
return (String)ExpressionParseUtil.parse(joinPoint, name, String.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void releaseLock() throws Throwable {
|
||||
LockResult lockResult = this.currentThreadLockResult.get();
|
||||
if (lockResult.getLocked().booleanValue()) {
|
||||
boolean releaseRes = ((Lock)this.currentThreadLock.get()).unlock();
|
||||
lockResult.setLocked(Boolean.valueOf(false));
|
||||
if (!releaseRes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class LockResult
|
||||
{
|
||||
private LockInfo lockInfo;
|
||||
|
||||
|
||||
private Boolean isLocked;
|
||||
|
||||
|
||||
public LockResult(LockInfo lockInfo, Boolean isLocked) {
|
||||
this.lockInfo = lockInfo;
|
||||
this.isLocked = isLocked;
|
||||
}
|
||||
|
||||
public LockInfo getLockInfo() {
|
||||
return this.lockInfo;
|
||||
}
|
||||
|
||||
public void setLockInfo(LockInfo lockInfo) {
|
||||
this.lockInfo = lockInfo;
|
||||
}
|
||||
|
||||
public Boolean getLocked() {
|
||||
return this.isLocked;
|
||||
}
|
||||
|
||||
public void setLocked(Boolean locked) {
|
||||
this.isLocked = locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package cn.cloudwalk.intelligent.lock.common.enums;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum LockType
|
||||
{
|
||||
REENTRANT,
|
||||
|
||||
|
||||
|
||||
|
||||
REDLOCK;
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package cn.cloudwalk.intelligent.lock.common.exception;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class AcquireLockTimeoutException
|
||||
extends RuntimeException
|
||||
{
|
||||
public AcquireLockTimeoutException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package cn.cloudwalk.intelligent.lock.common.exception;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class LockOperationException
|
||||
extends RuntimeException
|
||||
{
|
||||
public LockOperationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LockOperationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package cn.cloudwalk.intelligent.lock.common.model;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.enums.LockType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class LockInfo
|
||||
{
|
||||
private LockType type;
|
||||
private String name;
|
||||
private long lockWaitTime;
|
||||
private long leaseTime;
|
||||
|
||||
public LockInfo(LockType type, String name, long lockWaitTime, long leaseTime) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.lockWaitTime = lockWaitTime;
|
||||
this.leaseTime = leaseTime;
|
||||
}
|
||||
|
||||
public LockType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(LockType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getLockWaitTime() {
|
||||
return this.lockWaitTime;
|
||||
}
|
||||
|
||||
public void setLockWaitTime(long lockWaitTime) {
|
||||
this.lockWaitTime = lockWaitTime;
|
||||
}
|
||||
|
||||
public long getLeaseTime() {
|
||||
return this.leaseTime;
|
||||
}
|
||||
|
||||
public void setLeaseTime(long leaseTime) {
|
||||
this.leaseTime = leaseTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package cn.cloudwalk.intelligent.lock.common.util;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ExpressionParseUtil
|
||||
{
|
||||
private static ExpressionParser parser = (ExpressionParser)new SpelExpressionParser();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static <T> T parse(ProceedingJoinPoint joinPoint, String spel, Class<T> clazz) {
|
||||
String[] parameterNames = (new LocalVariableTableParameterNameDiscoverer()).getParameterNames(((MethodSignature)joinPoint.getSignature()).getMethod());
|
||||
Object[] values = joinPoint.getArgs();
|
||||
|
||||
StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
standardEvaluationContext.setVariable(parameterNames[i], values[i]);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(spel)) {
|
||||
return null;
|
||||
}
|
||||
Expression expression = parser.parseExpression(spel);
|
||||
return (T)expression.getValue((EvaluationContext)standardEvaluationContext, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package cn.cloudwalk.intelligent.lock.locks;
|
||||
|
||||
public interface Lock {
|
||||
boolean acquire();
|
||||
|
||||
boolean unlock();
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package cn.cloudwalk.intelligent.lock.locks;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class LockFactory
|
||||
{
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public Lock create(LockInfo lockInfo) {
|
||||
return new ReentrantLock(lockInfo, this.redissonClient);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package cn.cloudwalk.intelligent.lock.locks;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.exception.LockOperationException;
|
||||
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ReentrantLock
|
||||
implements Lock
|
||||
{
|
||||
private LockInfo lockInfo;
|
||||
private RLock rLock;
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public ReentrantLock(LockInfo lockInfo, RedissonClient redissonClient) {
|
||||
this.lockInfo = lockInfo;
|
||||
this.redissonClient = redissonClient;
|
||||
}
|
||||
|
||||
|
||||
public boolean acquire() {
|
||||
try {
|
||||
this.rLock = this.redissonClient.getLock(this.lockInfo.getName());
|
||||
return this.rLock.tryLock(this.lockInfo.getLockWaitTime(), this.lockInfo.getLeaseTime(), TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
throw new LockOperationException("获取锁操作异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean unlock() {
|
||||
if (this.rLock.isHeldByCurrentThread()) {
|
||||
try {
|
||||
return ((Boolean)this.rLock.forceUnlockAsync().get()).booleanValue();
|
||||
} catch (Exception e) {
|
||||
throw new LockOperationException("释放锁操作异常", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package cn.cloudwalk.intelligent.lock.locks.handler;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
|
||||
import cn.cloudwalk.intelligent.lock.locks.Lock;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
public interface LockAcquireTimeoutHandler {
|
||||
void handle(LockInfo paramLockInfo, Lock paramLock, JoinPoint paramJoinPoint);
|
||||
}
|
||||
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package cn.cloudwalk.intelligent.lock.locks.handler;
|
||||
|
||||
import cn.cloudwalk.intelligent.lock.common.exception.AcquireLockTimeoutException;
|
||||
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
|
||||
import cn.cloudwalk.intelligent.lock.locks.Lock;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum LockAcquireTimeoutStrategy
|
||||
implements LockAcquireTimeoutHandler
|
||||
{
|
||||
NO_OPERATION
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {}
|
||||
},
|
||||
FAIL_FAST
|
||||
{
|
||||
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {
|
||||
throw new AcquireLockTimeoutException(String.format("获取锁(%s)超时(%dms)", new Object[] { lockInfo.getName(),
|
||||
Long.valueOf(lockInfo.getLockWaitTime())
|
||||
|
||||
|
||||
|
||||
}));
|
||||
}
|
||||
},
|
||||
KEEP_ACQUIRE
|
||||
{
|
||||
private static final long DEFAULT_INTERVAL = 100L;
|
||||
|
||||
private static final long DEFAULT_MAX_INTERVAL = 180000L;
|
||||
|
||||
|
||||
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {
|
||||
long interval = 100L;
|
||||
while (!lock.acquire()) {
|
||||
|
||||
if (interval > 180000L) {
|
||||
throw new AcquireLockTimeoutException(String.format("获取锁(%s)阻塞时间过长", new Object[] { lockInfo.getName() }));
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(interval);
|
||||
interval <<= 1L;
|
||||
} catch (InterruptedException e) {
|
||||
throw new AcquireLockTimeoutException(String.format("获取锁(%s)失)", new Object[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package cn.cloudwalk.intelligent.lock.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ConfigurationProperties(prefix = "intelligent.lock.config")
|
||||
public class LockProperties
|
||||
{
|
||||
public static final String PREFIX = "intelligent.lock.config";
|
||||
private Long defaultWaitTime = Long.valueOf(15000L);
|
||||
|
||||
public void setDefaultWaitTime(Long defaultWaitTime) {
|
||||
this.defaultWaitTime = defaultWaitTime;
|
||||
}
|
||||
|
||||
public Long getDefaultWaitTime() {
|
||||
return this.defaultWaitTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user