K
- key for the lockspublic class LockPool<K> extends Object implements Closeable
Constructor and Description |
---|
LockPool(java.util.function.Function<? super K,? extends ReentrantReadWriteLock> defaultLoader,
int initialSize,
int lowWatermark,
int highWatermark,
int concurrencyLevel)
Constructor for a lock pool.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
containsKey(K key)
Returns whether the pool contains a particular key.
|
LockResource |
get(K key,
LockMode mode)
Locks the specified key in the specified mode.
|
RWLockResource |
get(K key,
LockMode mode,
boolean useTryLock)
Locks the specified key in the specified mode.
|
Map<K,ReentrantReadWriteLock> |
getEntryMap() |
ReentrantReadWriteLock |
getRawReadWriteLock(K key)
Get the raw readwrite lock from the pool.
|
int |
size() |
String |
toString() |
Optional<RWLockResource> |
tryGet(K key,
LockMode mode)
Attempts to take a lock on the given key.
|
public LockPool(java.util.function.Function<? super K,? extends ReentrantReadWriteLock> defaultLoader, int initialSize, int lowWatermark, int highWatermark, int concurrencyLevel)
defaultLoader
- specify a function to generate a value based on a keyinitialSize
- initial size of the poollowWatermark
- low watermark of the pool sizehighWatermark
- high watermark of the pool sizeconcurrencyLevel
- concurrency level of the poolpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public LockResource get(K key, LockMode mode)
key
- the key to lockmode
- the mode to lock inpublic RWLockResource get(K key, LockMode mode, boolean useTryLock)
key
- the key to lockmode
- the mode to lock inuseTryLock
- Determines whether or not to use Lock.tryLock()
or
Lock.lock()
to acquire the lock. Differs from
tryGet(Object, LockMode)
in that it will block until the lock has
been acquired.public Optional<RWLockResource> tryGet(K key, LockMode mode)
key
- the key to lockmode
- lockMode to acquirepublic ReentrantReadWriteLock getRawReadWriteLock(K key)
key
- key to look up the valuepublic boolean containsKey(K key)
key
- the key to look up in the poolpublic int size()
public Map<K,ReentrantReadWriteLock> getEntryMap()
Copyright © 2023. All Rights Reserved.