Interface RPermitExpirableSemaphoreReactive

  • All Superinterfaces:
    RExpirableReactive, RObjectReactive

    public interface RPermitExpirableSemaphoreReactive
    extends RExpirableReactive
    Reactive 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 Detail

      • acquire

        reactor.core.publisher.Mono<String> acquire()
        Acquires a permit and returns its id. Waits if necessary until a permit became available.
        Returns:
        permit id
      • acquire

        reactor.core.publisher.Mono<String> acquire(long leaseTime,
                                                    TimeUnit unit)
        Acquires a permit with defined leaseTime and return its id. Waits if necessary until a permit became available.
        Parameters:
        leaseTime - permit lease time
        unit - time unit
        Returns:
        permit id
      • tryAcquire

        reactor.core.publisher.Mono<String> tryAcquire()
        Tries to acquire currently available permit and return its id.
        Returns:
        permit id if a permit was acquired and null otherwise
      • tryAcquire

        reactor.core.publisher.Mono<String> tryAcquire(long waitTime,
                                                       TimeUnit unit)
        Tries to acquire currently available permit and return its id. Waits up to defined waitTime if necessary until a permit became available.
        Parameters:
        waitTime - the maximum time to wait
        unit - the time unit
        Returns:
        permit id if a permit was acquired and null if the waiting time elapsed before a permit was acquired
      • tryAcquire

        reactor.core.publisher.Mono<String> tryAcquire(long waitTime,
                                                       long leaseTime,
                                                       TimeUnit unit)
        Tries to acquire currently available permit with defined leaseTime and return its id. Waits up to defined waitTime if necessary until a permit became available.
        Parameters:
        waitTime - the maximum time to wait
        leaseTime - permit lease time, use -1 to make it permanent
        unit - the time unit
        Returns:
        permit id if a permit was acquired and null if the waiting time elapsed before a permit was acquired
      • tryRelease

        reactor.core.publisher.Mono<Boolean> tryRelease(String permitId)
        Tries to release permit by its id.
        Parameters:
        permitId - permit id
        Returns:
        true if a permit has been released and false otherwise
      • release

        reactor.core.publisher.Mono<Void> release(String permitId)
        Releases a permit by its id. Increases the number of available permits. Throws an exception if permit id doesn't exist or has already been released.
        Parameters:
        permitId - - permit id
        Returns:
        void
      • availablePermits

        reactor.core.publisher.Mono<Integer> availablePermits()
        Returns amount of available permits.
        Returns:
        number of permits
      • trySetPermits

        reactor.core.publisher.Mono<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.
      • addPermits

        reactor.core.publisher.Mono<Void> addPermits(int permits)
        Increases or decreases the number of available permits by defined value.
        Parameters:
        permits - amount of permits to add/remove
        Returns:
        void
      • updateLeaseTime

        reactor.core.publisher.Mono<Boolean> updateLeaseTime(String permitId,
                                                             long leaseTime,
                                                             TimeUnit 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
        Returns:
        true if permits has been updated successfully, otherwise false.