| Method from org.jboss.ejb.BeanLockManager Detail: |
public boolean canPassivate(Object id) {
if (id == null)
throw new IllegalArgumentException("Attempt to passivate with a null object");
HashMap mapInUse = getHashMap(id);
synchronized (mapInUse)
{
BeanLock lock = (BeanLock) mapInUse.get(id);
if (lock == null)
throw new IllegalStateException("Attempt to passivate without a lock");
return (lock.getRefs() < = 1);
}
}
|
public BeanLock getLock(Object id) {
if (id == null)
throw new IllegalArgumentException("Attempt to get lock ref with a null object");
HashMap mapInUse = getHashMap(id);
synchronized (mapInUse)
{
BeanLock lock = (BeanLock) mapInUse.get(id);
if (lock!=null)
{
lock.addRef();
return lock;
}
}
try
{
BeanLock lock2 = (BeanLock)createLock(id);
synchronized(mapInUse)
{
BeanLock lock = (BeanLock) mapInUse.get(id);
// in case of bad luck, this might happen
if (lock != null)
{
lock.addRef();
return lock;
}
mapInUse.put(id, lock2);
lock2.addRef();
return lock2;
}
}
catch (Exception e)
{
// schrouf: should we really proceed with lock object
// in case of exception ??
log.warn("Failed to initialize lock:"+id, e);
throw new RuntimeException (e);
}
}
returns the lock associated with the key passed. If there is
no lock one is created this call also increments the number of
references interested in Lock.
WARNING: All access to this method MUST have an equivalent
removeLockRef cleanup call, or this will create a leak in the map, |
public LockMonitor getLockMonitor() {
return monitor;
}
|
public void removeLockRef(Object id) {
if (id == null)
throw new IllegalArgumentException("Attempt to remove lock ref with a null object");
HashMap mapInUse = getHashMap(id);
synchronized(mapInUse)
{
BeanLock lock = (BeanLock) mapInUse.get(id);
if (lock != null)
{
try
{
lock.removeRef();
if( trace )
log.trace("Remove ref lock:"+lock);
}
finally
{
// schrouf: ALLWAYS ensure proper map lock removal even in case
// of exception within lock.removeRef ! There seems to be a bug
// in the ref counting of QueuedPessimisticEJBLock under certain
// conditions ( lock.ref < 0 should never happen !!! )
if (lock.getRefs() < = 0)
{
Object mapLock = mapInUse.remove(lock.getId());
if( trace )
log.trace("Lock no longer referenced, lock: "+lock);
}
}
}
}
}
|
public void setContainer(Container container) {
this.container = container;
}
|
public void setLockCLass(Class lockClass) {
this.lockClass = lockClass;
}
|
public void setReentrant(boolean reentrant) {
this.reentrant = reentrant;
}
|