Interface RSemaphoreAsync

All Superinterfaces:
RExpirableAsync, RObjectAsync
All Known Subinterfaces:
RSemaphore
All Known Implementing Classes:
RedissonQueueSemaphore, RedissonSemaphore

public interface RSemaphoreAsync extends RExpirableAsync
Async interface of Redis based Semaphore.

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

Author:
Nikita Koksharov
  • Method Details

    • tryAcquireAsync

      RFuture<Boolean> tryAcquireAsync()
      Acquires a permit. Waits if necessary until a permit became available.
      Returns:
      true if a permit was acquired and false otherwise
    • tryAcquireAsync

      RFuture<Boolean> tryAcquireAsync(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
    • acquireAsync

      RFuture<Void> acquireAsync()
      Acquires a permit. Waits if necessary until a permit became available.
      Returns:
      void
    • acquireAsync

      RFuture<Void> acquireAsync(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
    • releaseAsync

      RFuture<Void> releaseAsync()
      Releases a permit.
      Returns:
      void
    • releaseAsync

      RFuture<Void> releaseAsync(int permits)
      Releases defined amount of permits.
      Parameters:
      permits - amount
      Returns:
      void
    • trySetPermitsAsync

      RFuture<Boolean> trySetPermitsAsync(int permits)
      Tries to set number of permits.
      Parameters:
      permits - - number of permits
      Returns:
      true if permits has been set successfully, otherwise false.
    • tryAcquireAsync

      RFuture<Boolean> tryAcquireAsync(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
    • tryAcquireAsync

      RFuture<Boolean> tryAcquireAsync(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
    • addPermitsAsync

      RFuture<Void> addPermitsAsync(int permits)
      Increases or decreases the number of available permits by defined value.
      Parameters:
      permits - amount of permits to add/remove
    • availablePermitsAsync

      RFuture<Integer> availablePermitsAsync()
      Returns amount of available permits.
      Returns:
      number of permits
    • drainPermitsAsync

      RFuture<Integer> drainPermitsAsync()
      Acquires and returns all permits that are immediately available.
      Returns:
      number of permits