Interface RSemaphoreRx

  • All Superinterfaces:
    RExpirableRx, RObjectRx

    public interface RSemaphoreRx
    extends RExpirableRx
    RxJava2 interface of Redis based Semaphore.

    Works in non-fair mode. Therefore order of acquiring is unpredictable.

    Author:
    Nikita Koksharov
    • Method Detail

      • tryAcquire

        io.reactivex.rxjava3.core.Single<Boolean> tryAcquire()
        Acquires a permit. Waits if necessary until a permit became available.
        Returns:
        true if a permit was acquired and false otherwise
      • tryAcquire

        io.reactivex.rxjava3.core.Single<Boolean> tryAcquire​(int permits)
        Tries to acquire defined amount of currently available permits.
        Parameters:
        permits - the number of permits to acquire
        Returns:
        true if permits were acquired and false otherwise
      • acquire

        io.reactivex.rxjava3.core.Completable acquire()
        Acquires a permit. Waits if necessary until a permit became available.
        Returns:
        void
      • acquire

        io.reactivex.rxjava3.core.Completable acquire​(int permits)
        Acquires defined amount of permits. Waits if necessary until all permits became available.
        Parameters:
        permits - the number of permits to acquire
        Returns:
        void
        Throws:
        IllegalArgumentException - if permits is negative
      • release

        io.reactivex.rxjava3.core.Completable release()
        Releases a permit.
        Returns:
        void
      • release

        io.reactivex.rxjava3.core.Completable release​(int permits)
        Releases defined amount of permits.
        Parameters:
        permits - amount
        Returns:
        void
      • trySetPermits

        io.reactivex.rxjava3.core.Single<Boolean> trySetPermits​(int permits)
        Tries to set number of permits.
        Parameters:
        permits - - number of permits
        Returns:
        true if permits has been set successfully, otherwise false.
      • tryAcquire

        io.reactivex.rxjava3.core.Single<Boolean> tryAcquire​(long waitTime,
                                                             TimeUnit unit)
        Tries to acquire currently available permit. Waits up to defined waitTime if necessary until a permit became available.
        Parameters:
        waitTime - the maximum time to wait
        unit - the time unit
        Returns:
        true if a permit was acquired and false otherwise
      • tryAcquire

        io.reactivex.rxjava3.core.Single<Boolean> tryAcquire​(int permits,
                                                             long waitTime,
                                                             TimeUnit unit)
        Tries to acquire defined amount of currently available permits. Waits up to defined waitTime if necessary until all permits became available.
        Parameters:
        permits - amount of permits
        waitTime - the maximum time to wait
        unit - the time unit
        Returns:
        true if permits were acquired and false otherwise
      • addPermits

        io.reactivex.rxjava3.core.Completable addPermits​(int permits)
        Increases or decreases the number of available permits by defined value.
        Parameters:
        permits - amount of permits to add/remove
      • availablePermits

        io.reactivex.rxjava3.core.Single<Integer> availablePermits()
        Returns amount of available permits.
        Returns:
        number of permits
      • drainPermits

        io.reactivex.rxjava3.core.Single<Integer> drainPermits()
        Acquires and returns all permits that are immediately available.
        Returns:
        number of permits