Skip to content

Commit

Permalink
kdoc corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
himadieievsv committed Jan 12, 2024
1 parent 8e5d42b commit 209e56c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import kotlin.coroutines.cancellation.CancellationException
* Allows one or more workloads to wait until a set of other workload are get ready or finished.
* [ListeningCountDownLatch] implementation uses Redis Pub/Sub mechanism to notify other instances
* about counter reached to 0.
*
* @param name [String] the name of the latch.
* @param count [Int] the number of times [countDown] must be invoked before threads can pass through [await].
* @param backends [List] of [CountDownLatchBackend] instances.
* @param maxDuration [Duration] the maximum time to wait.
* @param retryCount [Int] the number of retries to acquire lock.
* @param retryDelay [Duration] the delay between retries.
*/
class ListeningCountDownLatch(
private val name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package com.himadieiev.redpulsar.core.locks

import com.himadieiev.redpulsar.core.locks.abstracts.AbstractMultyInstanceLock
import com.himadieiev.redpulsar.core.locks.abstracts.AbstractMultiInstanceLock
import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import java.time.Duration

/**
* A distributed lock for single or multiple Redis instances / clusters.
* It uses Redlock algorithm to determine if the lock was acquired.
* See details in [AbstractMultyInstanceLock].
* It uses RedLock algorithm to determine if the lock was acquired.
* See details in [AbstractMultiInstanceLock].
*
* @param backends [List] of [LocksBackend] instances.
* @param retryCount [Int] the number of retries to acquire lock.
* @param retryDelay [Duration] the delay between retries.
* @param scope [CoroutineScope] the scope for coroutines.
*/
class RedLock(
backends: List<LocksBackend>,
retryCount: Int = 3,
retryDelay: Duration = Duration.ofMillis(100),
scope: CoroutineScope = CoroutineScope(Dispatchers.IO),
) : AbstractMultyInstanceLock(backends, scope, retryCount, retryDelay) {
) : AbstractMultiInstanceLock(backends, scope, retryCount, retryDelay) {
init {
require(retryDelay.toMillis() > 0) { "Retry delay must be positive" }
require(retryCount > 0) { "Retry count must be positive" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.himadieiev.redpulsar.core.locks

import com.himadieiev.redpulsar.core.locks.abstracts.AbstractMultyInstanceLock
import com.himadieiev.redpulsar.core.locks.abstracts.AbstractMultiInstanceLock
import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -9,14 +9,20 @@ import java.time.Duration
/**
* An implementation for Semaphore lock in distributed systems.
* Semaphore lock is a lock that allows multiple clients to acquire the lock until lock limit is reached.
*
* @param backends [List] of [LocksBackend] instances.
* @param maxLeases [Int] the maximum number of leases that can be acquired.
* @param retryCount [Int] the number of retries to acquire lock.
* @param retryDelay [Duration] the delay between retries.
* @param scope [CoroutineScope] the scope for coroutines.
*/
class Semaphore(
backends: List<LocksBackend>,
private val maxLeases: Int,
retryCount: Int = 3,
retryDelay: Duration = Duration.ofMillis(100),
scope: CoroutineScope = CoroutineScope(Dispatchers.IO),
) : AbstractMultyInstanceLock(backends, scope, retryCount, retryDelay) {
) : AbstractMultiInstanceLock(backends, scope, retryCount, retryDelay) {
private val globalKeyPrefix = "semaphore"
private val leasersKey = "leasers"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import java.time.Duration

/**
* A distributed lock implementation that using only single Redis Cluster or Redis instance.
*
* @param backend [LocksBackend] instance.
* @param retryDelay [Duration] the delay between retries.
* @param retryCount [Int] the number of retries to acquire lock.
*/
class SimpleLock(
private val backend: LocksBackend,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import kotlinx.coroutines.CoroutineScope
import java.time.Duration

/**
* A distributed lock implementation based on the Redlock algorithm.
* A distributed lock implementation based on the RedLock algorithm.
* Algorithm depends on single or multiple Redis instances / clusters.
* It uses a quorum to determine if the lock was acquired.
* Details: https://redis.io/docs/manual/patterns/distributed-locks/
*/
abstract class AbstractMultyInstanceLock(
abstract class AbstractMultiInstanceLock(
private val backends: List<LocksBackend>,
private val scope: CoroutineScope,
private val retryCount: Int = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.himadieiev.redpulsar.core.utils
import mu.KotlinLogging

/**
* Catch and supress all types of exceptions.
* Catch and suppress all types of exceptions.
* If [block] failed to run with exception, default value will be returned.
*/
inline fun <R> failsafe(
Expand Down

0 comments on commit 209e56c

Please sign in to comment.