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

org.redisson.api.RPermitExpirableSemaphoreAsync 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-2021 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.concurrent.TimeUnit;

/**
 * Asynchronous 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 RPermitExpirableSemaphoreAsync extends RExpirableAsync { /** * Acquires a permit and returns its id. * Waits if necessary until a permit became available. * * @return permit id */ RFuture acquireAsync(); /** * 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 */ RFuture acquireAsync(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 */ RFuture tryAcquireAsync(); /** * 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 */ RFuture tryAcquireAsync(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 */ RFuture tryAcquireAsync(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 */ RFuture tryReleaseAsync(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. * * @param permitId - permit id * @return void */ RFuture releaseAsync(String permitId); /** * Returns amount of available permits. * * @return number of permits */ RFuture availablePermitsAsync(); /** * Tries to set number of permits. * * @param permits - number of permits * @return true if permits has been set successfully, otherwise false. */ RFuture trySetPermitsAsync(int permits); /** * Increases or decreases the number of available permits by defined value. * * @param permits amount of permits to add/remove * @return void */ RFuture addPermitsAsync(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. */ RFuture updateLeaseTimeAsync(String permitId, long leaseTime, TimeUnit unit); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy