Search in sources :

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

Example 37 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) 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 38 with AtomicTransaction

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

the class Client02 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();
            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)) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client02.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client02.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Example 39 with AtomicTransaction

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

the class Client04 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        String counterIOR = ServerIORStore.loadIOR(args[args.length - 4]);
        Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
        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]);
        }
        for (int index = 0; index < 2; index++) {
            AtomicTransaction atomicTransaction = new AtomicTransaction();
            atomicTransaction.begin();
            counter.increase(OTS.current().get_control());
            if ((index % 2) == 0) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
            }
        }
        int clientMemory0 = (int) JVMStats.getMemory();
        int serverMemory0 = counter.getMemory();
        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();
            }
        }
        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);
        System.err.println("Server percentage memory increase: " + (float) (100.0 * serverMemoryIncrease) + "%");
        System.err.println("Server memory increase per call  : " + (serverMemory1 - serverMemory0) / numberOfCalls);
        if ((clientMemoryIncrease < clientIncreaseThreshold) && (serverMemoryIncrease < clientIncreaseThreshold)) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Client04.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Client04.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction)

Example 40 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();
        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)

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