Skip to content

Commit 3f234db

Browse files
author
yangzhao
committed
新增分布式锁模块(普通分布式锁和分布式方法锁)
1 parent 56165c8 commit 3f234db

File tree

22 files changed

+568
-153
lines changed

22 files changed

+568
-153
lines changed

common-cache/pom.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>common-project</artifactId>
55
<groupId>com.yz</groupId>
6-
<version>1.0.1</version>
6+
<version>1.0.2</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99

@@ -14,18 +14,14 @@
1414
<url>http://maven.apache.org</url>
1515

1616
<dependencies>
17-
1817
<dependency>
19-
<groupId>com.yz</groupId>
20-
<artifactId>common-core</artifactId>
21-
<version>1.0.1</version>
18+
<groupId>redis.clients</groupId>
19+
<artifactId>jedis</artifactId>
2220
</dependency>
23-
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
2421
<dependency>
2522
<groupId>org.springframework.data</groupId>
2623
<artifactId>spring-data-redis</artifactId>
2724
</dependency>
28-
2925
</dependencies>
3026

3127
<build>

common-core/src/main/java/com/yz/common/core/redis/RedisUtil.java renamed to common-cache/src/main/java/com/yz/common/cache/RedisUtil.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package com.yz.common.core.redis;
1+
package com.yz.common.cache;
22

33
import java.util.List;
44
import java.util.Map;
55
import java.util.Set;
66
import com.alibaba.fastjson.JSON;
7-
import com.yz.common.core.utils.PropertyUtil;
87
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
98
import org.slf4j.Logger;
109
import org.slf4j.LoggerFactory;
@@ -69,23 +68,6 @@ public RedisUtil(String redisHost, String redisPassword, int redisPort, int data
6968
}
7069

7170

