Skip to content

Commit cadeb55

Browse files
committed
Init
1 parent 0ffafd8 commit cadeb55

File tree

32 files changed

+610
-247
lines changed

32 files changed

+610
-247
lines changed

.idea/encodings.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,76 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>org.example</groupId>
7+
<groupId>cc.coopersoft</groupId>
88
<artifactId>uid-generator-spring-boot</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.0.1.BATE</version>
10+
<packaging>pom</packaging>
11+
<modules>
12+
<module>uid-generator</module>
13+
<module>uid-worker-id-jdbc-spring-boot-starter</module>
14+
<module>uid-generator-api</module>
15+
<module>uid-worker-id-db-provider</module>
16+
<module>uid-generator-spring-boot-starter</module>
17+
<module>uid-worker-id-r2dbc-spring-boot-starter</module>
18+
</modules>
1019

1120
<properties>
1221
<maven.compiler.source>15</maven.compiler.source>
1322
<maven.compiler.target>15</maven.compiler.target>
1423
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<slf4j-version>2.0.6</slf4j-version>
1525
</properties>
16-
26+
27+
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-dependencies</artifactId>
33+
<version>2.7.8</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
</dependencies>
38+
</dependencyManagement>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>org.slf4j</groupId>
44+
<artifactId>slf4j-api</artifactId>
45+
<version>${slf4j-version}</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.slf4j</groupId>
50+
<artifactId>log4j-over-slf4j</artifactId>
51+
<version>${slf4j-version}</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-simple</artifactId>
57+
<version>${slf4j-version}</version>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
62+
<dependency>
63+
<groupId>org.projectlombok</groupId>
64+
<artifactId>lombok</artifactId>
65+
<version>1.18.26</version>
66+
<scope>provided</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-test</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
</dependencies>
76+
77+
78+
1779
</project>
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
package cc.coopersoft.cloud.uid;public class UidCachedProperties {
1+
package cc.coopersoft.cloud.uid;
2+
3+
public interface UidCachedProperties {
4+
5+
/**
6+
* RingBuffer size扩容参数, 可提高UID生成的吞吐量.
7+
* 默认:3, 原bufferSize=8192, 扩容后bufferSize= 8192 << 3 = 65536
8+
*/
9+
int getBoostPower();
10+
11+
/**
12+
* 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
13+
* 举例: bufferSize=1024, paddingFactor=50 -> threshold=1024 * 50 / 100 = 512.
14+
* 当环上可用UID数量 < 512时, 将自动对RingBuffer进行填充补全
15+
*/
16+
int getPaddingFactor();
17+
18+
Long getScheduleInterval();
19+
220
}

uid-generator-spring-boot-starter/pom.xml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>cc.coopersoft</groupId>
88
<artifactId>uid-generator-spring-boot</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.0.1.BATE</version>
1010
</parent>
1111

1212
<artifactId>uid-generator-spring-boot-starter</artifactId>
@@ -17,4 +17,51 @@
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

20+
<dependencies>
21+
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-autoconfigure</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>cc.coopersoft</groupId>
29+
<artifactId>uid-generator</artifactId>
30+
<version>1.0.1.BATE</version>
31+
</dependency>
32+
33+
34+
<!-- test by jdbc and mariadb -->
35+
36+
<!-- <dependency>-->
37+
<!-- <groupId>cc.coopersoft</groupId>-->
38+
<!-- <artifactId>uid-worker-id-jdbc-spring-boot-starter</artifactId>-->
39+
<!-- <version>1.0.1.BATE</version>-->
40+
<!-- <scope>test</scope>-->
41+
<!-- </dependency>-->
42+
43+
<!-- <dependency>-->
44+
<!-- <groupId>org.mariadb.jdbc</groupId>-->
45+
<!-- <artifactId>mariadb-java-client</artifactId>-->
46+
<!-- <scope>test</scope>-->
47+
<!-- </dependency>-->
48+
49+
<!-- test by r2dbc and mariadb -->
50+
<dependency>
51+
<groupId>cc.coopersoft</groupId>
52+
<artifactId>uid-worker-id-r2dbc-spring-boot-starter</artifactId>
53+
<version>1.0.1.BATE</version>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
58+
<dependency>
59+
<groupId>org.mariadb</groupId>
60+
<artifactId>r2dbc-mariadb</artifactId>
61+
<scope>test</scope>
62+
<version>1.1.3</version>
63+
</dependency>
64+
65+
</dependencies>
66+
2067
</project>
Lines changed: 108 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package com.github.wujun234.uid;
2-
3-
import com.github.wujun234.uid.impl.CachedUidGenerator;
4-
import com.github.wujun234.uid.impl.UidProperties;
5-
import com.github.wujun234.uid.worker.DisposableWorkerIdAssigner;
6-
import com.github.wujun234.uid.worker.WorkerIdAssigner;
7-
import com.github.wujun234.uid.impl.DefaultUidGenerator;
8-
import org.mybatis.spring.annotation.MapperScan;
9-
import org.springframework.beans.factory.annotation.Autowired;
10-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1+
package cc.coopersoft.cloud.uid;
2+
3+
import cc.coopersoft.cloud.uid.buffer.RejectedPutBufferHandler;
4+
import cc.coopersoft.cloud.uid.buffer.RejectedTakeBufferHandler;
5+
import cc.coopersoft.cloud.uid.impl.CachedUidGenerator;
6+
import cc.coopersoft.cloud.uid.impl.DefaultUidGenerator;
7+
import cc.coopersoft.cloud.uid.impl.UidCachedConfigProperties;
8+
import cc.coopersoft.cloud.uid.impl.UidConfigProperties;
9+
import cc.coopersoft.cloud.uid.worker.WorkerIdAssigner;
10+
import lombok.extern.slf4j.Slf4j;
1111
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
12-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
12+
import org.springframework.boot.context.properties.ConfigurationProperties;
1313
import org.springframework.context.annotation.Bean;
1414
import org.springframework.context.annotation.Configuration;
1515
import org.springframework.context.annotation.Lazy;
@@ -20,35 +20,104 @@
2020
* @author wujun
2121
* @date 2019.02.20 10:57
2222
*/
23+
@Slf4j
2324
@Configuration
24-
@ConditionalOnClass({ DefaultUidGenerator.class, CachedUidGenerator.class })
25-
@MapperScan({ "com.github.wujun234.uid.worker.mapper" })
26-
@EnableConfigurationProperties(UidProperties.class)
2725
public class UidAutoConfigure {
2826

29-
private final UidProperties uidProperties;
30-
31-
public UidAutoConfigure(UidProperties uidProperties) {
32-
this.uidProperties = uidProperties;
33-
}
34-
35-
@Bean
36-
@ConditionalOnMissingBean
37-
@Lazy
38-
DefaultUidGenerator defaultUidGenerator() {
39-
return new DefaultUidGenerator(uidProperties);
40-
}
41-
42-
@Bean
43-
@ConditionalOnMissingBean
44-
@Lazy
45-
CachedUidGenerator cachedUidGenerator() {
46-
return new CachedUidGenerator(uidProperties);
47-
}
48-
49-
@Bean
50-
@ConditionalOnMissingBean
51-
WorkerIdAssigner workerIdAssigner() {
52-
return new DisposableWorkerIdAssigner();
53-
}
27+
28+
private final WorkerIdAssigner workerIdAssigner;
29+
30+
//private final RejectedBufferConfigureImpl rejectedBufferConfigure;
31+
32+
public UidAutoConfigure(WorkerIdAssigner workerIdAssigner) {
33+
this.workerIdAssigner = workerIdAssigner;
34+
//this.rejectedBufferConfigure = rejectedBufferConfigure;
35+
}
36+
37+
@Bean
38+
@ConditionalOnMissingBean
39+
@Lazy
40+
@ConfigurationProperties(prefix = "uid.cached-uid-generator")
41+
UidCachedConfigProperties uidCachedProperties() {
42+
return new UidCachedConfigProperties();
43+
}
44+
45+
@Bean
46+
@ConditionalOnMissingBean
47+
@Lazy
48+
@ConfigurationProperties(prefix = "uid")
49+
UidProperties uidProperties() {
50+
return new UidConfigProperties();
51+
}
52+
53+
@Bean
54+
@ConditionalOnMissingBean
55+
@Lazy
56+
DefaultUidGenerator defaultUidGenerator(UidProperties uidProperties) {
57+
return new DefaultUidGenerator(uidProperties, workerIdAssigner);
58+
}
59+
60+
@Bean
61+
@ConditionalOnMissingBean
62+
@Lazy
63+
CachedUidGenerator cachedUidGenerator(
64+
UidProperties uidProperties,
65+
UidCachedProperties uidCachedProperties) {
66+
return new CachedUidGenerator(uidProperties, uidCachedProperties, workerIdAssigner);
67+
}
68+
69+
@Bean
70+
@ConditionalOnMissingBean
71+
@Lazy
72+
CachedUidGenerator cachedUidGenerator(
73+
UidProperties uidProperties,
74+
UidCachedProperties uidCachedProperties,
75+
RejectedTakeBufferHandler rejectedTakeBufferHandler,
76+
RejectedPutBufferHandler rejectedPutBufferHandler) {
77+
return new CachedUidGenerator(uidProperties,
78+
uidCachedProperties,
79+
workerIdAssigner,
80+
rejectedPutBufferHandler,
81+
rejectedTakeBufferHandler);
82+
}
83+
84+
@Bean
85+
@ConditionalOnMissingBean
86+
@Lazy
87+
CachedUidGenerator cachedUidGenerator(
88+
UidProperties uidProperties,
89+
UidCachedProperties uidCachedProperties,
90+
RejectedPutBufferHandler rejectedPutBufferHandler) {
91+
return new CachedUidGenerator(
92+
uidProperties,
93+
uidCachedProperties,
94+
workerIdAssigner,
95+
rejectedPutBufferHandler);
96+
}
97+
98+
@Bean
99+
@ConditionalOnMissingBean
100+
@Lazy
101+
CachedUidGenerator cachedUidGenerator(
102+
UidProperties uidProperties,
103+
UidCachedProperties uidCachedProperties,
104+
RejectedTakeBufferHandler rejectedTakeBufferHandler) {
105+
return new CachedUidGenerator(
106+
uidProperties,
107+
uidCachedProperties,
108+
workerIdAssigner,
109+
rejectedTakeBufferHandler);
110+
}
111+
112+
/**
113+
* example custom rejected handler
114+
*
115+
* @return RejectedPutBufferHandler
116+
*/
117+
// @Bean
118+
// RejectedPutBufferHandler customPutHandler() {
119+
// return (r, i) -> {
120+
// do your
121+
// };
122+
// }
54123
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.github.wujun234.uid.UidAutoConfigure
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cc.coopersoft.cloud.uid.UidAutoConfigure

0 commit comments

Comments
 (0)