use of com.arjuna.ats.arjuna.coordinator.ActionHierarchy in project narayana by jbosstm.
the class ArjunaContextImple method initialiseContext.
public void initialiseContext(Object param) {
try {
BACoordinator currentCoordinator = (BACoordinator) param;
ActivityHierarchy hier = null;
try {
hier = UserActivityFactory.userActivity().currentActivity();
} catch (SystemException ex) {
ex.printStackTrace();
}
if ((currentCoordinator != null) && (hier != null)) {
/*
* Do the manditory stuff first.
*/
ActionHierarchy txHier = currentCoordinator.getHierarchy();
final int depth = txHier.depth();
_identifierValues = new String[depth];
_expiresValues = new int[depth];
_identifierValues[0] = txHier.getDeepestActionUid().stringForm();
_expiresValues[0] = hier.activity(hier.size() - 1).getTimeout();
/*
* Now let's do the optional stuff.
*/
for (int count = 1, index = 0; count < depth; count++, index++) {
_identifierValues[count] = txHier.getActionUid(index).stringForm();
_expiresValues[count] = hier.activity(index).getTimeout();
}
}
} catch (ClassCastException ex) {
throw new IllegalArgumentException();
}
}
use of com.arjuna.ats.arjuna.coordinator.ActionHierarchy in project narayana by jbosstm.
the class LockManager method setlock.
/*
* This is the main user visible operation. Attempts to set the given lock
* on the current object. If lock cannot be set, then the lock attempt is
* retried retry times before giving up and returning an error. This gives a
* simple handle on deadlock.
*
* sleepTime is milliseconds.
*
* @return <code>LockResult</code> indicating outcome.
*/
public int setlock(Lock toSet, int retry, int sleepTime) {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::setlock(" + toSet + ", " + retry + ", " + sleepTime + ")");
}
int returnStatus = LockResult.REFUSED;
// JBTM-2098, we need to have the action locked in case a simultaneous abort
// is issued which would try to lock the mutex before we can call modified
Object toLock = BasicAction.Current();
if (toLock == null) {
toLock = new Object();
}
synchronized (toLock) {
if (!lockMutex())
return LockResult.REFUSED;
try {
int conflict = ConflictType.CONFLICT;
LockRecord newLockR = null;
boolean modifyRequired = false;
BasicAction currAct = null;
if (toSet == null) {
txojLogger.i18NLogger.warn_LockManager_2();
return LockResult.REFUSED;
}
currAct = BasicAction.Current();
if (currAct != null) {
ActionHierarchy ah = currAct.getHierarchy();
if (ah != null)
toSet.changeHierarchy(ah);
else {
txojLogger.i18NLogger.warn_LockManager_3();
toSet = null;
return LockResult.REFUSED;
}
}
if (super.loadObjectState())
super.setupStore();
while ((conflict == ConflictType.CONFLICT) && ((retry >= 0) || ((retry == LockManager.waitTotalTimeout) && (sleepTime > 0)))) {
synchronized (locksHeldLockObject) {
conflict = ConflictType.CONFLICT;
if (loadState()) {
conflict = lockConflict(toSet);
} else {
txojLogger.i18NLogger.warn_LockManager_4();
}
if (conflict != ConflictType.CONFLICT) {
/*
* When here the conflict was resolved or the retry limit
* expired.
*/
/* no conflict so set lock */
modifyRequired = toSet.modifiesObject();
if (super.activate()) {
returnStatus = LockResult.GRANTED;
if (conflict == ConflictType.COMPATIBLE) {
int lrStatus = AddOutcome.AR_ADDED;
if (currAct != null) {
/* add new lock record to action list */
newLockR = new LockRecord(this, (modifyRequired ? false : true), currAct);
if ((lrStatus = currAct.add(newLockR)) != AddOutcome.AR_ADDED) {
newLockR = null;
if (lrStatus == AddOutcome.AR_REJECTED)
returnStatus = LockResult.REFUSED;
}
}
if (returnStatus == LockResult.GRANTED) {
locksHeld.insert(toSet);
/*
* add to local lock
* list
*/
}
}
} else {
/* activate failed - refuse request */
txojLogger.i18NLogger.warn_LockManager_5();
returnStatus = LockResult.REFUSED;
}
}
if ((returnStatus == LockResult.GRANTED) && (conflict == ConflictType.COMPATIBLE)) {
if (!unloadState()) {
txojLogger.i18NLogger.warn_LockManager_6();
returnStatus = LockResult.REFUSED;
}
} else
freeState();
if (returnStatus == LockResult.GRANTED) {
if (modifyRequired) {
if (super.modified())
hasBeenLocked = true;
else {
conflict = ConflictType.CONFLICT;
returnStatus = LockResult.REFUSED;
}
}
}
if (conflict == ConflictType.CONFLICT)
freeState();
}
if (conflict == ConflictType.CONFLICT) {
if (retry != 0) {
if (sleepTime > 0) {
sleepTime -= conflictManager.wait(retry, sleepTime);
} else
retry = 0;
}
if (retry != LockManager.waitTotalTimeout)
retry--;
}
}
} finally {
unlockMutex();
}
}
return returnStatus;
}
use of com.arjuna.ats.arjuna.coordinator.ActionHierarchy in project narayana by jbosstm.
the class Lock method restore_state.
/**
* Carefully restore the state of a Lock.
*
* @return <code>true</code> if successful, <code>false</code> otherwise.
*/
public boolean restore_state(InputObjectState os, int ot) {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("Lock::restore_state(" + os + ", " + ot + ")");
}
ActionHierarchy ah = new ActionHierarchy(0);
try {
currentStatus = os.unpackInt();
lMode = os.unpackInt();
ah.unpack(os);
owners = ah;
return true;
} catch (IOException e) {
return false;
}
}
use of com.arjuna.ats.arjuna.coordinator.ActionHierarchy in project narayana by jbosstm.
the class ActionHierarchyUnitTest method test.
@Test
public void test() throws Exception {
ActionHierarchy ah = new ActionHierarchy(5);
Uid[] tx = new Uid[5];
assertEquals(ah.getDeepestActionUid(), Uid.nullUid());
for (int i = 0; i < tx.length; i++) {
tx[i] = new Uid();
ah.add(tx[i]);
}
assertEquals(ah.depth(), tx.length);
assertEquals(ah.getActionUid(0), tx[0]);
Uid deepest = new Uid();
ah.add(deepest, ActionType.TOP_LEVEL);
PrintWriter pw = new PrintWriter(System.err);
ah.print(pw);
assertEquals(ah.getDeepestActionUid(), deepest);
ActionHierarchy cp = new ActionHierarchy(ah);
assertTrue(cp.equals(ah));
cp.copy(ah);
ah.copy(ah);
assertTrue(cp.equals(ah));
OutputBuffer out = new OutputBuffer();
cp.pack(out);
InputBuffer in = new InputBuffer(out.buffer());
ah.unpack(in);
assertTrue(ah.equals(cp));
assertTrue(ah.isAncestor(deepest));
ah.forgetDeepest();
assertTrue(ah.findCommonPrefix(cp) != 0);
}
use of com.arjuna.ats.arjuna.coordinator.ActionHierarchy in project narayana by jbosstm.
the class ArjunaContextImple method initialiseContext.
public void initialiseContext(Object param) {
try {
ATCoordinator currentCoordinator = (ATCoordinator) param;
ActivityHierarchy hier = null;
try {
hier = UserActivityFactory.userActivity().currentActivity();
} catch (SystemException ex) {
ex.printStackTrace();
}
if ((currentCoordinator != null) && (hier != null)) {
/*
* Do the manditory stuff first.
*/
ActionHierarchy txHier = currentCoordinator.getHierarchy();
final int depth = txHier.depth();
_identifierValues = new String[depth];
_expiresValues = new int[depth];
_identifierValues[0] = txHier.getDeepestActionUid().stringForm();
_expiresValues[0] = hier.activity(hier.size() - 1).getTimeout();
/*
* Now let's do the optional stuff.
*/
for (int count = 1, index = 0; count < depth; count++, index++) {
_identifierValues[count] = txHier.getActionUid(index).stringForm();
_expiresValues[count] = hier.activity(index).getTimeout();
}
}
} catch (ClassCastException ex) {
throw new IllegalArgumentException();
}
}
Aggregations