Search in sources :

Example 21 with Lock

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

the class AITCounterImpl04 method set.

public void set(int value) throws InvocationException {
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.WRITE), super.waitTotalTimeout) == LockResult.GRANTED) {
                _value = value;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITCounterImpl04.set: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException();
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITCounterImpl04.set: " + exception);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 22 with Lock

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

the class AITCounterImpl01 method increase.

public void increase() throws InvocationException {
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
                _value++;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITCounterImpl01.increase: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException();
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITCounterImpl01.increase: " + exception);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 23 with Lock

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

the class AITPingPongImpl01 method hit.

public void hit(int count, PingPong ponger, PingPong pinger) throws InvocationException {
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (count != 0) {
                ponger.hit(count - 1, pinger, ponger);
                atomicTransaction.commit(true);
            } else if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
                _value++;
                atomicTransaction.commit(true);
            } else {
                System.err.println("AITPingPongImpl01.hit: failed to get lock");
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITPingPongImpl01.hit: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException();
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITPingPongImpl01.hit: " + exception);
        throw new InvocationException();
    } catch (Error error) {
        System.err.println("AITPingPongImpl01.hit: " + error);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 24 with Lock

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

the class AITPingPongImpl01 method get.

public void get(IntHolder value) throws InvocationException {
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
                value.value = _value;
                atomicTransaction.commit(true);
            } else {
                System.err.println("AITPingPongImpl01.get: failed to get lock");
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITPingPongImpl01.get: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException();
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITPingPongImpl01.get: " + exception);
        throw new InvocationException();
    } catch (Error error) {
        System.err.println("AITPingPongImpl01.get: " + error);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 25 with Lock

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

the class AITCounterImpl04 method set.

public void set(int value, Control ctrl) throws InvocationException {
    try {
        com.arjuna.ats.jts.ExplicitInterposition interposition = new com.arjuna.ats.jts.ExplicitInterposition();
        interposition.registerTransaction(ctrl);
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.WRITE), super.waitTotalTimeout) == LockResult.GRANTED) {
                _value = value;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITCounterImpl04.set: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITCounterImpl04.set: " + error);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        }
        interposition.unregisterTransaction();
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITCounterImpl04.set: " + exception);
        throw new InvocationException();
    }
}
Also used : JVMStats(org.jboss.jbossts.qa.Utils.JVMStats) 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