Skip to content

Commit b9761e9

Browse files
调整架构使其更容易维护,调整注释
1 parent 6326ef2 commit b9761e9

23 files changed

Lines changed: 486 additions & 509 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<p align="center">
12
<img src="https://images.gitee.com/uploads/images/2020/1022/231243_f2ae30da_2071767.png" width="229" height="210" alt="Icon"/>
3+
</p>
24

35
# PDConcurrent
46

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tasks.withType(JavaCompile).configureEach {
88
}
99

1010
group 'fybug.nulll'
11-
version = '0.1.0'
11+
version = '0.1.3'
1212

1313
java {
1414
toolchain {
@@ -53,12 +53,13 @@ dependencies {
5353
// lombok
5454
testCompileOnly "org.projectlombok:lombok:+"
5555
testAnnotationProcessor "org.projectlombok:lombok:+"
56-
testRuntimeOnly "org.junit.jupiter:junit-jupiter:5.12.0+"
56+
testImplementation platform('org.junit:junit-bom:5.10.0')
57+
testRuntimeOnly "org.junit.jupiter:junit-jupiter:5.12.0-RC2"
5758
}
5859

5960
test {
6061
dependencies {
61-
testImplementation "org.junit.jupiter:junit-jupiter:5.12.0+"
62+
testImplementation "org.junit.jupiter:junit-jupiter:5.12.0-RC2"
6263
}
6364
useJUnitPlatform()
6465
}

jar/PDConcurrent_bin.jar

5.87 KB
Binary file not shown.

jar/PDConcurrent_sources.jar

4.91 KB
Binary file not shown.

src/main/java/fybug/nulll/pdconcurrent/SyLock.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package fybug.nulll.pdconcurrent;
22
import fybug.nulll.pdconcurrent.e.LockType;
3-
import fybug.nulll.pdconcurrent.i.ReadWriteLock;
4-
import fybug.nulll.pdconcurrent.i.TryReadWriteLock;
3+
import fybug.nulll.pdconcurrent.i.simple.ReadLockSimple;
4+
import fybug.nulll.pdconcurrent.i.simple.TryReadLockSimple;
5+
import fybug.nulll.pdconcurrent.i.simple.TryWriteLockSimple;
6+
import fybug.nulll.pdconcurrent.i.simple.WriteLockSimple;
57
import fybug.nulll.pdconcurrent.lock.ObjLock;
68
import fybug.nulll.pdconcurrent.lock.RWLock;
79
import fybug.nulll.pdconcurrent.lock.ReLock;
810
import jakarta.validation.constraints.NotNull;
911

1012
/**
1113
* <h2>并发管理.</h2>
12-
* 通过传入回调的方式隐藏内部的并发管理方法,并支持复用内部的try块,通过传入的回调插入到catch,finally块中执行<br/>
14+
* 通过传入回调的方式隐藏内部的并发管理方法,并支持复用内部的 try 块,通过传入的回调插入到 catch,finally 块中执行<br/>
1315
* {@code lock()}方法用于根据传入的{@link LockType}申请不同的锁类型进行执行<br/>
1416
* {@code read()}方法用于使用读锁执行,{@code write()}用于使用写锁执行,只有在使用读写锁实现{@link RWLock}才有区别。其余实现两个之间无区别<br/>
1517
* {@code trylock()}类型的方法为尝试获取锁的实现,这意味着并不是一定能获取到锁,但也意味着不需要等待<br/>
@@ -18,19 +20,19 @@
1820
* 使用 {@code new**Lock()} 的方法获取不同并发管理的实例<br/>
1921
*
2022
* @author fybug
21-
* @version 0.1.2
23+
* @version 0.1.3
2224
* @since PDConcurrent 0.0.1
2325
*/
26+
@SuppressWarnings("unused")
2427
public
25-
interface SyLock extends ReadWriteLock, TryReadWriteLock {
28+
interface SyLock extends ReadLockSimple, WriteLockSimple, TryReadLockSimple, TryWriteLockSimple {
2629
/**
2730
* 获取传统并发实现
2831
*
2932
* @return 获取的并发控制对象
3033
*
3134
* @see ObjLock
3235
*/
33-
@SuppressWarnings("unused")
3436
@NotNull
3537
static
3638
ObjLock newObjLock() { return new ObjLock(); }
@@ -42,7 +44,6 @@ interface SyLock extends ReadWriteLock, TryReadWriteLock {
4244
*
4345
* @see ReLock
4446
*/
45-
@SuppressWarnings("unused")
4647
@NotNull
4748
static
4849
ReLock newReLock() { return new ReLock(); }
@@ -54,7 +55,6 @@ interface SyLock extends ReadWriteLock, TryReadWriteLock {
5455
*
5556
* @see RWLock
5657
*/
57-
@SuppressWarnings("unused")
5858
@NotNull
5959
static
6060
RWLock newRWLock() { return new RWLock(); }

src/main/java/fybug/nulll/pdconcurrent/i/Lock.java

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111
/**
1212
* <h2>基础锁管理.</h2>
13-
* 通过传入回调的方式隐藏内部的并发管理方法,并支持复用内部的try块,通过传入的回调插入到catch,finally块中执行<br/>
14-
* {@code lock()}方法用于根据传入的{@link LockType}申请不同的锁类型进行执行<br/>
13+
* 通过传入回调的方式隐藏内部的并发管理方法,并支持复用内部的 try 块,通过传入的回调插入到 catch,finally 块中执行<br/>
14+
* {@code lock()} 方法用于根据传入的 {@link LockType} 申请不同的锁类型进行执行<br/>
1515
* 有可抛出异常的方法变体,可在传入的接口中抛出异常
1616
*
1717
* @author fybug
18-
* @version 0.0.1
18+
* @version 0.0.2
1919
* @see LockType
2020
* @since i 0.0.1
2121
*/
22+
public
2223
interface Lock {
2324
/**
2425
* 使用锁执行指定回调
@@ -44,11 +45,6 @@ <R> R lock(@NotNull LockType lockType, @NotNull trySupplier<R> run, @Nullable Fu
4445
* 使用锁执行指定回调
4546
* <p>
4647
* {@link #lock(LockType, trySupplier, Function, Function)}的无返回变体
47-
*
48-
* @param lockType 锁类型
49-
* @param run 执行的回调
50-
* @param catchby 进入catch块后的回调,传入当前异常
51-
* @param finaby 进入finally块后的回调
5248
*/
5349
default
5450
void lock(@NotNull LockType lockType, @NotNull tryRunnable run, @Nullable Consumer<Exception> catchby,
@@ -85,33 +81,10 @@ void lock(@NotNull LockType lockType, @NotNull tryRunnable run, @Nullable Consum
8581
*/
8682
<R> R lock(@NotNull LockType lockType, @NotNull trySupplier<R> run, @Nullable Function<R, R> finaby) throws Exception;
8783

88-
/**
89-
* 使用锁执行指定回调
90-
* <p>
91-
* {@link #lock(LockType, trySupplier, Function)}的简易变体
92-
*
93-
* @param lockType 锁类型
94-
* @param run 带返回的回调
95-
* @param <R> 要返回的数据类型
96-
*
97-
* @return 回调返回的内容,遇到异常不返回
98-
*
99-
* @throws Exception 异常类型根据实际运行时回调抛出决定
100-
*/
101-
default
102-
<R> R lock(@NotNull LockType lockType, @NotNull trySupplier<R> run) throws Exception
103-
{ return lock(lockType, run, null); }
104-
10584
/**
10685
* 使用锁执行指定回调
10786
* <p>
10887
* {@link #lock(LockType, trySupplier, Function)}的无返回变体
109-
*
110-
* @param lockType 锁类型
111-
* @param run 执行的回调
112-
* @param finaby 进入finally块后的回调
113-
*
114-
* @throws Exception 异常类型根据实际运行时回调抛出决定
11588
*/
11689
default
11790
void lock(@NotNull LockType lockType, @NotNull tryRunnable run, @Nullable Runnable finaby) throws Exception {
@@ -123,18 +96,4 @@ void lock(@NotNull LockType lockType, @NotNull tryRunnable run, @Nullable Runnab
12396
return null;
12497
});
12598
}
126-
127-
/**
128-
* 使用锁执行指定回调
129-
* <p>
130-
* {@link #lock(LockType, tryRunnable, Runnable)}的简易变体
131-
*
132-
* @param lockType 锁类型
133-
* @param run 执行的回调
134-
*
135-
* @throws Exception 异常类型根据实际运行时回调抛出决定
136-
*/
137-
default
138-
void lock(@NotNull LockType lockType, @NotNull tryRunnable run) throws Exception
139-
{ lock(lockType, run, null); }
14099
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package fybug.nulll.pdconcurrent.i;
2+
import java.util.function.Consumer;
3+
import java.util.function.Function;
4+
5+
import fybug.nulll.pdconcurrent.e.LockType;
6+
import fybug.nulll.pdconcurrent.fun.tryRunnable;
7+
import fybug.nulll.pdconcurrent.fun.trySupplier;
8+
import fybug.nulll.pdconcurrent.i.simple.LockSimple;
9+
import jakarta.annotation.Nullable;
10+
import jakarta.validation.constraints.NotNull;
11+
12+
/**
13+
* <h2>并发管理读锁支持拓展.</h2>
14+
* {@link Lock}的拓展,增加 {@code read()} 类方法用于隐藏 {@link LockType} 参数
15+
*
16+
* @author fybug
17+
* @version 0.0.1
18+
* @see LockType#READ
19+
* @see Lock
20+
* @since i 0.0.2
21+
*/
22+
@SuppressWarnings("unused")
23+
public
24+
interface ReadLock extends LockSimple {
25+
/**
26+
* 使用读锁执行指定回调
27+
* <p>
28+
* {@link #lock(LockType, trySupplier, Function, Function)}指定读锁的变种
29+
*/
30+
default
31+
<R> R read(@NotNull trySupplier<R> run, @Nullable Function<Exception, R> catchby, @Nullable Function<R, R> finaby)
32+
{ return lock(LockType.READ, run, catchby, finaby); }
33+
34+
/**
35+
* 使用读锁执行指定回调
36+
* <p>
37+
* {@link #lock(LockType, tryRunnable, Consumer, Runnable)}指定读锁的变种
38+
*/
39+
default
40+
void read(@NotNull tryRunnable run, @Nullable Consumer<Exception> catchby, @Nullable Runnable finaby)
41+
{ lock(LockType.READ, run, catchby, finaby); }
42+
43+
/**
44+
* 使用读锁执行指定回调
45+
* <p>
46+
* {@link #lock(LockType, trySupplier, Function)}指定读锁的变种
47+
*/
48+
default
49+
<R> R read(@NotNull trySupplier<R> run, @Nullable Function<R, R> finaby) throws Exception
50+
{ return lock(LockType.READ, run, finaby); }
51+
52+
/**
53+
* 使用读锁执行指定回调
54+
* <p>
55+
* {@link #lock(LockType, tryRunnable, Runnable)}指定读锁的变种
56+
*/
57+
default
58+
void read(@NotNull tryRunnable run, @Nullable Runnable finaby) throws Exception
59+
{ lock(LockType.READ, run, finaby); }
60+
}

0 commit comments

Comments
 (0)