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

org.redisson.api.RRateLimiterRx 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 io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * Reactive interface for Redis based Rate Limiter object.
 * 
 * @author Nikita Koksharov
 *
 */
public interface RRateLimiterRx extends RExpirableRx {

    /**
     * Use {@link #trySetRate(RateType, long, Duration)} instead
     * 
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     * @param rateIntervalUnit rate time interval unit
     * @return {@code true} if rate was set and {@code false}
     *         otherwise
     */
    @Deprecated
    Single trySetRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);

    /**
     * Sets the rate limit only if it hasn't been set before.
     *
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     * @return {@code true} if rate was set and {@code false}
     *         otherwise
     */
    Single trySetRate(RateType mode, long rate, Duration rateInterval);

    /**
     * Sets the rate limit only if it hasn't been set before.
     * Time to live is applied only if rate limit has been set successfully.
     *
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     * @param keepAliveTime this is the maximum time that key will wait for new acquire before delete
     * @return {@code true} if rate was set and {@code false}
     *         otherwise
     */
    Single trySetRate(RateType mode, long rate, Duration rateInterval, Duration keepAliveTime);

    /**
     * Use {@link #setRate(RateType, long, Duration)} instead.
     *
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     * @param rateIntervalUnit rate time interval unit
     *
     */
    @Deprecated
    Single setRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);

    /**
     * Sets the rate limit and clears the state.
     * Overrides both limit and state if they haven't been set before.
     *
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     */
    Single setRate(RateType mode, long rate, Duration rateInterval);

    /**
     * Sets time to live, the rate limit, and clears the state.
     * Overrides both limit and state if they haven't been set before.
     *
     * @param mode rate mode
     * @param rate rate
     * @param rateInterval rate time interval
     * @param keepAliveTime this is the maximum time that key will wait for new acquire before delete
     */
    Single setRate(RateType mode, long rate, Duration rateInterval, Duration keepAliveTime);

    /**
     * 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 value {@code true}, * reducing the number of available permits by one. * *

If no permit is available then this method will return * immediately with the value {@code false}. * * @return {@code true} if a permit was acquired and {@code false} * otherwise */ Single tryAcquire(); /** * Acquires the given number of permits only if all are available at the * time of invocation. * *

Acquires a permits, if all are available and returns immediately, * with the value {@code true}, * reducing the number of available permits by given number of permits. * *

If no permits are available then this method will return * immediately with the value {@code false}. * * @param permits the number of permits to acquire * @return {@code true} if a permit was acquired and {@code false} * otherwise */ Single tryAcquire(long permits); /** * Acquires a permit from this RateLimiter, blocking until one is available. * *

Acquires a permit, if one is available and returns immediately, * reducing the number of available permits by one. * * @return void */ Completable acquire(); /** * Acquires a specified permits from this RateLimiter, * blocking until one is available. * *

Acquires the given number of permits, if they are available * and returns immediately, reducing the number of available permits * by the given amount. * * @param permits the number of permits to acquire * @return void */ Completable acquire(long permits); /** * Use {@link #tryAcquire(Duration)} instead. * * @param timeout the maximum time to wait for a permit * @param unit the time unit of the {@code timeout} argument * @return {@code true} if a permit was acquired and {@code false} * if the waiting time elapsed before a permit was acquired */ @Deprecated Single tryAcquire(long timeout, TimeUnit unit); /** * Acquires a permit from this RateLimiter, if one becomes available * within the given waiting time. * *

Acquires a permit, if one is available and returns immediately, * with the value {@code true}, * 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 * specified waiting time elapses. * *

If a permit is acquired then the value {@code true} is returned. * *

If the specified waiting time elapses then the value {@code false} * is returned. If the time is less than or equal to zero, the method * will not wait at all. * * @param timeout the maximum time to wait for a permit * @return {@code true} if a permit was acquired and {@code false} * if the waiting time elapsed before a permit was acquired */ Single tryAcquire(Duration timeout); /** * Use {@link #tryAcquire(long, Duration)} instead. * * @param permits amount * @param timeout the maximum time to wait for a permit * @param unit the time unit of the {@code timeout} argument * @return {@code true} if a permit was acquired and {@code false} * if the waiting time elapsed before a permit was acquired */ @Deprecated Single tryAcquire(long permits, long timeout, TimeUnit unit); /** * Acquires the given number of permits only if all are available * within the given waiting time. * *

Acquires the given number of permits, if all are available and returns immediately, * with the value {@code true}, 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 * the specified waiting time elapses. * *

If a permits is acquired then the value {@code true} is returned. * *

If the specified waiting time elapses then the value {@code false} * is returned. If the time is less than or equal to zero, the method * will not wait at all. * * @param permits amount * @param timeout the maximum time to wait for a permit * @return {@code true} if a permit was acquired and {@code false} * if the waiting time elapsed before a permit was acquired */ Single tryAcquire(long permits, Duration timeout); /** * Returns amount of available permits. * * @return number of permits */ Single availablePermits(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy