Search in sources :

Example 71 with AtomicTransaction

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

the class AITCounterImpl01 method set.

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

Example 72 with AtomicTransaction

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

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

Example 73 with AtomicTransaction

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

the class Client19 method main.

public static void main(String[] args) {
    boolean correct = true;
    int numberOfCalls = 10;
    Counter counter = null;
    System.err.println("Starting first init");
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in first start: " + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("Starting first block");
    try {
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
        counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        for (int index = 0; index < numberOfCalls; index++) {
            AtomicTransaction atomicTransaction = new AtomicTransaction();
            atomicTransaction.begin();
            counter.increase(OTS.current().get_control());
            if ((index % 2) == 0) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
            }
        }
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        IntHolder value = new IntHolder();
        counter.get(value, OTS.current().get_control());
        atomicTransaction.commit(true);
        if (value.value == (numberOfCalls / 2) && correct) {
            correct = true;
        } else {
            correct = false;
        }
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in first block" + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("Starting first shutdown");
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in first shutdown" + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("----Starting second block -------");
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in second start " + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("init done starting second block");
    try {
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
        counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        counter.set(0, OTS.current().get_control());
        atomicTransaction.commit(true);
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in set operation " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        for (int index = 0; index < numberOfCalls; index++) {
            AtomicTransaction atomicTransaction = new AtomicTransaction();
            atomicTransaction.begin();
            counter.increase(OTS.current().get_control());
            if ((index % 2) == 0) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
            }
        }
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in second loop block " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        IntHolder value = new IntHolder();
        counter.get(value, OTS.current().get_control());
        atomicTransaction.commit(true);
        if (value.value == (numberOfCalls / 2) && correct) {
            correct = true;
        } else {
            correct = false;
        }
    } catch (Exception exception) {
        correct = false;
        System.err.println("exception in second test " + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("Starting second shutdown");
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        correct = false;
        System.err.println("error in second shutdown" + exception);
        exception.printStackTrace(System.err);
    }
    System.err.println("testing result");
    if (correct) {
        System.out.println("Passed");
    } else {
        System.out.println("Failed");
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Example 74 with AtomicTransaction

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

the class AITCounterImpl04 method increase.

public void increase(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++;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITCounterImpl04.increase: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITCounterImpl04.increase: " + 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.increase: " + 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 75 with AtomicTransaction

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

the class AITCounterImpl04 method get.

public void get(IntHolder 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.READ), super.waitTotalTimeout) == LockResult.GRANTED) {
                value.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.get: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITCounterImpl04.get: " + 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.get: " + 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

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