class LockManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private class |
LockManager.Lock
An utility class which represents single lock.
|
(package private) static class |
LockManager.LockRef
Utility class which is used to pass lock data between user and
LockManager . |
Modifier and Type | Field and Description |
---|---|
static int |
LOCK_COUNT
Number of different types of locks.
|
static int |
LOCK_RO
Read-only lock
|
static int |
LOCK_RW
Read/Write lock
|
static int |
LOCK_RX
Exclusive lock stage #1
|
static int |
LOCK_WX
Exclusive lock stage #2
|
private java.util.ArrayList<LockManager.Lock> |
lockList
Data storage where locks are stored
|
private static java.util.logging.Logger |
LOG |
static java.lang.String[] |
name
String representation of lock types
|
private boolean |
shutdown
Shutdown flag
|
Constructor and Description |
---|
LockManager()
Construct an instance of TreeLockManager.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
dumpLocks(java.lang.String msg)
Get snapshot of the current list of locks.
|
java.lang.Object |
enterLock(java.lang.String id,
int type)
Try to lock sub-tree.
|
private LockManager.Lock |
insertLock(LockManager.Lock lock)
Insert lock into the array.
|
private LockManager.Lock |
locateLock(java.lang.String id)
Locate existing lock which is on the same path the ID passed as a
parameter.
|
private int |
locateLockIndex(java.lang.String id)
Locate an index of the lock with the same ID or index where element with
ID provided as a parameter can be inserted without breaking ordering of
the array.
|
private static void |
log(java.util.logging.Level level,
java.lang.String message)
Logging helper.
|
void |
releaseLock(java.lang.Object objLock)
Release existing lock and notify all waiting threads if counter is set
to 0.
|
private void |
removeLock(LockManager.Lock lock)
Remove specified lock from the list.
|
void |
shutdownManager()
Shutdown manager and release all waiting threads.
|
boolean |
upgradeLock(java.lang.Object objLock)
Upgrade RX lock into RW lock.
|
public static final java.lang.String[] name
public static final int LOCK_COUNT
LockManager.Lock.getCount()
.public static final int LOCK_RO
public static final int LOCK_RW
public static final int LOCK_RX
public static final int LOCK_WX
private java.util.ArrayList<LockManager.Lock> lockList
private boolean shutdown
private static java.util.logging.Logger LOG
public java.lang.Object enterLock(java.lang.String id, int type)
Rules of lock coexistence:
id
- Sub-tree id to locktype
- Lock type to set.null
if lock can't be set for some reason.public void releaseLock(java.lang.Object objLock)
objLock
- Reference to lock which will be released.public void shutdownManager()
public boolean upgradeLock(java.lang.Object objLock)
objLock
- Reference to lock provided by the enterLock.true
if upgrade was successful.void dumpLocks(java.lang.String msg)
msg
- Additional message which will be printed in dump header.private static void log(java.util.logging.Level level, java.lang.String message)
level
- Debug level of this message.message
- Text of the message.private LockManager.Lock insertLock(LockManager.Lock lock)
lock
- Lock
instance to insert.null
otherwise.private LockManager.Lock locateLock(java.lang.String id)
Note that this method is invoked only from inside synchronization block
on lockList
.
id
- Sub-tree ID.null
if there is no such lock.private int locateLockIndex(java.lang.String id)
id
- Subtree ID.private void removeLock(LockManager.Lock lock)
Logic of enterLock(String, int)
and
releaseLock(Object)
allow a situation when lock is found in the
list and is about to be incremented (i.e LockManager.Lock.enter(int)
is
called) while this method is called. Since methods mentioned above
contain synchronization block on lockList
, the body of this
method will not be executed until those method will finish their work.
Since lock count may change, we check it right after entering the block.
lock
- A lock to remove.