Interface DistributedLock

All Known Implementing Classes:
DistributedLockMock

public interface DistributedLock
Distributed lock with RxJava API.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    Tries to acquire the lock.
    @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    acquire(@NotNull Duration duration)
    Tries to acquire the lock for a given duration.
    @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    Tries to acquire the lock without expiration date.
    @NotNull String
    Return the lock id.
    @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.ReleaseResult>
    Tries to release the lock.
    default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    runLocked(@NotNull io.reactivex.rxjava3.core.Completable completable)
    Tries to acquire the lock and releases it after action is executed.
    default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>>
    runLocked(@NotNull io.reactivex.rxjava3.core.Single<T> single)
    Tries to acquire the lock and releases it after action is executed.
    default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    runLocked(@NotNull Runnable runnable)
    Tries to acquire the lock and releases it after action is executed.
    default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    runLocked(@NotNull Duration duration, @NotNull io.reactivex.rxjava3.core.Completable completable)
    Tries to acquire the lock for a given duration and releases it after action is executed.
    default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>>
    runLocked(@NotNull Duration duration, @NotNull io.reactivex.rxjava3.core.Single<T> single)
    Tries to acquire the lock for a given duration and releases it after action is executed.
    default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult>
    runLocked(@NotNull Duration duration, @NotNull Runnable runnable)
    Tries to acquire the lock for a given duration and releases it after action is executed.
    default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>>
    runLocked(@NotNull Duration duration, @NotNull Callable<T> callable)
    Tries to acquire the lock for a given duration and releases it after action is executed.
    default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>>
    runLocked(@NotNull Callable<T> callable)
    Tries to acquire the lock and releases it after action is executed.
  • Method Details

    • getId

      @NotNull @NotNull String getId()
      Return the lock id.
      Returns:
      the lock id
    • acquire

      @NotNull @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> acquire()
      Tries to acquire the lock.

      Lock is acquired for a pre-configured duration. I lock is not released manually, it becomes released after expiration time.

      Returns:
      AcquireResult
    • acquire

      @NotNull @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> acquire(@NotNull @NotNull Duration duration)
      Tries to acquire the lock for a given duration.

      If lock is not released manually, it becomes released after expiration time.

      Parameters:
      duration - lock expiration time when release is not executed
      Returns:
      AcquireResult
    • acquireForever

      @NotNull @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> acquireForever()
      Tries to acquire the lock without expiration date.

      It is potentially dangerous. Lookout for a situation when the lock owning instance goes down without releasing the lock.

      Returns:
      AcquireResult
    • release

      @NotNull @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.ReleaseResult> release()
      Tries to release the lock.
      Returns:
      ReleaseResult
    • runLocked

      @NotNull default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>> runLocked(@NotNull @NotNull io.reactivex.rxjava3.core.Single<T> single)
      Tries to acquire the lock and releases it after action is executed.
      Type Parameters:
      T - type emitted when lock is acquired
      Parameters:
      single - subscribed on lock acquisition
      Returns:
      invalid reference
      AcquireResultWithValue#acquiredResult(T)
      when lock is acquired, AcquireResultWithValue.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>> runLocked(@NotNull @NotNull Callable<T> callable)
      Tries to acquire the lock and releases it after action is executed.
      Type Parameters:
      T - type emitted when lock is acquired
      Parameters:
      callable - executed when lock is acquired
      Returns:
      invalid reference
      AcquireResultWithValue#acquiredResult(T)
      when lock is acquired, AcquireResultWithValue.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> runLocked(@NotNull @NotNull io.reactivex.rxjava3.core.Completable completable)
      Tries to acquire the lock and releases it after action is executed.
      Parameters:
      completable - executed when lock is acquired
      Returns:
      AcquireResult.acquiredResult() when lock is acquired, AcquireResult.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> runLocked(@NotNull @NotNull Runnable runnable)
      Tries to acquire the lock and releases it after action is executed.
      Parameters:
      runnable - executed when lock is acquired
      Returns:
      AcquireResult.acquiredResult() when lock is acquired, AcquireResult.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>> runLocked(@NotNull @NotNull Duration duration, @NotNull @NotNull io.reactivex.rxjava3.core.Single<T> single)
      Tries to acquire the lock for a given duration and releases it after action is executed.
      Type Parameters:
      T - type emitted when lock is acquired
      Parameters:
      duration - lock expiration time when release is not executed
      single - subscribed on lock acquisition
      Returns:
      invalid reference
      AcquireResultWithValue#acquiredResult(T)
      when lock is acquired, AcquireResultWithValue.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default <T> @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResultWithValue<T>> runLocked(@NotNull @NotNull Duration duration, @NotNull @NotNull Callable<T> callable)
      Tries to acquire the lock for a given duration and releases it after action is executed.
      Type Parameters:
      T - type emitted when lock is acquired
      Parameters:
      duration - lock expiration time when release is not executed
      callable - executed when lock is acquired
      Returns:
      invalid reference
      AcquireResultWithValue#acquiredResult(T)
      when lock is acquired, AcquireResultWithValue.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> runLocked(@NotNull @NotNull Duration duration, @NotNull @NotNull Runnable runnable)
      Tries to acquire the lock for a given duration and releases it after action is executed.
      Parameters:
      duration - lock expiration time when release is not executed
      runnable - executed when lock is acquired
      Returns:
      AcquireResult.acquiredResult() when lock is acquired, AcquireResult.rejectedResult() otherwise.
      See Also:
    • runLocked

      @NotNull default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> runLocked(@NotNull @NotNull Duration duration, @NotNull @NotNull io.reactivex.rxjava3.core.Completable completable)
      Tries to acquire the lock for a given duration and releases it after action is executed.
      Parameters:
      duration - lock expiration time when release is not executed
      completable - executed when lock is acquired
      Returns:
      AcquireResult.acquiredResult() when lock is acquired, AcquireResult.rejectedResult() otherwise.
      See Also: