Search in sources :

Example 1 with CadaverActivationRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord 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;
}
Also used : Enumeration(java.util.Enumeration) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)

Example 2 with CadaverActivationRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord in project narayana by jbosstm.

the class CadaverActivationUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverActivationRecord cr = new CadaverActivationRecord(new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertFalse(cr.shouldReplace(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject())));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
}
Also used : ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord) Test(org.junit.Test)

Aggregations

OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 CadaverActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)2 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)1 CadaverRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)1 PersistenceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)1 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)1 Enumeration (java.util.Enumeration)1 Test (org.junit.Test)1