Search in sources :

Example 51 with AtomicTransaction

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

the class StackImple method push.

public int push(int val) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    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;
    }
    return res;
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 52 with AtomicTransaction

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

the class StackImple method pop.

public int pop(IntHolder val) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top > 0) {
                top--;
                val.value = array[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;
    }
    return res;
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 53 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();
            if ((index % 2) == 0) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
            }
        }
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        atomicTransaction.begin();
        IntHolder value = new IntHolder();
        counter.get(value);
        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 54 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();
            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();
            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 55 with AtomicTransaction

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

the class Client01 method operation.

private static boolean operation() throws Exception {
    boolean successful = false;
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            try {
                int x0 = Math.abs(_random.nextInt() % _matrixWidth);
                int y0 = Math.abs(_random.nextInt() % _matrixHeight);
                int x1 = Math.abs(_random.nextInt() % _matrixWidth);
                int y1 = Math.abs(_random.nextInt() % _matrixHeight);
                IntHolder srcValue = new IntHolder();
                IntHolder dstValue = new IntHolder();
                _matrix.get_value(x0, y0, srcValue);
                if (srcValue.value == 1) {
                    _matrix.get_value(x1, y1, dstValue);
                    if (dstValue.value == 0) {
                        _matrix.set_value(x0, y0, 0);
                        _matrix.set_value(x1, y1, 1);
                        successful = true;
                    }
                }
            } catch (InvocationException invocationException) {
                if (invocationException.myreason != Reason.ReasonConcurrencyControl) {
                    throw invocationException;
                }
            }
            if (successful) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
            }
        } catch (Exception exception) {
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw exception;
        }
    } catch (Exception exception) {
        System.err.println("Client01.operation: " + exception);
        exception.printStackTrace(System.err);
        throw exception;
    }
    return successful;
}
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