public class GcsLock extends Object implements DistributedLock, Serializable
| Constructor and Description |
|---|
GcsLock(GcsLockConfig lockConfig) |
| Modifier and Type | Method and Description |
|---|---|
void |
addLockListener(GcsLockListener listener)
Add a lock listener as the callback for state change
|
boolean |
isHeldByCurrentThread() |
boolean |
isLocked() |
void |
lock()
Acquires the lock.
|
void |
lockInterruptibly()
Acquires the lock unless the current thread is
interrupted.
|
void |
removeLockListener(GcsLockListener listener)
Remove a lock listener as the callback for state change
|
boolean |
tryLock()
Acquires the lock only if it is free at the time of invocation.
|
boolean |
tryLock(long time,
TimeUnit timeUnit)
Acquires the lock if it is free within the given waiting time and the
current thread has not been interrupted.
|
void |
unlock()
Releases the lock.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnewConditionpublic GcsLock(GcsLockConfig lockConfig)
public boolean tryLock()
Acquires the lock if it is available and returns immediately
with the value true.
If the lock is not available then this method will return
immediately with the value false.
Any exception would be returned as the parameter in the callback GcsLockListener#acquireLockException(java.lang.Exception)
public boolean tryLock(long time,
TimeUnit timeUnit)
throws InterruptedException
If the lock is available this method returns immediately
with the value true.
If the lock is not available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until one of three things happens:
If the lock is acquired then the value true is returned.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.
If the specified waiting time elapses then the value false
is returned.
If the time is
less than or equal to zero, the method will not wait at all.
tryLock in interface Locktime - the maximum time to wait for the locktimeUnit - the time unit of the time argumenttrue if the lock was acquired and false
if the waiting time elapsed before the lock was acquiredInterruptedException - if the current thread is interrupted
while acquiring the lock (and interruption of lock
acquisition is supported)public void 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.
Any exception would be returned as the parameter in the callback GcsLockListener#acquireLockException(java.lang.Exception)
public void lockInterruptibly()
throws InterruptedException
Acquires the lock if it is available and returns immediately.
If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.lockInterruptibly in interface LockInterruptedException - if the current thread is
interrupted while acquiring the lock (and interruption
of lock acquisition is supported)public void unlock()
While used in multi-thread environment only the thread that originally acquired the lock is able to release the lock.
Any exception would be returned as the parameter in the callback GcsLockListener#releaseLockException(java.lang.Exception)
public boolean isLocked()
true if the lock has been acquired and
false otherwisepublic boolean isHeldByCurrentThread()
true if the lock was acquired by the current thread
false otherwisepublic void addLockListener(GcsLockListener listener)
listener - public void removeLockListener(GcsLockListener listener)
listener - Copyright © 2021. All rights reserved.