Search in sources :

Example 1 with AtomicTransaction

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

the class Client0001 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
        Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        int numberOfCalls = 1000;
        for (int index = 0; index < numberOfCalls; index++) {
            AtomicTransaction atomicTransaction = new AtomicTransaction();
            atomicTransaction.begin();
            try {
                counter.increase();
            } catch (InvocationException invocationException) {
            }
            atomicTransaction.commit(true);
        }
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        IntHolder value = new IntHolder();
        counter.get(value);
        atomicTransaction.commit(true);
        if (value.value == numberOfCalls) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client0001.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client0001.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Example 2 with AtomicTransaction

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

the class AITMatrixImpl01 method set_value.

public void set_value(int x, int y, int value, Control ctrl) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    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), 0) == LockResult.GRANTED) {
                _values[x][y] = value;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl01.set_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException(Reason.ReasonUnknown);
        } catch (Error error) {
            System.err.println("AITMatrixImpl01.set_value: " + error);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException(Reason.ReasonUnknown);
        }
        interposition.unregisterTransaction();
    } 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)

Example 3 with AtomicTransaction

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

the class AITMatrixImpl03 method get_value.

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

Example 4 with AtomicTransaction

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

the class AITMatrixImpl03 method set_value.

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

Example 5 with AtomicTransaction

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

the class CounterImpl0001 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 {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("CounterImpl0001.get: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException();
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("CounterImpl0001.get: " + exception);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

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