Search in sources :

Example 41 with AtomicTransaction

use of com.arjuna.ats.jts.extensions.AtomicTransaction 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 42 with AtomicTransaction

use of com.arjuna.ats.jts.extensions.AtomicTransaction 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 43 with AtomicTransaction

use of com.arjuna.ats.jts.extensions.AtomicTransaction 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 44 with AtomicTransaction

use of com.arjuna.ats.jts.extensions.AtomicTransaction 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)

Example 45 with AtomicTransaction

use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.

the class Client16 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 3]);
        Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        int numberOfWorkers = Integer.parseInt(args[args.length - 2]);
        int numberOfCalls = Integer.parseInt(args[args.length - 1]);
        Worker[] workers = new Worker[numberOfWorkers];
        for (int index = 0; index < workers.length; index++) {
            workers[index] = new Worker(numberOfCalls, counter);
        }
        for (int index = 0; index < workers.length; index++) {
            workers[index].start();
        }
        boolean correct = true;
        for (int index = 0; index < workers.length; index++) {
            workers[index].join();
            correct = correct && workers[index].isCorrect();
        }
        IntHolder value = new IntHolder();
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        counter.get(value, OTS.current().get_control());
        atomicTransaction.commit(true);
        correct = correct && (value.value == (numberOfWorkers * numberOfCalls));
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client16.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client16.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Aggregations

AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)101 Lock (com.arjuna.ats.txoj.Lock)38 Date (java.util.Date)36 IntHolder (org.omg.CORBA.IntHolder)12 JVMStats (org.jboss.jbossts.qa.Utils.JVMStats)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 SystemException (org.omg.CORBA.SystemException)6 DemoResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource)3 ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)2 TopLevelTransaction (com.arjuna.ats.jts.extensions.TopLevelTransaction)2 Control (org.omg.CosTransactions.Control)2 DemoSubTranResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource)1 com.hp.mwtests.ts.jts.orbspecific.resources.demosync (com.hp.mwtests.ts.jts.orbspecific.resources.demosync)1 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)1