Search in sources :

Example 11 with BasicAction

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

the class LockManager method setlock.

/*
     * This is the main user visible operation. Attempts to set the given lock
     * on the current object. If lock cannot be set, then the lock attempt is
     * retried retry times before giving up and returning an error. This gives a
     * simple handle on deadlock.
     * 
     * sleepTime is milliseconds.
     * 
     * @return <code>LockResult</code> indicating outcome.
     */
public int setlock(Lock toSet, int retry, int sleepTime) {
    if (txojLogger.logger.isTraceEnabled()) {
        txojLogger.logger.trace("LockManager::setlock(" + toSet + ", " + retry + ", " + sleepTime + ")");
    }
    int returnStatus = LockResult.REFUSED;
    // JBTM-2098, we need to have the action locked in case a simultaneous abort
    // is issued which would try to lock the mutex before we can call modified
    Object toLock = BasicAction.Current();
    if (toLock == null) {
        toLock = new Object();
    }
    synchronized (toLock) {
        if (!lockMutex())
            return LockResult.REFUSED;
        try {
            int conflict = ConflictType.CONFLICT;
            LockRecord newLockR = null;
            boolean modifyRequired = false;
            BasicAction currAct = null;
            if (toSet == null) {
                txojLogger.i18NLogger.warn_LockManager_2();
                return LockResult.REFUSED;
            }
            currAct = BasicAction.Current();
            if (currAct != null) {
                ActionHierarchy ah = currAct.getHierarchy();
                if (ah != null)
                    toSet.changeHierarchy(ah);
                else {
                    txojLogger.i18NLogger.warn_LockManager_3();
                    toSet = null;
                    return LockResult.REFUSED;
                }
            }
            if (super.loadObjectState())
                super.setupStore();
            while ((conflict == ConflictType.CONFLICT) && ((retry >= 0) || ((retry == LockManager.waitTotalTimeout) && (sleepTime > 0)))) {
                synchronized (locksHeldLockObject) {
                    conflict = ConflictType.CONFLICT;
                    if (loadState()) {
                        conflict = lockConflict(toSet);
                    } else {
                        txojLogger.i18NLogger.warn_LockManager_4();
                    }
                    if (conflict != ConflictType.CONFLICT) {
                        /*
                         * When here the conflict was resolved or the retry limit
                         * expired.
                         */
                        /* no conflict so set lock */
                        modifyRequired = toSet.modifiesObject();
                        if (super.activate()) {
                            returnStatus = LockResult.GRANTED;
                            if (conflict == ConflictType.COMPATIBLE) {
                                int lrStatus = AddOutcome.AR_ADDED;
                                if (currAct != null) {
                                    /* add new lock record to action list */
                                    newLockR = new LockRecord(this, (modifyRequired ? false : true), currAct);
                                    if ((lrStatus = currAct.add(newLockR)) != AddOutcome.AR_ADDED) {
                                        newLockR = null;
                                        if (lrStatus == AddOutcome.AR_REJECTED)
                                            returnStatus = LockResult.REFUSED;
                                    }
                                }
                                if (returnStatus == LockResult.GRANTED) {
                                    locksHeld.insert(toSet);
                                /*
                                     * add to local lock
                                     * list
                                     */
                                }
                            }
                        } else {
                            /* activate failed - refuse request */
                            txojLogger.i18NLogger.warn_LockManager_5();
                            returnStatus = LockResult.REFUSED;
                        }
                    }
                    if ((returnStatus == LockResult.GRANTED) && (conflict == ConflictType.COMPATIBLE)) {
                        if (!unloadState()) {
                            txojLogger.i18NLogger.warn_LockManager_6();
                            returnStatus = LockResult.REFUSED;
                        }
                    } else
                        freeState();
                    if (returnStatus == LockResult.GRANTED) {
                        if (modifyRequired) {
                            if (super.modified())
                                hasBeenLocked = true;
                            else {
                                conflict = ConflictType.CONFLICT;
                                returnStatus = LockResult.REFUSED;
                            }
                        }
                    }
                    if (conflict == ConflictType.CONFLICT)
                        freeState();
                }
                if (conflict == ConflictType.CONFLICT) {
                    if (retry != 0) {
                        if (sleepTime > 0) {
                            sleepTime -= conflictManager.wait(retry, sleepTime);
                        } else
                            retry = 0;
                    }
                    if (retry != LockManager.waitTotalTimeout)
                        retry--;
                }
            }
        } finally {
            unlockMutex();
        }
    }
    return returnStatus;
}
Also used : BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) CadaverLockRecord(com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord) LockRecord(com.arjuna.ats.internal.txoj.abstractrecords.LockRecord) ActionHierarchy(com.arjuna.ats.arjuna.coordinator.ActionHierarchy)

