Interface RPermitExpirableSemaphoreRx

  • All Superinterfaces:
    RExpirableRx, RObjectRx

    public interface RPermitExpirableSemaphoreRx
    extends RExpirableRx
    RxJava2 interface for Semaphore object with lease time parameter support for each acquired permit.

    Each permit identified by own id and could be released only using its id. Permit id is a 128-bits unique random identifier generated each time during acquiring.

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

    Author:
    Nikita Koksharov
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      io.reactivex.rxjava3.core.Single<> acquire()
      Acquires a permit from this semaphore, blocking until one is available, or the thread is .
      io.reactivex.rxjava3.core.Single<> acquire​(long leaseTime,  unit)
      Acquires a permit with defined lease time from this semaphore, blocking until one is available, or the thread is .
      io.reactivex.rxjava3.core.Completable addPermits​(int permits)
      Increases or decreases the number of available permits by defined value.
      io.reactivex.rxjava3.core.Single<> availablePermits()
      Returns the current number of available permits.
      io.reactivex.rxjava3.core.Completable  permitId)
      Releases a permit by its id, returning it to the semaphore.
      io.reactivex.rxjava3.core.Maybe<> tryAcquire()
      Acquires a permit only if one is available at the time of invocation.
      io.reactivex.rxjava3.core.Maybe<> tryAcquire​(long waitTime, long leaseTime,  unit)
      Acquires a permit with defined lease time from this semaphore, if one becomes available within the given waiting time and the current thread has not been .
      io.reactivex.rxjava3.core.Maybe<> tryAcquire​(long waitTime,  unit)
      Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been .
      io.reactivex.rxjava3.core.Single<>  permitId)
      Releases a permit by its id, returning it to the semaphore.
      io.reactivex.rxjava3.core.Single<> trySetPermits​(int permits)
      Sets number of permits.
      io.reactivex.rxjava3.core.Single<>  permitId, long leaseTime,  unit)
      Overrides and updates lease time for defined permit id.
    • Method Detail

      • acquire

        io.reactivex.rxjava3.core.Single<> acquire()
        Acquires a permit from this semaphore, blocking until one is available, or the thread is .

        Acquires a permit, if one is available and returns its id, reducing the number of available permits by one.

        If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

        • Some other thread invokes the release(String) method for this semaphore and the current thread is next to be assigned a permit; or
        • Some other thread the current thread.
        Returns:
        permit id
      • acquire

        io.reactivex.rxjava3.core.Single<> acquire​(long leaseTime,
                                                          unit)
        Acquires a permit with defined lease time from this semaphore, blocking until one is available, or the thread is .

        Acquires a permit, if one is available and returns its id, reducing the number of available permits by one.

        If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

        • Some other thread invokes the release(java.lang.String) method for this semaphore and the current thread is next to be assigned a permit; or
        • Some other thread the current thread.
        Parameters:
        leaseTime - - permit lease time
        unit - - time unit
        Returns:
        permit id
      • tryAcquire

        io.reactivex.rxjava3.core.Maybe<> tryAcquire()
        Acquires a permit only if one is available at the time of invocation.

        Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.

        If no permit is available then this method will return immediately with the value null.

        Returns:
        permit id if a permit was acquired and null otherwise
      • tryAcquire

        io.reactivex.rxjava3.core.Maybe<> tryAcquire​(long waitTime,
                                                            unit)
        Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been .

        Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.

        If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

        • Some other thread invokes the release(String) method for this semaphore and the current thread is next to be assigned a permit; or
        • Some other thread the current thread; or
        • The specified waiting time elapses.

        If a permit is acquired then the permit id is returned.

        If the specified waiting time elapses then the value null is returned. If the time is less than or equal to zero, the method will not wait at all.

        Parameters:
        waitTime - the maximum time to wait for a permit
        unit - the time unit of the timeout argument
        Returns:
        permit id if a permit was acquired and null if the waiting time elapsed before a permit was acquired
      • tryAcquire

        io.reactivex.rxjava3.core.Maybe<> tryAcquire​(long waitTime,
                                                           long leaseTime,
                                                            unit)
        Acquires a permit with defined lease time from this semaphore, if one becomes available within the given waiting time and the current thread has not been .

        Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.

        If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

        • Some other thread invokes the release(String) method for this semaphore and the current thread is next to be assigned a permit; or
        • Some other thread the current thread; or
        • The specified waiting time elapses.

        If a permit is acquired then the permit id is returned.

        If the specified waiting time elapses then the value null is returned. If the time is less than or equal to zero, the method will not wait at all.

        Parameters:
        waitTime - the maximum time to wait for a permit
        leaseTime - permit lease time
        unit - the time unit of the timeout argument
        Returns:
        permit id if a permit was acquired and null if the waiting time elapsed before a permit was acquired
      • tryRelease

        io.reactivex.rxjava3.core.Single<> tryRelease​( permitId)
        Releases a permit by its id, returning it to the semaphore.

        Releases a permit, increasing the number of available permits by one. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that was just released.

        There is no requirement that a thread that releases a permit must have acquired that permit by calling acquire(). Correct usage of a semaphore is established by programming convention in the application.

        Parameters:
        permitId - - permit id
        Returns:
        true if a permit has been released and false otherwise
      • release

        io.reactivex.rxjava3.core.Completable release​( permitId)
        Releases a permit by its id, returning it to the semaphore.

        Releases a permit, increasing the number of available permits by one. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that was just released.

        There is no requirement that a thread that releases a permit must have acquired that permit by calling acquire(). Correct usage of a semaphore is established by programming convention in the application.

        Throws an exception if permit id doesn't exist or has already been release

        Parameters:
        permitId - - permit id
        Returns:
        void
      • availablePermits

        io.reactivex.rxjava3.core.Single<> availablePermits()
        Returns the current number of available permits.
        Returns:
        number of available permits
      • trySetPermits

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

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

        io.reactivex.rxjava3.core.Single<> updateLeaseTime​( permitId,
                                                                  long leaseTime,
                                                                   unit)
        Overrides and updates lease time for defined permit id.
        Parameters:
        permitId - - permit id
        leaseTime - - permit lease time, use -1 to make it permanent
        unit - - the time unit of the timeout argument
        Returns:
        true if permits has been updated successfully, otherwise false.