72-
public RedisUtil(String propertiesUri) {
73-
GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
74-
genericObjectPoolConfig.setMaxTotal(MAX_ACTIVE);
75-
genericObjectPoolConfig.setMaxIdle(MAX_IDLE);
76-
genericObjectPoolConfig.setMaxWaitMillis(MAX_WAIT);
77-
genericObjectPoolConfig.setTestOnBorrow(TEST_ON_BORROW);
78-
PropertyUtil property = new PropertyUtil(propertiesUri);
79-
String host = property.getProperty("redis.host");
80-
String password = property.getProperty("redis.password");
81-
int port = Integer.parseInt(property.getProperty("redis.port"));
82-
//初始化Redis连接池
83-
this.pool = new JedisPool(genericObjectPoolConfig, host, port, TIMEOUT, password);
84-
int dataBase = Integer.parseInt(property.getProperty("redis.database"));
85-
this.dataBase = dataBase;
86-
logger.info("----开启redis缓存(数据库为:" + dataBase + ")");
87-
}
88-
8971
/**
9072
* 获取Jedis实例
9173
*

common-cache/src/main/java/com/yz/common/cache/redis/JedisImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.yz.common.cache.redis;
22

33
import com.alibaba.fastjson.JSON;
4-
import com.yz.common.core.redis.RedisUtil;
4+
import com.yz.common.cache.RedisUtil;
55
import org.apache.commons.lang.StringUtils;
66
import org.springframework.util.CollectionUtils;
77

88
import java.util.HashMap;
9-
import java.util.Iterator;
109
import java.util.List;
1110
import java.util.Map;
12-
import java.util.Set;
1311
import java.util.stream.Collectors;
1412

1513

common-core/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>common-project</artifactId>
55
<groupId>com.yz</groupId>
6-
<version>1.0.1</version>
6+
<version>1.0.2</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99

@@ -19,6 +19,11 @@
1919
<artifactId>httpclient</artifactId>
2020
</dependency>
2121

22+
<dependency>
23+
<groupId>org.apache.httpcomponents</groupId>
24+
<artifactId>httpmime</artifactId>
25+
</dependency>
26+
2227
<!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj -->
2328
<dependency>
2429
<groupId>org.apache.solr</groupId>
@@ -58,11 +63,6 @@
5863
<artifactId>jackson-databind</artifactId>
5964
</dependency>
6065

61-
<dependency>
62-
<groupId>redis.clients</groupId>
63-
<artifactId>jedis</artifactId>
64-
</dependency>
65-
6666
<!-- https://mvnrepository.com/artifact/com.google.zxing/core -->
6767
<dependency>
6868
<groupId>com.google.zxing</groupId>

common-core/pom.xml.versionsBackup

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>common-project</artifactId>
5+
<groupId>com.yz</groupId>
6+
<version>1.0.1</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>common-core</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>common-core</name>
14+
<url>http://maven.apache.org</url>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.httpcomponents</groupId>
19+
<artifactId>httpclient</artifactId>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.apache.httpcomponents</groupId>
24+
<artifactId>httpmime</artifactId>
25+
</dependency>
26+
27+
<!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj -->
28+
<dependency>
29+
<groupId>org.apache.solr</groupId>
30+
<artifactId>solr-solrj</artifactId>
31+
</dependency>
32+
33+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
34+
<dependency>
35+
<groupId>org.apache.poi</groupId>
36+
<artifactId>poi</artifactId>
37+
</dependency>
38+
39+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
40+
<dependency>
41+
<groupId>org.apache.poi</groupId>
42+
<artifactId>poi-ooxml</artifactId>
43+
</dependency>
44+
45+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
46+
<dependency>
47+
<groupId>org.apache.poi</groupId>
48+
<artifactId>poi-scratchpad</artifactId>
49+
</dependency>
50+
51+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
52+
<dependency>
53+
<groupId>org.apache.poi</groupId>
54+
<artifactId>poi-ooxml-schemas</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.core</groupId>
59+
<artifactId>jackson-core</artifactId>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.fasterxml.jackson.core</groupId>
63+
<artifactId>jackson-databind</artifactId>
64+
</dependency>
65+
66+
<!-- https://mvnrepository.com/artifact/com.google.zxing/core -->
67+
<dependency>
68+
<groupId>com.google.zxing</groupId>
69+
<artifactId>core</artifactId>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>org.hibernate.validator</groupId>
74+
<artifactId>hibernate-validator</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.javassist</groupId>
78+
<artifactId>javassist</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>dom4j</groupId>
82+
<artifactId>dom4j</artifactId>
83+
</dependency>
84+
</dependencies>
85+
86+
<build>
87+
<finalName>${artifactId}</finalName>
88+
</build>
89+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.yz.common.core.annotations;
2+
3+
import java.lang.annotation.*;
4+
import java.util.concurrent.TimeUnit;
5+
6+
/**
7+
* @author: yangzhao
8+
* @Date: 2019/7/25 14:34
9+
* @Description:
10+
*/
11+
@Target({ElementType.METHOD})
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Documented
14+
public @interface MethodLock {
15+
/**
16+
* 锁标识
17+
* @return
18+
*/
19+
String key() default "";
20+
21+
/**
22+
* 时间
23+
* @return
24+
*/
25+
long time() default 10;
26+
27+
/**
28+
* 单位
29+
* @return
30+
*/
31+
TimeUnit timeUnit() default TimeUnit.SECONDS;
32+
33+
/**
34+
* 是否自动解锁
35+
* @return
36+
*/
37+
boolean autoUnLock() default true;
38+
39+
/**
40+
* 重试次数
41+
* @return
42+
*/
43+
int attemptNum() default 0;
44+
45+
}

common-core/src/main/java/com/yz/common/core/exception/HandlerException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Created by yangzhao on 17/3/29.
55
*/
6-
public class HandlerException extends Exception {
6+
public class HandlerException extends RuntimeException {
77

88
private int code;
99

common-core/src/main/java/com/yz/common/core/redis/RedisLockUtil.java

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)