Package alluxio.resource
Class LockResource
- java.lang.Object
-
- alluxio.resource.LockResource
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
RWLockResource
public class LockResource extends java.lang.Object implements java.io.Closeable
A resource lock that makes it possible to acquire and release locks using the following idiom:try (LockResource r = new LockResource(lock)) { ... }
The subclasses will be tracked by the leak detector. The subclasses should call super.close() in their close(), otherwise a leak will be reported.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.Lock
mLock
-
Constructor Summary
Constructors Constructor Description LockResource(java.util.concurrent.locks.Lock lock)
Creates a new instance ofLockResource
using the given lock.LockResource(java.util.concurrent.locks.Lock lock, boolean acquireLock, boolean useTryLock)
Creates a new instance ofLockResource
using the given lock.LockResource(java.util.concurrent.locks.Lock lock, boolean acquireLock, boolean useTryLock, java.lang.Runnable closeAction)
Creates a new instance ofLockResource
using the given lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Releases the lock.boolean
hasSameLock(LockResource other)
Returns true if the otherLockResource
contains the same lock.
-
-
-
Constructor Detail
-
LockResource
public LockResource(java.util.concurrent.locks.Lock lock)
Creates a new instance ofLockResource
using the given lock.- Parameters:
lock
- the lock to acquire
-
LockResource
public LockResource(java.util.concurrent.locks.Lock lock, boolean acquireLock, boolean useTryLock)
Creates a new instance ofLockResource
using the given lock. This method may use theLock.tryLock()
method to gain ownership of the locks. The reason one might want to use this is to avoid the fairness heuristics within theReentrantReadWriteLock
's NonFairSync which may block reader threads if a writer is the first in the queue.- Parameters:
lock
- the lock to acquireacquireLock
- whether to lock the lockuseTryLock
- whether or not use toLock.tryLock()
-
LockResource
public LockResource(java.util.concurrent.locks.Lock lock, boolean acquireLock, boolean useTryLock, @Nullable java.lang.Runnable closeAction)
Creates a new instance ofLockResource
using the given lock. This method may use theLock.tryLock()
method to gain ownership of the locks. The reason one might want to use this is to avoid the fairness heuristics within theReentrantReadWriteLock
's NonFairSync which may block reader threads if a writer is the first in the queue.- Parameters:
lock
- the lock to acquireacquireLock
- whether to lock the lockuseTryLock
- whether or not use toLock.tryLock()
closeAction
- the nullable closeable that will be run before releasing the lock
-
-
Method Detail
-
hasSameLock
public boolean hasSameLock(LockResource other)
Returns true if the otherLockResource
contains the same lock.- Parameters:
other
- other LockResource- Returns:
- true if the other lockResource has the same lock
-
close
public void close()
Releases the lock.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-