Search in sources :

Example 31 with Lock

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

the class ExplicitStackImple method push.

public int push(int 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 push interposed transaction: " + name);
    name = null;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top < ARRAY_SIZE) {
                array[top] = val;
                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 32 with Lock

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

the class ExplicitStackImple 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 33 with Lock

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

the class StackImple method push.

public int push(int val) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top < ARRAY_SIZE) {
                array[top] = val;
                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;
    }
    return res;
}
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 34 with Lock

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

the class StackImple method pop.

public int pop(IntHolder val) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    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;
    }
    return res;
}
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 35 with Lock

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

the class AtomicObject method get.

public synchronized int get() throws TestException {
    CurrentImple current = OTSImpleManager.current();
    int value = -1;
    try {
        current.begin();
        if (setlock(new Lock(LockMode.READ), 5) == LockResult.GRANTED) {
            value = _value;
            current.commit(false);
            return value;
        } else {
            current.rollback();
            throw new TestException("Could not setlock");
        }
    } catch (Exception e) {
        throw new TestException(e);
    }
}
Also used : TestException(com.hp.mwtests.ts.jts.exceptions.TestException) 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)

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