Search in sources :

Example 1 with ActivationRecord

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

the class StateManager method activate.

/**
 * This operation activates an object. Activation of an object may entail
 * loading its passive state from the object store and unpacking it into the
 * memory resident form, or it may simply be a no-op. Full activation is
 * only necessary if the object is currently marked as being PASSIVE (that
 * is, the object was constructed as being of type ANDPERSISTENT with an
 * existing uid and has not already been activated). Objects that are not of
 * type ANDPERSISTENT or are persistent but have not yet been saved in an
 * object store (so-called new persistent objects) are unaffected by this
 * function. Returns false if PASSIVE object cannot be loaded from object
 * store, true otherwise.
 *
 * @return <code>true</code> on success, <code>false</code> otherwise.
 * @see com.arjuna.ats.arjuna.objectstore.ObjectStore
 */
public synchronized boolean activate(String rootName) {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::activate( " + ((rootName != null) ? rootName : "null") + ") for object-id " + objectUid);
    }
    if (myType == ObjectType.NEITHER) {
        return true;
    }
    if (currentStatus == ObjectStatus.DESTROYED)
        return false;
    BasicAction action = null;
    int oldStatus = currentStatus;
    boolean result = true;
    /* assume 'succeeds' */
    boolean forceAR = false;
    /*
         * Check if this action has logged its presence before. If not we force
         * creation of an ActivationRecord so that each thread/action tree has
         * an ActivationRecord in it. This allows us to passivate the object
         * when the last thread has finished with it, i.e., when the last
         * ActivationRecord is gone.
         */
    action = BasicAction.Current();
    if ((action != null) && (action.status() == ActionStatus.RUNNING)) {
        synchronized (mutex) {
            createLists();
            if (usingActions.get(action.get_uid()) == null) {
                /*
                     * May cause us to add parent as well as child.
                     */
                usingActions.put(action.get_uid(), action);
                forceAR = true;
            }
        }
    }
    if (forceAR || (currentStatus == ObjectStatus.PASSIVE) || (currentStatus == ObjectStatus.PASSIVE_NEW)) {
        if (loadObjectState()) {
            setupStore(rootName);
        }
        if (currentStatus == ObjectStatus.PASSIVE) {
            if (loadObjectState()) {
                InputObjectState oldState = null;
                try {
                    oldState = participantStore.read_committed(objectUid, type());
                } catch (ObjectStoreException e) {
                    e.printStackTrace();
                    oldState = null;
                }
                if (oldState != null) {
                    if ((result = restore_state(oldState, ObjectType.ANDPERSISTENT))) {
                        currentStatus = ObjectStatus.ACTIVE;
                    }
                    oldState = null;
                } else {
                    tsLogger.i18NLogger.warn_StateManager_2(objectUid, type());
                    return false;
                }
            } else {
                if (currentStatus == ObjectStatus.PASSIVE_NEW)
                    currentStatus = ObjectStatus.ACTIVE_NEW;
                else
                    currentStatus = ObjectStatus.ACTIVE;
            }
        } else {
            if (currentStatus == ObjectStatus.PASSIVE_NEW)
                currentStatus = ObjectStatus.ACTIVE_NEW;
            else
                currentStatus = ObjectStatus.ACTIVE;
        }
        if (forceAR || ((currentStatus == ObjectStatus.ACTIVE) || (currentStatus == ObjectStatus.PASSIVE_NEW)) && (action != null)) {
            int arStatus = AddOutcome.AR_ADDED;
            ActivationRecord ar = new ActivationRecord(oldStatus, this, action);
            if ((arStatus = action.add(ar)) != AddOutcome.AR_ADDED) {
                ar = null;
                if (forceAR) {
                    synchronized (mutex) {
                        usingActions.remove(action.get_uid());
                    }
                }
                if (arStatus == AddOutcome.AR_REJECTED)
                    result = false;
            } else {
                /*
                     * We never reset activated, so we can optimise state
                     * loading/unloading in the case of SINGLE object model
                     */
                currentlyActivated = activated = true;
            }
        } else {
            if (currentStatus == ObjectStatus.ACTIVE_NEW)
                currentlyActivated = activated = true;
        }
    }
    return result;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)

Example 2 with ActivationRecord

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

the class RecordListUnitTest method test.

@Test
public void test() throws Exception {
    RecordList rl = new RecordList();
    DisposeRecord dr = new DisposeRecord();
    rl.insert(dr);
    assertEquals(rl.getFront(), dr);
    rl.insert(dr);
    assertEquals(rl.getRear(), dr);
    RecordList copy = new RecordList(rl);
    ActivationRecord ar = new ActivationRecord();
    rl.insert(ar);
    rl.print(new PrintWriter(new ByteArrayOutputStream()));
    assertTrue(rl.toString() != null);
    assertEquals(rl.getNext(dr), null);
    assertTrue(rl.peekFront() != null);
    assertTrue(rl.peekRear() != null);
    assertEquals(rl.peekNext(dr), null);
    assertTrue(rl.remove(dr));
}
Also used : RecordList(com.arjuna.ats.arjuna.coordinator.RecordList) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with ActivationRecord

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

the class ActivationRecordUnitTest method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    AtomicAction B = new AtomicAction();
    A.begin();
    B.begin();
    ActivationRecord cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertEquals((Integer) cr.value(), new Integer(ObjectType.ANDPERSISTENT));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    B.abort();
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord();
    cr.merge(new ActivationRecord());
    cr.alter(new ActivationRecord());
    assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Aggregations

ActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 Test (org.junit.Test)2 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 RecordList (com.arjuna.ats.arjuna.coordinator.RecordList)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 CadaverActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)1 DisposeRecord (com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord)1 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1