All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redisson.api.RPermitExpirableSemaphoreReactive Maven / Gradle / Ivy

Go to download

Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC

There is a newer version: 3.40.2
Show newest version
/**
 * Copyright (c) 2013-2024 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.api;

import java.util.List;
import java.util.concurrent.TimeUnit;

import reactor.core.publisher.Mono;

/**
 * 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 * */ public interface RPermitExpirableSemaphoreReactive extends RExpirableReactive { /** * Acquires a permit and returns its id. * Waits if necessary until a permit became available. * * @return permit id */ Mono acquire(); /** * Acquires defined amount of permits. * Waits if necessary until all permits became available. * * @param permits the number of permits to acquire * @return permits ids */ Mono> acquire(int permits); /** * Acquires a permit with defined leaseTime and return its id. * Waits if necessary until a permit became available. * * @param leaseTime permit lease time * @param unit time unit * @return permit id */ Mono acquire(long leaseTime, TimeUnit unit); /** * Acquires defined amount of permits with defined leaseTime and returns ids. * Waits if necessary until all permits became available. * * @param permits the number of permits to acquire * @param leaseTime permits lease time * @param unit time unit * @return permits ids */ Mono> acquire(int permits, long leaseTime, TimeUnit unit); /** * Tries to acquire currently available permit and return its id. * * @return permit id if a permit was acquired and {@code null} * otherwise */ Mono tryAcquire(); /** * Tries to acquire defined amount of currently available permits and returns ids. * * @param permits the number of permits to acquire * @return permits ids if permits were acquired and empty collection * otherwise */ Mono> tryAcquire(int permits); /** * Tries to acquire currently available permit and return its id. * Waits up to defined waitTime if necessary until a permit became available. * * @param waitTime the maximum time to wait * @param unit the time unit * @return permit id if a permit was acquired and {@code null} * if the waiting time elapsed before a permit was acquired */ Mono tryAcquire(long waitTime, 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. * * @param waitTime the maximum time to wait * @param leaseTime permit lease time, use -1 to make it permanent * @param unit the time unit * @return permit id if a permit was acquired and null * if the waiting time elapsed before a permit was acquired */ Mono tryAcquire(long waitTime, long leaseTime, TimeUnit unit); /** * Tries to acquire defined amount of currently available permits * with defined leaseTime and return their ids. * Waits up to defined waitTime if necessary until enough permits became available. * * @param permits the number of permits to acquire * @param waitTime the maximum time to wait * @param leaseTime permits lease time, use -1 to make them permanent * @param unit the time unit * @return permits ids if permits were acquired and empty collection * if the waiting time elapsed before permits were acquired */ Mono> tryAcquire(int permits, long waitTime, long leaseTime, TimeUnit unit); /** * Tries to release permit by its id. * * @param permitId permit id * @return true if a permit has been released and false * otherwise */ Mono tryRelease(String permitId); /** * Tries to release permits by their ids. * * @param permitsIds permits ids * @return amount of released permits */ Mono tryRelease(List permitsIds); /** * 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. * * @param permitId - permit id * @return void */ Mono release(String permitId); /** * Releases a permits by their ids. Increases the number of available permits. * Throws an exception if permit id doesn't exist or has already been released. * * @param permitsIds - permits ids * @return void */ Mono release(List permitsIds); /** * Returns amount of available permits. * * @return number of permits */ Mono availablePermits(); /** * Returns the number of permits. * * @return number of permits */ Mono getPermits(); /** * Returns the number of acquired permits. * * @return number of acquired permits */ Mono acquiredPermits(); /** * Tries to set number of permits. * * @param permits - number of permits * @return true if permits has been set successfully, otherwise false. */ Mono trySetPermits(int permits); /** * Sets the number of permits to the provided value. * Calculates the delta between the given permits value and the * current number of permits, then increases the number of available permits by delta. * * @param permits - number of permits */ Mono setPermits(int permits); /** * Increases or decreases the number of available permits by defined value. * * @param permits amount of permits to add/remove * @return void */ Mono addPermits(int permits); /** * Overrides and updates lease time for defined permit id. * * @param permitId permit id * @param leaseTime permit lease time, use -1 to make it permanent * @param unit the time unit * @return true if permits has been updated successfully, otherwise false. */ Mono updateLeaseTime(String permitId, long leaseTime, TimeUnit unit); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy