Search in sources :

Example 21 with InputObjectState

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

the class InheritenceLockManagerProxyUnitTest method testInheritSaveRestore.

public void testInheritSaveRestore() {
    Inherit obj = new Inherit();
    LockManagerProxy<Inherit> proxy = new LockManagerProxy<Inherit>(obj);
    OutputObjectState os = new OutputObjectState();
    assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
    obj.myString = "";
    InputObjectState ios = new InputObjectState(os);
    assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
    assertEquals(obj.myString, "");
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 22 with InputObjectState

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

the class InheritenceLockManagerProxyUnitTest method testSaveRestore.

public void testSaveRestore() {
    BasicLockable obj = new BasicLockable();
    LockManagerProxy<BasicLockable> proxy = new LockManagerProxy<BasicLockable>(obj);
    OutputObjectState os = new OutputObjectState();
    assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
    obj._saved = 4567;
    // make sure it's ignored by save/restore.
    obj._isState = 0;
    ((Base) obj).valid = false;
    InputObjectState ios = new InputObjectState(os);
    assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
    assertEquals(obj._saved, 1234);
    assertEquals(obj._isState, 0);
    assertTrue(((Base) obj).valid);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 23 with InputObjectState

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

the class OptimisticLockManager method loadState.

/*
     * Lock and load the concurrency control state. First we grab the semaphore
     * to ensure exclusive access and then we build the held lock list by
     * retreiving the locks from the lock repository. If there is only one
     * server we do not bother doing this since all the locks can stay in the
     * server's memory. This is yet another consequence of not having
     * multi-threaded servers. Does not require synchronized since it can only
     * be called from other synchronized methods.
     */
protected final boolean loadState() {
    if (txojLogger.logger.isTraceEnabled()) {
        txojLogger.logger.trace("LockManager::loadState()");
    }
    if (super.objectModel == ObjectModel.SINGLE) {
        stateLoaded = true;
        return true;
    } else {
        InputObjectState S = null;
        if ((systemKey == null) && !initialise()) {
            return false;
        /* init failed */
        }
        if ((mutex == null) || (!mutex.tryLock())) {
            return false;
        }
        stateLoaded = false;
        objectLocked = true;
        try {
            S = lockStore.read_state(get_uid(), type());
            if (S != null) {
                Uid u = null;
                /*
                                                     * avoid system calls in Uid
                                                     * creation
                                                     */
                Lock current = null;
                int count = 0;
                try {
                    count = S.unpackInt();
                    boolean cleanLoad = true;
                    if (txojLogger.logger.isTraceEnabled()) {
                        txojLogger.logger.trace("LockManager::loadState() loading " + count + " lock(s)");
                    }
                    for (int i = 0; (i < count) && cleanLoad; i++) {
                        try {
                            u = UidHelper.unpackFrom(S);
                            current = new OptimisticLock(u);
                            if (current != null) {
                                if (current.restore_state(S, ObjectType.ANDPERSISTENT)) {
                                    locksHeld.push(current);
                                } else {
                                    current = null;
                                    cleanLoad = false;
                                }
                            } else {
                                cleanLoad = false;
                            }
                        } catch (IOException e) {
                            cleanLoad = false;
                        }
                    }
                    if (cleanLoad)
                        stateLoaded = true;
                    else {
                        while ((current = locksHeld.pop()) != null) current = null;
                    }
                } catch (IOException e) {
                }
                S = null;
            } else
                stateLoaded = true;
        } catch (LockStoreException e) {
            txojLogger.logger.warn(e);
        }
    }
    if (!stateLoaded) {
        if (// means object model != SINGLE
        mutex != null) {
            // and exit mutual exclusion
            mutex.unlock();
        }
        objectLocked = false;
    }
    return stateLoaded;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) IOException(java.io.IOException) LockStoreException(com.arjuna.ats.txoj.exceptions.LockStoreException) Lock(com.arjuna.ats.txoj.Lock)

Example 24 with InputObjectState

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

the class ObjectStoreTest 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";
    for (int i = 0; i < 100; i++) {
        Uid u = new Uid();
        InputObjectState ios = new InputObjectState();
        try {
            as.allObjUids("", ios);
        } catch (final Exception ex) {
        }
        try {
            assertTrue(as.read_uncommitted(u, tn) == null);
        } catch (final Exception ex) {
        }
        try {
            as.commit_state(u, tn);
        } catch (final Exception ex) {
        }
        as.write_committed(u, tn, buff);
        assertTrue(as.currentState(u, tn) == StateStatus.OS_COMMITTED);
        as.read_committed(u, tn);
        try {
            assertTrue(as.remove_uncommitted(u, tn));
        } catch (final Exception ex) {
        }
        as.remove_committed(u, tn);
        try {
            assertTrue(as.hide_state(u, tn));
        } catch (final Exception ex) {
        }
        try {
            assertTrue(as.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) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) VolatileStore(com.arjuna.ats.internal.arjuna.objectstore.VolatileStore) TwoPhaseVolatileStore(com.arjuna.ats.internal.arjuna.objectstore.TwoPhaseVolatileStore) Test(org.junit.Test)

Example 25 with InputObjectState

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

the class ObjectStoreTest method testHashedStore.

@Test
public void testHashedStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    HashedStore as = new HashedStore(objectStoreEnvironmentBean);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    for (int i = 0; i < 100; i++) {
        Uid u = new Uid();
        as.write_uncommitted(u, tn, buff);
        as.commit_state(u, tn);
        assertTrue(as.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
        InputObjectState ios = new InputObjectState();
        as.allObjUids("", ios);
        assertTrue(as.read_uncommitted(u, tn) == null);
        as.write_committed(u, tn, buff);
        as.read_committed(u, tn);
        assertTrue(!as.remove_uncommitted(u, tn));
        as.remove_committed(u, tn);
        assertTrue(!as.hide_state(u, tn));
        assertTrue(!as.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) HashedStore(com.arjuna.ats.internal.arjuna.objectstore.HashedStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) 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