Search in sources :

Example 46 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState 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 47 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class ObjectStateQuery method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    String uid = null;
    String type = null;
    for (int i = 0; i < args.length; i++) {
        if (args[i].compareTo("-help") == 0) {
            usage();
            System.exit(0);
        } else {
            if (args[i].compareTo("-uid") == 0) {
                uid = args[i + 1];
                i++;
            } else {
                if (args[i].compareTo("-type") == 0) {
                    type = args[i + 1];
                    i++;
                } else {
                    System.out.println("Unknown option " + args[i]);
                    usage();
                    System.exit(0);
                }
            }
        }
    }
    try {
        RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
        System.out.println("Status is " + recoveryStore.currentState(new Uid(uid), type));
        InputObjectState buff = new InputObjectState();
        recoveryStore.allObjUids(type, buff, StateStatus.OS_UNCOMMITTED);
        Uid u = UidHelper.unpackFrom(buff);
        System.out.println("got " + u);
    } catch (Exception e) {
        System.err.println("Caught unexpected exception: " + e);
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore)

Example 48 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class OtherObjectStoreAPIJMXTest method testActionStore.

@Test
public void testActionStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    ActionStore as = new ActionStore(objectStoreEnvironmentBean);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    createMBeans(as, as);
    for (int i = 0; i < 10; i++) {
        Uid u = new Uid();
        psProxy.write_uncommitted(u, tn, buff);
        psProxy.commit_state(u, tn);
        assertTrue(rsProxy.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
        InputObjectState ios = new InputObjectState();
        rsProxy.allObjUids("", ios);
        assertTrue(psProxy.read_uncommitted(u, tn) == null);
        rsProxy.write_committed(u, tn, buff);
        rsProxy.read_committed(u, tn);
        assertTrue(!psProxy.remove_uncommitted(u, tn));
        rsProxy.remove_committed(u, tn);
        assertTrue(!rsProxy.hide_state(u, tn));
        assertTrue(!rsProxy.reveal_state(u, tn));
    }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ActionStore(com.arjuna.ats.internal.arjuna.objectstore.ActionStore) NullActionStore(com.arjuna.ats.internal.arjuna.objectstore.NullActionStore) HashedActionStore(com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore) Test(org.junit.Test)

Example 49 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class OtherObjectStoreAPIJMXTest method testVolatileStore.

@Test
public void testVolatileStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    VolatileStore as = new VolatileStore(objectStoreEnvironmentBean);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    createMBeans(as, as);
    for (int i = 0; i < 10; i++) {
        Uid u = new Uid();
        InputObjectState ios = new InputObjectState();
        try {
            rsProxy.allObjUids("", ios);
        } catch (final Exception ex) {
        }
        try {
            assertTrue(psProxy.read_uncommitted(u, tn) == null);
        } catch (final Exception ex) {
        }
        try {
            psProxy.commit_state(u, tn);
        } catch (final Exception ex) {
        }
        rsProxy.write_committed(u, tn, buff);
        assertTrue(rsProxy.currentState(u, tn) == StateStatus.OS_COMMITTED);
        rsProxy.read_committed(u, tn);
        try {
            assertTrue(psProxy.remove_uncommitted(u, tn));
        } catch (final Exception ex) {
        }
        rsProxy.remove_committed(u, tn);
        try {
            assertTrue(rsProxy.hide_state(u, tn));
        } catch (final Exception ex) {
        }
        try {
            assertTrue(rsProxy.reveal_state(u, tn));
        } catch (final Exception ex) {
        }
    }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) VolatileStore(com.arjuna.ats.internal.arjuna.objectstore.VolatileStore) Test(org.junit.Test)

Example 50 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class OtherObjectStoreAPIJMXTest method testHashedActionStore.

@Test
public void testHashedActionStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    HashedActionStore as = new HashedActionStore(objectStoreEnvironmentBean);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    createMBeans(as, as);
    for (int i = 0; i < 10; i++) {
        Uid u = new Uid();
        psProxy.write_uncommitted(u, tn, buff);
        psProxy.commit_state(u, tn);
        assertTrue(rsProxy.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
        InputObjectState ios = new InputObjectState();
        rsProxy.allObjUids("", ios);
        assertTrue(psProxy.read_uncommitted(u, tn) == null);
        rsProxy.write_committed(u, tn, buff);
        rsProxy.read_committed(u, tn);
        assertTrue(!psProxy.remove_uncommitted(u, tn));
        rsProxy.remove_committed(u, tn);
        assertTrue(!rsProxy.hide_state(u, tn));
        assertTrue(!rsProxy.reveal_state(u, tn));
    }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) HashedActionStore(com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore) Test(org.junit.Test)

Aggregations

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4