lokk

Kotlin/JVM coroutine-based distributed locks

APACHE-2.0 License

Stars
2

Lokk

Here should be some modern logo

Overview

Kotlin/JVM coroutine-based distributed locks

Why not ShedLock?

There are some simple advantages:

  • Core API is build on coroutines (suspend-able methods), providers are implementing them with non-blocking APIs
  • There are no optional hell inside core, result is an instance of sealed class
  • Kotlin DSL api

Disadvantages:

  • Much less implementations are done :( (plz help and contribute!)

Distribution

Library with modules are available only from jitpack so far:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Usage

Usage as simple as is - just instantiate required provider and use it like this:

val lokkProvider = /*...*/ 
lokkProvider.withLokk(atLeastFor = Duration.ofMinutes(10), atMostFor = Duration.ofHours(1)) {
    // do some magic
}

There are several jvm lokk implementations so far

Redis with reactive Lettuce

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>lokk-redis-lettuce</artifactId>
    <version>${lokk.version}</version>
</dependency>

Then use this implementation:

val lokkProvider = RedisLettuceLokkProvider(client = RedisClient.create())

Mongo with reactive streams driver

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>lokk-mongo-reactive-streams</artifactId>
    <version>${lokk.version}</version>
</dependency>

Then use this implementation:

val lokkProvider = MongoReactiveStreamsLokkProvider(client = MongoClients.create())