Interface RxDistributedLock

  • All Known Implementing Classes:
    RxDistributedLockMock

    public interface RxDistributedLock
    A 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​(java.time.Duration duration, java.util.function.Supplier<io.reactivex.Single<T>> action)
      Acquire a lock for a given duration and release it after action is executed.
      default <T> io.reactivex.Maybe<T> acquireAndExecute​(java.util.function.Supplier<io.reactivex.Single<T>> action)
      Acquire a lock 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​(java.util.function.Supplier<io.reactivex.Single<T>> action)
      Acquire a lock without expiration time and release it after action is executed.
      java.lang.String getId()
      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​(java.util.function.Supplier<io.reactivex.Single<T>> action)
      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.SUCCESS if 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.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​(java.util.function.Supplier<io.reactivex.Single<T>> action)
        Acquire a lock and release it after action is executed.
        Type Parameters:
        T - type od value emitted by the action
        Parameters:
        action - to be executed 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,
                                                            java.util.function.Supplier<io.reactivex.Single<T>> action)
        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
        action - to be executed when lock is acquired
        Returns:
        true, if lock is acquired
        See Also:
        acquire(Duration)
      • acquireForeverAndExecute

        default <T> io.reactivex.Maybe<T> acquireForeverAndExecute​(java.util.function.Supplier<io.reactivex.Single<T>> action)
        Acquire a lock without expiration time and release it after action is executed.
        Type Parameters:
        T - type od value emitted by the action
        Parameters:
        action - to be executed when lock is acquired
        Returns:
        true, if lock is acquired
        See Also:
        acquireForever()
      • releaseAndExecute

        default <T> io.reactivex.Maybe<T> releaseAndExecute​(java.util.function.Supplier<io.reactivex.Single<T>> action)
        Run the action when lock is released
        Type Parameters:
        T - type od value emitted by the action
        Parameters:
        action - to be executed when lock is released
        Returns:
        true, if lock was release
        See Also:
        release()