Package com.coditory.sherlock.rxjava
Interface DistributedLock
- All Known Implementing Classes:
DistributedLockMock
public interface DistributedLock
Distributed lock with RxJava API.
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> acquire()Tries to acquire the lock.@NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> 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 StringgetId()Return the lock id.@NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.ReleaseResult> release()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> Tries to acquire the lock and releases it after action is executed.default @NotNull io.reactivex.rxjava3.core.Single<com.coditory.sherlock.connector.AcquireResult> 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>> 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> 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>> 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>> Tries to acquire the lock and releases it after action is executed.
-
Method Details
-
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:
-
when lock is acquired,
invalid reference
AcquireResultWithValue#acquiredResult(T)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:
-
when lock is acquired,
invalid reference
AcquireResultWithValue#acquiredResult(T)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 executedsingle- subscribed on lock acquisition- Returns:
-
when lock is acquired,
invalid reference
AcquireResultWithValue#acquiredResult(T)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 executedcallable- executed when lock is acquired- Returns:
-
when lock is acquired,
invalid reference
AcquireResultWithValue#acquiredResult(T)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 executedrunnable- 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 executedcompletable- executed when lock is acquired- Returns:
AcquireResult.acquiredResult()when lock is acquired,AcquireResult.rejectedResult()otherwise.- See Also:
-