Search in sources :

Example 36 with Lock

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

the class AtomicObject method incr.

public synchronized boolean incr(int value) {
    boolean res = false;
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 5) == LockResult.GRANTED) {
            _value = _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 37 with Lock

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

the class HammerObject method get.

public boolean get(IntHolder value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.incr - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
            value.value = _value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.get: " + 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 38 with Lock

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

the class HammerObject method incr.

public boolean incr(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.incr - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            _value = _value + value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.incr: " + 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 39 with Lock

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

the class AITMatrixImpl01 method get_value.

public void get_value(int x, int y, IntHolder value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
                value.value = _values[x][y];
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl01.get_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException(Reason.ReasonUnknown);
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITMatrixImpl01.get_value: " + exception);
        throw new InvocationException(Reason.ReasonUnknown);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 40 with Lock

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

the class AITMatrixImpl01 method set_value.

public void set_value(int x, int y, int value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
                _values[x][y] = value;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl01.set_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException(Reason.ReasonUnknown);
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITMatrixImpl01.set_value: " + exception);
        throw new InvocationException(Reason.ReasonUnknown);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) 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