Search in sources :

Example 46 with Lock

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

the class ExplicitStackImple method pop.

public int pop(IntHolder val, Control action) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(action);
    } catch (Exception e) {
        System.err.println("WARNING ExplicitStackImple::push - could not create interposition.");
        return -1;
    }
    String name = OTSImpleManager.current().get_transaction_name();
    System.out.println("Created pop interposed transaction: " + name);
    name = null;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top > 0) {
                top--;
                val.value = array[top];
            } else
                res = -1;
            if (res == 0) {
                A.commit(false);
            } else
                A.rollback();
        } else {
            A.rollback();
        }
    } catch (Exception e1) {
        try {
            A.rollback();
        } catch (Exception e2) {
            System.err.println(e2);
        }
        res = -1;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 47 with Lock

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

the class StackImple method printStack.

public void printStack() throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top > 0) {
                System.out.println("\nContents of stack:");
                for (int i = 0; i < top; i++) System.out.println("\t" + array[i]);
            } else
                System.out.println("\nStack is empty.");
            A.commit(false);
        } else {
            System.out.println("printStack: could not set WRITE lock.");
            A.rollback();
        }
    } catch (Exception e1) {
        try {
            A.rollback();
        } catch (Exception e2) {
            System.err.println(e2);
        }
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 48 with Lock

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

the class AtomicObject method set.

public synchronized boolean set(int value) {
    boolean res = false;
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 5) == LockResult.GRANTED) {
            _value = value;
            current.commit(false);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        logger.info(e);
        logger.warn(e.getMessage(), e);
        res = false;
    }
    return res;
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) IOException(java.io.IOException) TestException(com.hp.mwtests.ts.jts.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 49 with Lock

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

the class HammerObject method set.

public boolean set(int value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.set - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            _value = value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.set: " + e);
        res = false;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 50 with Lock

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

the class LockManagerProxyUnitTest method testTransactionalUpdate.

public void testTransactionalUpdate() {
    ExtendedLockable sample = new ExtendedLockable();
    LockManagerProxy<ExtendedLockable> proxy = new LockManagerProxy<ExtendedLockable>(sample);
    assertNotNull(proxy.type());
    AtomicAction A = new AtomicAction();
    A.begin();
    sample._isState = new Double(1.0);
    assertEquals(proxy.setlock(new Lock(LockMode.WRITE)), LockResult.GRANTED);
    sample._isState = new Double(4.0);
    A.abort();
    assertEquals(sample._isState, new Double(1.0));
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Lock(com.arjuna.ats.txoj.Lock)

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