Search in sources :

Example 6 with BasicAction

use of com.arjuna.ats.arjuna.coordinator.BasicAction 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 7 with BasicAction

use of com.arjuna.ats.arjuna.coordinator.BasicAction in project narayana by jbosstm.

the class StateManager method destroy.

/**
 * Destroy the object (e.g., remove its state from the persistent store.)
 * Calls to destroy for volatile objects (ones not maintained within the
 * volatile object store) are ignored, and FALSE is returned.
 *
 * @return <code>true</code> on success, <code>false</code> otherwise.
 */
public synchronized boolean destroy() {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::destroy for object-id " + objectUid);
    }
    boolean result = false;
    if (participantStore != null) {
        BasicAction action = BasicAction.Current();
        if (// add will fail if the status is wrong!
        action != null) {
            DisposeRecord dr = new DisposeRecord(participantStore, this);
            if (action.add(dr) != AddOutcome.AR_ADDED) {
                dr = null;
                tsLogger.i18NLogger.warn_StateManager_6(action.get_uid());
            } else
                result = true;
        } else {
            try {
                result = participantStore.remove_committed(get_uid(), type());
                if (result)
                    destroyed();
            } catch (Exception e) {
                tsLogger.i18NLogger.warn_StateManager_7(e);
                result = false;
            }
        }
    } else {
        /*
             * Not a persistent object!
             */
        tsLogger.i18NLogger.warn_StateManager_8();
    }
    return result;
}
Also used : BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 8 with BasicAction

use of com.arjuna.ats.arjuna.coordinator.BasicAction 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 9 with BasicAction

use of com.arjuna.ats.arjuna.coordinator.BasicAction in project narayana by jbosstm.

the class BasicThreadedObject method run.

public void run() {
    if (startAction) {
        BasicThreadedObject.A = new AtomicAction();
        System.out.println("BasicThreadedObject " + uid + " created action " + BasicThreadedObject.A.get_uid());
        BasicThreadedObject.A.begin();
        Thread.yield();
    } else {
        System.out.println("BasicThreadedObject " + uid + " adding to action " + BasicThreadedObject.A.get_uid());
        BasicThreadedObject.A.addThread();
        Thread.yield();
    }
    BasicAction act = BasicAction.Current();
    if (act != null)
        System.out.println("BasicThreadedObject " + uid + " current action " + act.get_uid());
    else
        System.out.println("BasicThreadedObject " + uid + " current action null");
    try {
        BasicThreadedObject.O.incr(4);
        Thread.yield();
    } catch (TestException e) {
    }
    if (startAction) {
        System.out.println("\nBasicThreadedObject " + uid + " committing action " + act.get_uid());
        BasicThreadedObject.A.commit();
        System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " committed\n");
    } else {
        System.out.println("\nBasicThreadedObject " + uid + " aborting action " + act.get_uid());
        BasicThreadedObject.A.abort();
        System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " aborted\n");
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 10 with BasicAction

use of com.arjuna.ats.arjuna.coordinator.BasicAction in project narayana by jbosstm.

the class LockManager method cleanUp.

protected final void cleanUp() {
    if (txojLogger.logger.isTraceEnabled()) {
        txojLogger.logger.trace("LockManager::cleanUp() for object-id " + get_uid());
    }
    if (lockMutex()) {
        if (hasBeenLocked) {
            if ((super.objectModel == ObjectModel.MULTIPLE) && (systemKey == null)) {
                initialise();
            }
            /*
                 * Unlike in the original version of Arjuna, we don't check to see
                 * if the invoking thread is within a transaction. We look at
                 * whether this object has been used within a transaction, and then
                 * act accordingly.
                 */
            BasicAction current = BasicAction.Current();
            synchronized (super.usingActions) {
                if (super.usingActions != null) {
                    Enumeration e = super.usingActions.elements();
                    while (e.hasMoreElements()) {
                        BasicAction action = (BasicAction) e.nextElement();
                        if (// shouldn't be null!!
                        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.
                                 */
                            /*
                                 * We need to create a cadaver lock record to
                                 * maintain the locks because this object is being
                                 * deleted.
                                 */
                            AbstractRecord A = new CadaverLockRecord(lockStore, this, action);
                            if (action.add(A) != AddOutcome.AR_ADDED) {
                                A = null;
                            }
                        }
                    }
                }
            }
            hasBeenLocked = false;
        }
        unlockMutex();
    }
}
Also used : Enumeration(java.util.Enumeration) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) CadaverLockRecord(com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Aggregations

BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)22 Uid (com.arjuna.ats.arjuna.common.Uid)8 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)3 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)3 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 CadaverActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)2 CadaverLockRecord (com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord)2 Enumeration (java.util.Enumeration)2 SystemException (org.omg.CORBA.SystemException)2 Inactive (org.omg.CosTransactions.Inactive)2 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)2 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)1 ActionHierarchy (com.arjuna.ats.arjuna.coordinator.ActionHierarchy)1 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)1 ActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord)1 CadaverRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)1