Skip to content

Commit 2734470

Browse files
committed
update reactive support
1 parent 88611e1 commit 2734470

File tree

75 files changed

+1517
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1517
-681
lines changed

.idea/encodings.xml

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

.idea/misc.xml

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

.idea/sqldialects.xml

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

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.cooperlyt</groupId>
88
<artifactId>uid-generator-spring-boot</artifactId>
9-
<version>1.0.2-SNAPSHOT</version>
9+
<version>1.0.5-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<name>uid-generator-spring-boot</name>
@@ -43,11 +43,12 @@
4343

4444
<modules>
4545
<module>uid-generator</module>
46-
<module>uid-worker-id-jdbc-spring-boot-starter</module>
46+
<module>uid-worker-mybatis-jdbc-spring-boot-starter</module>
4747
<module>uid-generator-api</module>
48-
<module>uid-worker-id-db-provider</module>
4948
<module>uid-generator-spring-boot-starter</module>
50-
<module>uid-worker-id-r2dbc-spring-boot-starter</module>
49+
<module>uid-worker-mybatis-r2dbc-spring-boot-starter</module>
50+
<module>uid-worker-jpa-r2dbc-spring-boot-starter</module>
51+
<module>uid-worker-jap-jdbc-spring-boot-starter</module>
5152
</modules>
5253

5354
<properties>

uid-generator-api/pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.cooperlyt</groupId>
88
<artifactId>uid-generator-spring-boot</artifactId>
9-
<version>1.0.2-SNAPSHOT</version>
9+
<version>1.0.5-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>uid-generator-api</artifactId>
@@ -17,4 +17,23 @@
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

20+
<dependencies>
21+
<dependency>
22+
<groupId>commons-lang</groupId>
23+
<artifactId>commons-lang</artifactId>
24+
<version>2.6</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>io.projectreactor</groupId>
29+
<artifactId>reactor-core</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>io.projectreactor</groupId>
34+
<artifactId>reactor-test</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
</dependencies>
2039
</project>

uid-generator-api/src/main/java/io/github/cooperlyt/cloud/uid/UidCachedProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ public interface UidCachedProperties {
88
*/
99
int getBoostPower();
1010

11+
void setBoostPower(int value);
12+
1113
/**
1214
* 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
1315
* 举例: bufferSize=1024, paddingFactor=50 -> threshold=1024 * 50 / 100 = 512.
1416
* 当环上可用UID数量 < 512时, 将自动对RingBuffer进行填充补全
1517
*/
1618
int getPaddingFactor();
1719

20+
void setPaddingFactor(int value);
21+
22+
/**
23+
* 另外一种RingBuffer填充时机, 在Schedule线程中, 周期性检查填充
24+
* 默认:不配置此项, 即不使用Schedule线程. 如需使用, 请指定Schedule线程时间间隔, 单位:秒
25+
*/
1826
Long getScheduleInterval();
1927

28+
void setScheduleInterval(long value);
29+
2030
}

uid-generator-api/src/main/java/io/github/cooperlyt/cloud/uid/UidGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
import io.github.cooperlyt.cloud.uid.exception.UidGenerateException;
20+
import reactor.core.publisher.Mono;
2021

2122
/**
2223
* Represents a unique id generator.
@@ -31,7 +32,7 @@ public interface UidGenerator {
3132
* @return UID
3233
* @throws UidGenerateException
3334
*/
34-
long getUID() throws UidGenerateException;
35+
Mono<Long> getUID() throws UidGenerateException;
3536

3637
/**
3738
* Parse the UID into elements which are used to generate the UID. <br>

uid-generator-api/src/main/java/io/github/cooperlyt/cloud/uid/UidProperties.java

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,73 @@
22

33
public interface UidProperties {
44

5-
/**
6-
* 时间增量值占用位数。当前时间相对于时间基点的增量值,单位为秒
7-
*/
5+
86
int getTimeBits();
97

108
/**
11-
* 工作机器ID占用的位数
9+
* @param timeBits 时间增量值占用位数。当前时间相对于时间基点的增量值,单位为秒
1210
*/
11+
void setTimeBits(int timeBits);
12+
13+
1314
int getWorkerBits();
1415

1516
/**
16-
* 序列号占用的位数
17+
* @param value 工作机器ID占用的位数
1718
*/
19+
void setWorkerBits(int value);
20+
21+
1822
int getSeqBits();
1923

2024
/**
21-
* 时间基点. 例如 2019-02-20 (毫秒: 1550592000000)
25+
* @param value 序列号占用的位数
2226
*/
27+
28+
void setSeqBits(int value);
29+
30+
2331
long getEpochSeconds();
2432

2533
/**
26-
* 是否容忍时钟回拨, 默认:true
34+
* 发号起始时间
35+
*
36+
* @param value
37+
* 时间基点. 例如 2019-02-20 (毫秒: 1550592000000)
38+
*
39+
*/
40+
void setEpochStr(String value);
41+
42+
43+
long getMaxBackwardSeconds();
44+
45+
/**
46+
* 系统时钟回拨和使用未来时间最长容忍时间(秒)
47+
*
48+
* @param value
49+
*
50+
* 设置为0时如果发生系统回拨会抛出异常并无法使用未来时间生成ID
51+
*
52+
*
2753
*/
28-
boolean isEnableBackward();
54+
void setMaxBackwardSeconds(long value);
55+
56+
boolean isEnableFutureTime();
2957

3058
/**
31-
* 时钟回拨最长容忍时间(秒)
59+
* 当前时间所生成的ID超出最大序列时和时钟回拨时是否允许使用未来时间的序列来生成ID
60+
*
61+
* 如果ID发号量巨大而经常需要使用到未来时间应当使用 {@link CachedUidGenerator},
62+
* 因持续使用未来时间而得不到回正会引起服务重启后生成重复的ID
63+
*
64+
* @param enable
65+
*
66+
* true: 会使用未来时间来生成ID会造成ID中的时间不准确,
67+
* 可以使用多少未来时间由 maxBackwardSeconds 控制
68+
*
69+
* false: 会返回一下 Mono 等待到达当前时间后通知订阅者
70+
*
3271
*/
33-
long getMaxBackwardSeconds();
72+
void setEnableFutureTime(boolean enable);
3473

3574
}

0 commit comments

Comments
 (0)