Search in sources :

Example 11 with Lock

use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.

the class AtomicObject method set.

public void set(int value) throws TestException {
    AtomicAction A = new AtomicAction();
    A.begin();
    if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED) {
        state = value;
        if (A.commit() != ActionStatus.COMMITTED)
            throw new TestException("Action commit error.");
        else
            return;
    } else {
        if (printDebug)
            System.out.println("Error - could not set write lock.");
    }
    A.abort();
    throw new TestException("Write lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 12 with Lock

use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.

the class AtomicObject method get.

public int get() throws TestException {
    AtomicAction A = new AtomicAction();
    int value = -1;
    A.begin();
    if (setlock(new Lock(LockMode.READ), retry) == LockResult.GRANTED) {
        value = state;
        if (A.commit() == ActionStatus.COMMITTED)
            return value;
        else
            throw new TestException("Action commit error.");
    } else {
        if (printDebug)
            System.out.println("Error - could not set read lock.");
    }
    A.abort();
    throw new TestException("Read lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 13 with Lock

use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.

the class AtomicObjectLog method incr.

public void incr(int value) throws TestException {
    AtomicAction A = new AtomicAction();
    A.begin();
    if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
        state += value;
        if (A.commit() != ActionStatus.COMMITTED)
            throw new TestException("Action commit error.");
        else
            return;
    } else {
        if (printDebug)
            System.out.println("Error - could not set write lock.");
    }
    A.abort();
    throw new TestException("Write lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 14 with Lock

use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.

the class AtomicObjectLog method get.

public int get() throws TestException {
    AtomicAction A = new AtomicAction();
    int value = -1;
    A.begin();
    if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
        value = state;
        if (A.commit() == ActionStatus.COMMITTED)
            return value;
        else
            throw new TestException("Action commit error.");
    } else {
        if (printDebug)
            System.out.println("Error - could not set read lock.");
    }
    A.abort();
    throw new TestException("Read lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 15 with Lock

use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.

the class LockUnitTest method test.

@Test
public void test() throws Exception {
    Lock lock = new Lock();
    lock = new Lock(LockMode.WRITE);
    assertTrue(lock.getAllOwners() != null);
    assertEquals(lock.getCurrentStatus(), LockStatus.LOCKFREE);
    assertFalse(lock.equals(new Object()));
    assertFalse(lock.equals((Object) new Lock()));
    assertTrue(lock.equals(lock));
    assertTrue(lock.toString() != null);
    assertEquals(lock.type(), "/StateManager/Lock");
    lock.print(new PrintWriter(new ByteArrayOutputStream()));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Lock(com.arjuna.ats.txoj.Lock) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Lock (com.arjuna.ats.txoj.Lock)69 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)38 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)17 IOException (java.io.IOException)13 JVMStats (org.jboss.jbossts.qa.Utils.JVMStats)9 SystemException (org.omg.CORBA.SystemException)9 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)6 ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)5 TestException (com.hp.mwtests.ts.jts.exceptions.TestException)3 Method (java.lang.reflect.Method)2 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)1 Uid (com.arjuna.ats.arjuna.common.Uid)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 LockStoreException (com.arjuna.ats.txoj.exceptions.LockStoreException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LockException (org.jboss.stm.LockException)1 TransactionException (org.jboss.stm.TransactionException)1