use of com.arjuna.ats.internal.txoj.LockListIterator in project narayana by jbosstm.
the class LockManager method print.
/**
* Print information about this instance on the specified
* <code>PrintWriter</code>.
*/
public void print(PrintWriter strm) {
LockListIterator next = new LockListIterator(locksHeld);
Lock current;
strm.println("LocalLockManager for object " + get_uid());
if (!stateLoaded)
strm.println("No loaded state");
else if (locksHeld != null) {
strm.println("\tCurrently holding : " + locksHeld.entryCount() + " locks");
while ((current = next.iterate()) != null) current.print(strm);
} else
strm.println("Currently holding : 0 locks");
}
use of com.arjuna.ats.internal.txoj.LockListIterator in project narayana by jbosstm.
the class LockManager method lockConflict.
/*
* lockconflict: Here we attempt to determine if the provided lock is in
* conflict with any of the existing locks. If it is we use nested locking
* rules to allow children to lock objects already locked by their
* ancestors.
*/
protected final int lockConflict(Lock otherLock) {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::lockConflict(" + otherLock.get_uid() + ")");
}
boolean matching = false;
Lock heldLock = null;
LockListIterator next = new LockListIterator(locksHeld);
while ((heldLock = next.iterate()) != null) {
if (heldLock.conflictsWith(otherLock)) {
if (LockManager.nestedLocking) {
if (!isAncestorOf(heldLock))
/* not quite Moss's rules */
return ConflictType.CONFLICT;
} else
return ConflictType.CONFLICT;
} else {
if (heldLock.equals(otherLock))
matching = true;
}
}
return (matching ? ConflictType.PRESENT : ConflictType.COMPATIBLE);
}
use of com.arjuna.ats.internal.txoj.LockListIterator in project narayana by jbosstm.
the class LockListIteratorUnitTest method test.
@Test
public void test() throws Exception {
LockList list = new LockList();
LockListIterator iter = new LockListIterator(list);
assertEquals(iter.iterate(), null);
iter.reset();
}
use of com.arjuna.ats.internal.txoj.LockListIterator in project narayana by jbosstm.
the class LockManager method doRelease.
/*
* doRelease: Does all the hard work of lock release. Either releases all
* locks for a given tx uid, or simply one lock with a given uid as
* appropriate.
*/
protected boolean doRelease(Uid u, boolean all) {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::doRelease(" + u + ", " + all + ")");
}
if (!lockMutex())
return false;
Lock previous = null;
Lock current = null;
boolean deleted = false;
boolean result = false;
int retryCount = 10;
boolean loaded = false;
boolean releasedOK = false;
BasicAction currAct = BasicAction.Current();
try {
synchronized (locksHeldLockObject) {
do {
if (loadState()) {
loaded = true;
/*
* Must declare iterator after loadstate or it sees an empty
* list!
*/
LockListIterator next = new LockListIterator(locksHeld);
/*
* Now scan through held lock list to find which locks to
* release u is either the unique id of the lock owner
* (oneOrAll = ALL_LOCKS) or the uid of the actual lock
* itself (oneOrAll = SINGLE_LOCK).
*/
previous = null;
while ((current = next.iterate()) != null) {
Uid checkUid = null;
if (all)
checkUid = current.getCurrentOwner();
else
checkUid = current.get_uid();
if (u.equals(checkUid)) {
locksHeld.forgetNext(previous);
current = null;
deleted = true;
if (!all) {
break;
}
} else
previous = current;
}
result = true;
} else {
/*
* Free state while we still have the lock.
*/
freeState();
result = false;
}
if (!result) {
try {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("LockManager.doRelease() Dozing");
}
Thread.sleep(LockManager.DOZE_TIME);
} catch (InterruptedException e) {
}
} else {
// if (!stateLoaded)
if (!loaded) {
txojLogger.i18NLogger.warn_LockManager_7();
/*
* No need to freeState since we will have done that by now.
*/
} else {
if (!deleted) {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace(" *** CANNOT locate locks ***");
}
}
int unloadRetryCount = 10;
do {
if (!unloadState()) {
txojLogger.i18NLogger.warn_LockManager_8();
} else
releasedOK = true;
} while ((--unloadRetryCount > 0) && (!releasedOK));
}
}
} while ((!result) && (--retryCount > 0));
}
/*
* Now signal to any waiting threads that they may try to acquire the
* lock.
*/
conflictManager.signal();
} finally {
unlockMutex();
}
return releasedOK;
}
Aggregations