Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coditory/sherlock-distributed-lock
Distributed lock for JVM
https://github.com/coditory/sherlock-distributed-lock
distributed-lock java jvm microservices mongodb
Last synced: about 6 hours ago
JSON representation
Distributed lock for JVM
- Host: GitHub
- URL: https://github.com/coditory/sherlock-distributed-lock
- Owner: coditory
- License: apache-2.0
- Created: 2019-07-04T08:07:14.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T11:22:52.000Z (9 months ago)
- Last Synced: 2024-05-01T09:39:48.352Z (9 months ago)
- Topics: distributed-lock, java, jvm, microservices, mongodb
- Language: Java
- Homepage:
- Size: 2.24 MB
- Stars: 33
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Sherlock Distributed Lock
[![Build](https://github.com/coditory/sherlock-distributed-lock/actions/workflows/build.yml/badge.svg)](https://github.com/coditory/sherlock-distributed-lock/actions/workflows/build.yml)
[![Coverage](https://codecov.io/gh/coditory/sherlock-distributed-lock/branch/main/graph/badge.svg)](https://codecov.io/gh/coditory/sherlock-distributed-lock)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.coditory.sherlock/sherlock-api/badge.svg)](https://search.maven.org/search?q=com.coditory.sherlock)> Java Distributed lock library with database migration capabilities
Look for details in the [documentation](https://coditory.github.io/sherlock-distributed-lock/).
- **[supports multiple databases](https://coditory.github.io/sherlock-distributed-lock/connectors/)** - [SQL databases](https://coditory.github.io/sherlock-distributed-lock/connectors/sql/), [MongoDB](https://coditory.github.io/sherlock-distributed-lock/connectors/mongo/) and more
- **[multiple types of locks](https://coditory.github.io/sherlock-distributed-lock/locks)** - multiple ways to acquire a lock: reentrant, single-entrant and more
- **[basic DB migration](https://coditory.github.io/sherlock-distributed-lock/migrator)** - provides database migration process based on locks. No need for another library.
- **[synchronous and reactive API](https://coditory.github.io/sherlock-distributed-lock/api)** - exposes synchronous and reactive API (supports synchronous calls, Reactor, RxJava, Kotlin coroutines)
- **minimal set of dependencies** - the main dependency is a database driver## Sample usage
Add dependency to `build.gradle`:
```groovy
dependencies {
implementation "com.coditory.sherlock:sherlock-mongo:$version"
}
```Create synchronous MongoDB backed lock:
```java
// Get mongo collection
// You can also use other DB or reactive API
MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017/sherlock");
MongoCollection collection = mongoClient
.getDatabase("sherlock")
.getCollection("locks");// Create sherlock
Sherlock sherlock = MongoSherlock.create(collection);// Create a lock
DistributedLock lock = sherlock.createLock("sample-lock");// Acquire a lock, run action and finally release the lock
lock.runLocked(() -> System.out.println("Lock granted!"));
```