Example 12 with BasicAction

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

the class LockManager method finalize.

/**
 * Cleanup. Note we grab the semaphore before destroying the lock store
 * to ensure the store is deleted cleanly.
 */
public void finalize() throws Throwable {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("LockManager.finalize() for object-id " + get_uid() + " type " + type());
    }
    if (status() == ObjectStatus.ACTIVE_NEW) {
        BasicAction action = BasicAction.Current();
        if ((action != null) && (action.status() == ActionStatus.RUNNING)) {
            tsLogger.i18NLogger.warn_StateManager_1();
            cleanup(false);
        }
    }
    boolean doSignal = false;
    cleanUp();
    if (mutex != null) {
        if (mutex.isLocked())
            doSignal = true;
    }
    locksHeld = null;
    lockStore = null;
    conflictManager = null;
    try {
        if (// mutex must be set
        doSignal) {
            mutex.unlock();
        }
    } catch (final Throwable ex) {
    }
    mutex = null;
}
Also used : BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction)

Example 13 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 existing action");
        if (A != null)
            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 (Exception 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)

Example 14 with BasicAction

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

the class TransactionFactoryImple method getChildTransactions.

/**
 * @return the list of child transactions.
 */
public org.omg.CosTransactions.otid_t[] getChildTransactions(otid_t parent) throws Inactive, NoTransaction, SystemException {
    Uid u = Utility.otidToUid(parent);
    org.omg.CosTransactions.otid_t[] ctx = null;
    if (u == null)
        throw new BAD_PARAM("otid_t " + jtsLogger.i18NLogger.get_orbspecific_otiderror());
    else {
        BasicAction act = ActionManager.manager().get(u);
        if (act == null)
            throw new NoTransaction();
        else {
            if (act.status() == ActionStatus.RUNNING) {
                Object[] children = act.childTransactions();
                int size = ((children == null) ? 0 : children.length);
                if (size > 0) {
                    ctx = new org.omg.CosTransactions.otid_t[size];
                    for (int i = 0; i < size; i++) {
                        ctx[i] = Utility.uidToOtid((Uid) children[i]);
                    }
                }
            } else
                throw new Inactive();
        }
    }
    return ctx;
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Uid(com.arjuna.ats.arjuna.common.Uid) Inactive(org.omg.CosTransactions.Inactive)

Example 15 with BasicAction

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

the class StateManager method modified.

/*
     * Protected non-virtual functions.
     */
/**
 * The object's state is about to be modified, and StateManager should take
 * a snapshot of the state if the object is being used within a transaction.
 *
 * @return <code>true</code> on success, <code>false</code> otherwise.
 */
protected synchronized boolean modified() {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::modified() for object-id " + get_uid());
    }
    BasicAction action = BasicAction.Current();
    RecoveryRecord record = null;
    if ((myType == ObjectType.NEITHER) || (currentStatus == ObjectStatus.DESTROYED)) /*
                                                               * NEITHER => no
                                                               * recovery info
                                                               */
    {
        return true;
    }
    if (currentStatus == ObjectStatus.PASSIVE) {
        tsLogger.i18NLogger.warn_StateManager_10();
        activate();
    }
    if (currentStatus == ObjectStatus.PASSIVE_NEW)
        currentStatus = ObjectStatus.ACTIVE_NEW;
    if (action != null) {
        /*
             * Check if this is the first call to modified in this action.
             * BasicList insert returns FALSE if the entry is already present.
             */
        createLists();
        synchronized (modifyingActions) {
            if ((modifyingActions.size() > 0) && (modifyingActions.get(action.get_uid()) != null)) {
                return true;
            } else
                modifyingActions.put(action.get_uid(), action);
        }
        /* If here then its a new action */
        OutputObjectState state = new OutputObjectState(objectUid, type());
        int rStatus = AddOutcome.AR_ADDED;
        if (save_state(state, ObjectType.RECOVERABLE)) {
            if ((myType == ObjectType.RECOVERABLE) && (objectModel == ObjectModel.SINGLE)) {
                record = new RecoveryRecord(state, this);
            } else
                record = new PersistenceRecord(state, participantStore, this);
            if ((rStatus = action.add(record)) != AddOutcome.AR_ADDED) {
                synchronized (modifyingActions) {
                    // remember
                    modifyingActions.remove(action.get_uid());
                // to
                // unregister
                // with
                // action
                }
                record = null;
                return false;
            }
        } else
            return false;
    }
    return true;
}
Also used : RecoveryRecord(com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)

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