Skip to content

Commit 4f422b8

Browse files
committed
update README.md and add workflows
1 parent 74d03d6 commit 4f422b8

File tree

2 files changed

+97
-11
lines changed

2 files changed

+97
-11
lines changed

.github/workflows/maven.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Build
5+
6+
on:
7+
push:
8+
branches-ignore:
9+
- '**-alpha'
10+
- '**-tmp'
11+
- '**-temp'
12+
pull_request:
13+
branches-ignore:
14+
- '**-alpha'
15+
- '**-tmp'
16+
- '**-temp'
17+
workflow_dispatch:
18+
inputs:
19+
profiles:
20+
description: 'mvn -P <arg>'
21+
required: false
22+
default: ''
23+
24+
jobs:
25+
build:
26+
27+
runs-on: ubuntu-18.04
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Set up JDK 1.8
32+
uses: actions/setup-java@v1
33+
with:
34+
java-version: 1.8
35+
- name: Clean and Package
36+
if: github.event.inputs.profiles == ''
37+
run: mvn clean package
38+
- name: Clean and Package With Profiles
39+
if: github.event.inputs.profiles != ''
40+
run: mvn -P ${{ github.event.inputs.profiles }} clean package
41+
- name: Upload coverage to Codecov
42+
if: github.event_name == 'push'
43+
uses: codecov/[email protected]
44+
with:
45+
token: ${{secrets.CODECOV_TOKEN}}

README.md

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
1-
1. memo:
2-
// 锁的元数据信息
3-
// 加锁过程的扩展点
4-
// 解锁过程的扩展点
5-
// 异常的扩展点
6-
// 数据源
1+
# DistributedLock
72

3+
[![Maven Central](https://img.shields.io/maven-central/v/site.hellooo/hellooo-distributedlock)](https://img.shields.io/maven-central/v/site.hellooo/hellooo-distributedlock)
4+
[![GitHub license](https://img.shields.io/github/license/hellooo-stack/hellooo-distributedlock)](https://img.shields.io/github/license/hellooo-stack/hellooo-distributedlock)
85

9-
2. features:
6+
DistributedLock is a lightweight distributed lock framework that provides reliable consistency features. It can be used with only the Lock interface.
107

118

12-
3. implemented:
9+
# Features
10+
- Reentrant locking
11+
- Supports tryLock(), lock(), unlock() operations
12+
- Supports lock leasing
1313

14-
4. test schedule:
14+
# Quick Start
15+
Step one: Add maven dependency
16+
```xml
17+
<dependency>
18+
<groupId>site.hellooo</groupId>
19+
<artifactId>hellooo-distributedlock</artifactId>
20+
<version>>${hellooo-distributedlock.version}</version>
21+
</dependency>
22+
```
1523

16-
5. what problems have I meet
17-
- how to test private method: [sloved](https://stackoverflow.com/questions/34571/how-do-i-test-a-class-that-has-private-methods-fields-or-inner-classes)
24+
Step two: Add customize configuration by annotation
25+
```java
26+
public class Main {
27+
public static void main(String[] args) {
28+
LockOptions lockOptions = LockOptions.options()
29+
.build();
30+
31+
// define the redis source
32+
JedisPool pool = new JedisPool("localhost", 6379);
33+
for (int i = 0; i < 10; i++) {
34+
final int threadNumber = i;
35+
Thread thread = new Thread(() -> {
36+
Thread.currentThread().setName("Thread " + threadNumber);
37+
38+
try (Jedis jedis = pool.getResource()) {
39+
try {
40+
Lock lock = new ReentrantDistributedLock(lockOptions, "my_lock", new RedisLockHandler(jedis));
41+
// lock
42+
lock.lock();
43+
System.out.println("thread" + Thread.currentThread().getName() + " locked!");
44+
Thread.sleep(1000);
45+
System.out.println("thread" + Thread.currentThread().getName() + " lock released!");
46+
// unlock
47+
lock.unlock();
48+
} catch (Exception e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
});
53+
thread.start();
54+
}
55+
}
56+
}
57+
58+
```

0 commit comments

Comments
 (0)