use of com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord in project narayana by jbosstm.
the class StateManager method cleanup.
/**
* Object cleanup. Attempt sane cleanup when object is deleted. Handle
* perverse cases where multiple actions are still active as object dies.
*
* @param fromTerminate
* indicates whether this method is being called from the
* <code>terminate</code> method, or from elsewhere.
* @see StateManager#terminate
*/
protected final synchronized void cleanup(boolean fromTerminate) {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("StateManager::cleanup() for object-id " + get_uid());
}
if (myType == ObjectType.NEITHER)
return;
BasicAction action = null;
synchronized (mutex) {
createLists();
if (usingActions.size() > 0) {
Enumeration e = usingActions.keys();
while (e.hasMoreElements()) {
action = (BasicAction) usingActions.remove(e.nextElement());
if (action != null) {
/*
* Pop actions off using list. Don't check if action is
* running below so that cadavers can be created in
* commit protocol too.
*/
AbstractRecord record = null;
int rStatus = AddOutcome.AR_ADDED;
if ((currentStatus == ObjectStatus.ACTIVE_NEW) || (currentStatus == ObjectStatus.ACTIVE)) {
OutputObjectState state = null;
tsLogger.i18NLogger.warn_StateManager_11(objectUid, type());
if (fromTerminate) {
state = new OutputObjectState(objectUid, type());
if (!save_state(state, myType)) {
tsLogger.i18NLogger.warn_StateManager_12();
/* force action abort */
action.preventCommit();
}
} else {
/* otherwise force action abort */
action.preventCommit();
}
/*
* This should be unnecessary - but just in case.
*/
setupStore(storeRoot);
record = new CadaverRecord(state, participantStore, this);
if ((rStatus = action.add(record)) != AddOutcome.AR_ADDED)
record = null;
}
if (currentlyActivated && (currentStatus != ObjectStatus.DESTROYED)) {
record = new CadaverActivationRecord(this);
if ((rStatus = action.add(record)) == AddOutcome.AR_ADDED) {
currentStatus = ObjectStatus.PASSIVE;
} else {
tsLogger.i18NLogger.warn_StateManager_6(action.get_uid());
record = null;
}
}
}
}
}
}
if (currentStatus == ObjectStatus.ACTIVE_NEW) {
if ((myType == ObjectType.RECOVERABLE) && (objectModel == ObjectModel.SINGLE)) {
currentStatus = ObjectStatus.ACTIVE;
} else {
currentStatus = ObjectStatus.PASSIVE;
}
}
currentlyActivated = false;
}
use of com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord in project narayana by jbosstm.
the class CadaverRecordUnitTest method test.
@Test
public void test() {
ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
CadaverRecord cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
assertTrue(cr.propagateOnAbort());
assertTrue(cr.propagateOnCommit());
assertEquals(cr.typeIs(), RecordType.PERSISTENCE);
assertTrue(cr.type() != null);
assertEquals(cr.doSave(), false);
cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new CadaverRecord();
cr.print(new PrintWriter(new ByteArrayOutputStream()));
assertFalse(cr.shouldMerge(new DisposeRecord()));
assertFalse(cr.shouldReplace(new DisposeRecord()));
}
Aggregations