Search in sources :

Example 46 with AtomicTransaction

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

the class AITCounterImpl01 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), 0) == 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("AITCounterImpl01.increase: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITCounterImpl01.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("AITCounterImpl01.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 47 with AtomicTransaction

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

the class AITPingPongImpl01 method bad_hit.

public void bad_hit(int count, int bad_count, PingPong ponger, PingPong pinger, 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 (count != 0) {
                ponger.bad_hit(count - 1, bad_count - 1, pinger, ponger, OTS.current().get_control());
                if (bad_count != 0) {
                    atomicTransaction.commit(true);
                } else {
                    atomicTransaction.rollback();
                }
            } else if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
                _value++;
                if (bad_count != 0) {
                    atomicTransaction.commit(true);
                } else {
                    atomicTransaction.rollback();
                }
            } else {
                System.err.println("AITPingPongImpl01.bad_hit: failed to get lock");
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITPingPongImpl01.bad_hit: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITPingPongImpl01.bad_hit: " + 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("AITPingPongImpl01.bad_hit: " + exception);
        throw new InvocationException();
    } catch (Error error) {
        System.err.println("AITPingPongImpl01.bad_hit: " + error);
        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 48 with AtomicTransaction

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

the class Client17 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 5]);
        Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        int numberOfWorkers = Integer.parseInt(args[args.length - 4]);
        int numberOfCalls = Integer.parseInt(args[args.length - 3]);
        float clientIncreaseThreshold;
        float serverIncreaseThreshold;
        // If no threshold value then use default.
        if (MemoryTestProfileStore.getNoThresholdValue().equals(args[args.length - 2])) {
            clientIncreaseThreshold = Float.parseFloat(MemoryTestProfileStore.getDefaultClientIncreaseThreshold());
        } else // Use passed threshold
        {
            clientIncreaseThreshold = Float.parseFloat(args[args.length - 2]);
        }
        // If no threshold value then use default.
        if (MemoryTestProfileStore.getNoThresholdValue().equals(args[args.length - 1])) {
            serverIncreaseThreshold = Float.parseFloat(MemoryTestProfileStore.getDefaultServerIncreaseThreshold());
        } else // Use passed threshold
        {
            serverIncreaseThreshold = Float.parseFloat(args[args.length - 1]);
        }
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        counter.increase(OTS.current().get_control());
        atomicTransaction.commit(true);
        int clientMemory0 = (int) JVMStats.getMemory();
        int serverMemory0 = counter.getMemory();
        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();
            workers[index] = null;
        }
        workers = null;
        int clientMemory1 = (int) JVMStats.getMemory();
        int serverMemory1 = counter.getMemory();
        float clientMemoryIncrease = ((float) (clientMemory1 - clientMemory0)) / ((float) clientMemory0);
        float serverMemoryIncrease = ((float) (serverMemory1 - serverMemory0)) / ((float) serverMemory0);
        System.err.println("Client memory increase threshold : " + (float) (100.0 * clientIncreaseThreshold) + "%");
        System.err.println("Server memory increase threshold : " + (float) (100.0 * serverIncreaseThreshold) + "%");
        System.err.println("Client percentage memory increase: " + (float) (100.0 * clientMemoryIncrease) + "%");
        System.err.println("Client memory increase per call  : " + (clientMemory1 - clientMemory0) / (numberOfCalls * numberOfWorkers));
        System.err.println("Server percentage memory increase: " + (float) (100.0 * serverMemoryIncrease) + "%");
        System.err.println("Server memory increase per call  : " + (serverMemory1 - serverMemory0) / (numberOfCalls * numberOfWorkers));
        if ((clientMemoryIncrease < clientIncreaseThreshold) && (serverMemoryIncrease < serverIncreaseThreshold)) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client17.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client17.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction)

Example 49 with AtomicTransaction

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

the class ExplicitStackImple method push.

public int push(int val, Control action) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(action);
    } catch (Exception e) {
        System.err.println("WARNING ExplicitStackImple::push - could not create interposition.");
        return -1;
    }
    String name = OTSImpleManager.current().get_transaction_name();
    System.out.println("Created push interposed transaction: " + name);
    name = null;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top < ARRAY_SIZE) {
                array[top] = val;
                top++;
            } else
                res = -1;
            if (res == 0) {
                A.commit(false);
            } else
                A.rollback();
        } else
            A.rollback();
    } catch (Exception e1) {
        try {
            A.rollback();
        } catch (Exception e2) {
            System.err.println(e2);
        }
        res = -1;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 50 with AtomicTransaction

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

the class ExplicitStackImple method printStack.

public void printStack() throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top > 0) {
                System.out.println("\nContents of stack:");
                for (int i = 0; i < top; i++) System.out.println("\t" + array[i]);
            } else
                System.out.println("\nStack is empty.");
            A.commit(false);
        } else {
            System.out.println("printStack: could not set WRITE lock.");
            A.rollback();
        }
    } catch (Exception e1) {
        try {
            A.rollback();
        } catch (Exception e2) {
            System.err.println(e2);
        }
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) 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