Package com.coditory.sherlock
Interface RxDistributedLock
-
- All Known Implementing Classes:
RxDistributedLockMock
public interface RxDistributedLockA reactive distributed lock with RxJava API.- See Also:
RxSherlock
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult>acquire()Try to acquire the lock.io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult>acquire(java.time.Duration duration)Try to acquire the lock for a given duration.default <T> io.reactivex.Maybe<T>acquireAndExecute(io.reactivex.Single<T> single)Acquire a lock and release it after action is executed.default <T> io.reactivex.Maybe<T>acquireAndExecute(java.time.Duration duration, io.reactivex.Single<T> single)Acquire a lock for a given duration and release it after action is executed.io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult>acquireForever()Try to acquire the lock without expiring date.default <T> io.reactivex.Maybe<T>acquireForeverAndExecute(io.reactivex.Single<T> single)Acquire a lock without expiration time and release it after action is executed.java.lang.StringgetId()Return the lock id.io.reactivex.Single<com.coditory.sherlock.connector.ReleaseResult>release()Try to release the lock.default <T> io.reactivex.Maybe<T>releaseAndExecute(io.reactivex.Single<T> single)Run the action when lock is released
-
-
-
Method Detail
-
getId
java.lang.String getId()
Return the lock id.- Returns:
- the lock id
-
acquire
io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult> acquire()
Try to acquire the lock. Lock is acquired for a pre configured duration.- Returns:
AcquireResult.SUCCESSif lock is acquired
-
acquire
io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult> acquire(java.time.Duration duration)
Try to acquire the lock for a given duration.- Parameters:
duration- how much time must pass for the acquired lock to expire- Returns:
AcquireResult.SUCCESSif lock is acquired
-
acquireForever
io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult> acquireForever()
Try to acquire the lock without expiring date.It is potentially dangerous. Lookout for a situation when the lock owning instance goes down with out releasing the lock.
- Returns:
AcquireResult.SUCCESSif lock is acquired
-
release
io.reactivex.Single<com.coditory.sherlock.connector.ReleaseResult> release()
Try to release the lock.- Returns:
ReleaseResult.SUCCESSif lock was released by this method invocation. If lock has expired or was released earlier thenReleaseResult.FAILUREis returned.
-
acquireAndExecute
default <T> io.reactivex.Maybe<T> acquireAndExecute(io.reactivex.Single<T> single)
Acquire a lock and release it after action is executed.- Type Parameters:
T- type od value emitted by the action- Parameters:
single- to be subscribed to when lock is acquired- Returns:
- true if lock is acquired.
- See Also:
acquire()
-
acquireAndExecute
default <T> io.reactivex.Maybe<T> acquireAndExecute(java.time.Duration duration, io.reactivex.Single<T> single)Acquire a lock for a given duration and release it after action is executed.- Type Parameters:
T- type od value emitted by the action- Parameters:
duration- how much time must pass for the acquired lock to expiresingle- to be subscribed to when lock is acquired- Returns:
- true, if lock is acquired
- See Also:
acquire(Duration)
-
acquireForeverAndExecute
default <T> io.reactivex.Maybe<T> acquireForeverAndExecute(io.reactivex.Single<T> single)
Acquire a lock without expiration time and release it after action is executed.- Type Parameters:
T- type od value emitted by the action- Parameters:
single- to be subscribed to when lock is acquired- Returns:
- true, if lock is acquired
- See Also:
acquireForever()
-
releaseAndExecute
default <T> io.reactivex.Maybe<T> releaseAndExecute(io.reactivex.Single<T> single)
Run the action when lock is released- Type Parameters:
T- type od value emitted by the action- Parameters:
single- to be subscribed to when lock is released- Returns:
- true, if lock was release
- See Also:
release()
-
-