Methods Summary |
---|
public boolean | canI(java.lang.Object key)Check to see if we can lock on a given object.
Object o = locks.get( key );
if (null == o || o == this.getCallerId()) {
return true;
}
return false;
|
private java.lang.Object | getCallerId()Private helper method to abstract away caller ID.
return Thread.currentThread();
|
public boolean | isLocked(java.lang.Object key)Check to see if the object is locked
return (locks.get(key) != null);
|
public boolean | lock(java.lang.Object key)Lock on a given object.
Object theLock;
synchronized(this) {
theLock = locks.get(key);
if (null == theLock) {
locks.put(key, getCallerId());
return true;
} else if (getCallerId() == theLock) {
return true;
} else {
return false;
}
}
|
public boolean | unlock(java.lang.Object key)Release the lock on a given object.
Object theLock;
synchronized (this) {
theLock = locks.get(key);
if (null == theLock) {
return true;
} else if (getCallerId() == theLock) {
locks.remove(key);
return true;
} else {
return false;
}
}
|