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

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

/**
 * Copyright 2018 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;
import java.util.concurrent.locks.Lock;

/**
 * Distributed implementation of {@link java.util.concurrent.locks.Lock}
 * Implements reentrant lock.
 * Use {@link RLock#getHoldCount()} to get a holds count.
 *
 * @author Nikita Koksharov
 *
 */

public interface RLock extends Lock, RExpirable, RLockAsync {

    /**
     * Acquires the lock.
     *
     * 

If the lock is not available then the current thread becomes * disabled for thread scheduling purposes and lies dormant until the * lock has been acquired. * * If the lock is acquired, it is held until unlock is invoked, * or until leaseTime have passed * since the lock was granted - whichever comes first. * * @param leaseTime the maximum time to hold the lock after granting it, * before automatically releasing it if it hasn't already been released by invoking unlock. * If leaseTime is -1, hold the lock until explicitly unlocked. * @param unit the time unit of the {@code leaseTime} argument * @throws InterruptedException - if the thread is interrupted before or during this method. */ void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException; /** * Returns true as soon as the lock is acquired. * If the lock is currently held by another thread in this or any * other process in the distributed system this method keeps trying * to acquire the lock for up to waitTime before * giving up and returning false. If the lock is acquired, * it is held until unlock is invoked, or until leaseTime * have passed since the lock was granted - whichever comes first. * * @param waitTime the maximum time to aquire the lock * @param leaseTime lease time * @param unit time unit * @return true if lock has been successfully acquired * @throws InterruptedException - if the thread is interrupted before or during this method. */ boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException; /** * Acquires the lock. * *

If the lock is not available then the current thread becomes * disabled for thread scheduling purposes and lies dormant until the * lock has been acquired. * * If the lock is acquired, it is held until unlock is invoked, * or until leaseTime milliseconds have passed * since the lock was granted - whichever comes first. * * @param leaseTime the maximum time to hold the lock after granting it, * before automatically releasing it if it hasn't already been released by invoking unlock. * If leaseTime is -1, hold the lock until explicitly unlocked. * @param unit the time unit of the {@code leaseTime} argument * */ void lock(long leaseTime, TimeUnit unit); /** * Unlocks lock independently of state * * @return true if unlocked otherwise false */ boolean forceUnlock(); /** * Checks if this lock locked by any thread * * @return true if locked otherwise false */ boolean isLocked(); /** * Checks if this lock is held by the current thread * * @return true if held by current thread * otherwise false */ boolean isHeldByCurrentThread(); /** * Number of holds on this lock by the current thread * * @return holds or 0 if this lock is not held by current thread */ int getHoldCount(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy