Interface RxDistributedLock

All Known Implementing Classes:
RxDistributedLockMock

public interface RxDistributedLock
A reactive distributed lock with RxJava API.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult>
    Try to acquire the lock.
    io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult>
    acquire(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(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>
    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.
    Return the lock id.
    io.reactivex.Single<com.coditory.sherlock.connector.ReleaseResult>
    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 Details

    • getId

      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.SUCCESS if lock is acquired
    • acquire

      io.reactivex.Single<com.coditory.sherlock.connector.AcquireResult> acquire(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.SUCCESS if 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.SUCCESS if lock is acquired
    • release

      io.reactivex.Single<com.coditory.sherlock.connector.ReleaseResult> release()
      Try to release the lock.
      Returns:
      ReleaseResult.SUCCESS if lock was released by this method invocation. If lock has expired or was released earlier then ReleaseResult.FAILURE is 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:
    • acquireAndExecute

      default <T> io.reactivex.Maybe<T> acquireAndExecute(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 expire
      single - to be subscribed to when lock is acquired
      Returns:
      true, if lock is acquired
      See Also:
    • 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:
    • 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: