Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: lock demo #783

Merged
merged 8 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/en/start/lock/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ The layotto file will be generated in the directory, run it:
<!-- tabs:end -->

## step 2. Run the client program, call Layotto to add, delete, modify and query
<!-- tabs:start -->
#### **Go**

```shell
cd ${project_path}/demo/lock/common/
Expand All @@ -98,6 +100,46 @@ client2 succeeded in unlocking
Demo success!
```

#### **Java**

Download java sdk and examples:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

Change directory:

```shell
cd java-sdk
```

Build:

```shell @if.not.exist examples-lock/target/examples-lock-jar-with-dependencies.jar
# build example jar
mvn -f examples-lock/pom.xml clean package
```

Run the examples:

```shell
java -jar examples-lock/target/examples-lock-jar-with-dependencies.jar
```

And you will see:

```bash
TryLockResponse{success=true}
TryLockResponse{success=true}
TryLockResponse{success=true}
UnlockResponse{status=SUCCESS}
TryLockResponse{success=true}
UnlockResponse{status=LOCK_UNEXIST}
```

<!-- tabs:end -->

## Next Step
### What did this client Demo do?
The demo client program uses the golang version SDK provided by Layotto, calls the Layotto distributed lock API, and starts multiple goroutines to do locking and unlocking operations.
Expand Down
42 changes: 42 additions & 0 deletions docs/zh/start/lock/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ go build -o layotto
<!-- tabs:end -->

### step 2. 运行客户端程序,调用Layotto抢锁/解锁
<!-- tabs:start -->
#### **Go**

```shell
cd ${project_path}/demo/lock/common/
Expand All @@ -100,6 +102,46 @@ client2 succeeded in unlocking
Demo success!
```

#### **Java**

下载 java sdk 和示例代码:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

切换目录:

```shell
cd java-sdk
```

构建:

```shell @if.not.exist examples-lock/target/examples-lock-jar-with-dependencies.jar
# build example jar
mvn -f examples-lock/pom.xml clean package
```

运行:

```shell
java -jar examples-lock/target/examples-lock-jar-with-dependencies.jar
```

打印出以下信息说明运行成功:

```bash
TryLockResponse{success=true}
TryLockResponse{success=true}
TryLockResponse{success=true}
UnlockResponse{status=SUCCESS}
TryLockResponse{success=true}
UnlockResponse{status=LOCK_UNEXIST}
```

<!-- tabs:end -->

### 下一步
#### 这个客户端程序做了什么?
示例客户端程序中使用了Layotto提供的golang版本sdk,调用Layotto 分布式锁API,启动多个协程进行抢锁、解锁操作。
Expand Down