Search in sources :

Example 1 with CadaverRecord

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;
}
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 CadaverRecord

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()));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

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