Search in sources :

Example 51 with InputObjectState

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

the class OtherObjectStoreAPIJMXTest method testNullActionStore.

@Test
public void testNullActionStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    NullActionStore as = new NullActionStore(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) NullActionStore(com.arjuna.ats.internal.arjuna.objectstore.NullActionStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 52 with InputObjectState

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

the class LockManager 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
     * retrieving 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.
     */
/*
     * Return to 'protected final boolean' if we address https://issues.jboss.org/browse/JBTM-2399
     */
protected 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 Lock(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) ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Example 53 with InputObjectState

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

the class TORecoveryModule method periodicWorkFirstPass.

public void periodicWorkFirstPass() {
    if (txojLogger.logger.isDebugEnabled()) {
        txojLogger.logger.debug("TORecoveryModule - first pass");
    }
    // Build a hashtable of uncommitted transactional objects
    _uncommittedTOTable = new Hashtable();
    try {
        InputObjectState types = new InputObjectState();
        // find all the types of transactional object (in this ObjectStore)
        if (_objectStore.allTypes(types)) {
            String theName = null;
            try {
                boolean endOfList = false;
                while (!endOfList) {
                    // extract a type
                    theName = types.unpackString();
                    if (theName.compareTo("") == 0)
                        endOfList = true;
                    else {
                        InputObjectState uids = new InputObjectState();
                        // entry in the object store
                        if (_objectStore.allObjUids(theName, uids, StateStatus.OS_UNCOMMITTED)) {
                            Uid theUid = null;
                            try {
                                boolean endOfUids = false;
                                while (!endOfUids) {
                                    // extract a uid
                                    theUid = UidHelper.unpackFrom(uids);
                                    if (theUid.equals(Uid.nullUid()))
                                        endOfUids = true;
                                    else {
                                        String newTypeString = new String(theName);
                                        Uid newUid = new Uid(theUid);
                                        _uncommittedTOTable.put(newUid, newTypeString);
                                        if (txojLogger.logger.isDebugEnabled()) {
                                            txojLogger.logger.debug("TO currently uncommitted " + newUid + " is a " + newTypeString);
                                        }
                                    }
                                }
                            } catch (Exception e) {
                            // end of uids!
                            }
                        }
                    }
                }
            } catch (IOException ex) {
            // nothing there.
            } catch (Exception e) {
                txojLogger.i18NLogger.warn_recovery_TORecoveryModule_5(e);
            }
        }
    } catch (Exception e) {
        txojLogger.i18NLogger.warn_recovery_TORecoveryModule_5(e);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) Hashtable(java.util.Hashtable) IOException(java.io.IOException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 54 with InputObjectState

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

the class PersistenceTest method test.

@Test
public void test() throws Throwable {
    ParticipantStore store = StoreManager.getParticipantStore();
    OutputObjectState state = new OutputObjectState();
    Uid u = new Uid();
    assertTrue(store.write_committed(u, "/StateManager/LockManager/foo", state));
    InputObjectState inputState = store.read_committed(u, "/StateManager/LockManager/foo");
    assertNotNull(inputState);
    store.stop();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) Test(org.junit.Test)

Example 55 with InputObjectState

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

the class IOStateUnitTest method testIOObjectState.

@Test
public void testIOObjectState() throws Exception {
    OutputObjectState oos = new OutputObjectState(new Uid(), "");
    oos.packBoolean(true);
    oos.packByte((byte) 0);
    oos.packChar('a');
    oos.packDouble(1.0);
    oos.packFloat((float) 1.0);
    oos.packInt(1);
    oos.packLong(1234);
    oos.packShort((short) 10);
    oos.packString("test");
    assertTrue(oos.valid());
    PrintWriter pw = new PrintWriter(new StringWriter());
    oos.print(pw);
    assertTrue(oos.length() != 0);
    assertTrue(oos.notempty());
    assertTrue(oos.stateUid() != Uid.nullUid());
    assertTrue(oos.buffer() != null);
    assertTrue(oos.size() > 0);
    assertTrue(oos.type() != null);
    OutputObjectState temp = new OutputObjectState(oos);
    assertTrue(temp.toString() != null);
    InputObjectState ios = new InputObjectState(oos);
    assertTrue(ios.buffer() != null);
    assertTrue(ios.length() > 0);
    assertTrue(ios.notempty());
    assertTrue(ios.size() > 0);
    assertTrue(ios.stateUid() != Uid.nullUid());
    assertTrue(ios.valid());
    ios.print(pw);
    InputObjectState is = new InputObjectState(ios);
    assertTrue(is.toString() != null);
    assertTrue(ios.unpackBoolean());
    assertEquals(ios.unpackByte(), (byte) 0);
    assertEquals(ios.unpackChar(), 'a');
    assertTrue(ios.unpackDouble() == 1.0);
    assertTrue(ios.unpackFloat() == (float) 1.0);
    assertEquals(ios.unpackInt(), 1);
    assertEquals(ios.unpackLong(), 1234);
    assertEquals(ios.unpackShort(), (short) 10);
    assertEquals(ios.unpackString(), "test");
    InputObjectState c = new InputObjectState();
    OutputObjectState buff = new OutputObjectState();
    OutputObjectState o = new OutputObjectState();
    Uid u = new Uid();
    buff.packString("foobar");
    UidHelper.packInto(u, buff);
    buff.packInto(o);
    InputBuffer ibuff = new InputBuffer(o.buffer());
    c.copy(ios);
    ios.unpackFrom(ibuff);
    ios.copyFrom(new OutputObjectState());
    assertTrue(ios.toString() != null);
    oos.reset();
    oos.rewrite();
    oos.packInto(new OutputObjectState());
    oos.copy(new OutputObjectState());
    assertTrue(oos.toString() != null);
    temp = new OutputObjectState(new Uid(), "", null);
    assertFalse(temp.valid());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) StringWriter(java.io.StringWriter) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PrintWriter(java.io.PrintWriter) 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