Search in sources :

Example 91 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class JtsTransactionImple method createControlWrapper.

private static ControlWrapper createControlWrapper(String ior) {
    org.omg.CORBA.Object obj = ORBManager.getORB().orb().string_to_object(ior);
    Control control = org.omg.CosTransactions.ControlHelper.narrow(obj);
    if (control == null)
        log.warn("createProxy: ior not a control");
    return new ControlWrapper(control);
}
Also used : Control(org.omg.CosTransactions.Control) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper)

Example 92 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class Test20 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        boolean correct = true;
        int numberOfControls = 1000;
        Current current = OTS.get_current();
        String[] transactionNames = new String[numberOfControls];
        Control[] controls = new Control[numberOfControls];
        for (int index = 0; index < numberOfControls; index++) {
            current.begin();
            transactionNames[index] = current.get_transaction_name();
            controls[index] = current.suspend();
        }
        for (int index = 0; index < numberOfControls; index++) {
            current.resume(controls[index]);
            correct = correct && transactionNames[index].equals(current.get_transaction_name());
            current.commit(true);
        }
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Test20.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Test20.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) Current(org.omg.CosTransactions.Current)

Example 93 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class Client02 method operation.

private static boolean operation() throws Exception {
    boolean successful = false;
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            try {
                int d = Math.abs(_random.nextInt() % 10) + 1;
                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 location0Value = new IntHolder();
                IntHolder location1Value = new IntHolder();
                Control control = OTS.current().get_control();
                _matrix.get_value(x0, y0, location0Value, control);
                _matrix.get_value(x1, y1, location1Value, control);
                _matrix.set_value(x0, y0, location1Value.value + d, control);
                _matrix.set_value(x1, y1, location0Value.value - d, control);
                successful = (x0 != x1) || (y0 != y1);
            } 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("Client02.operation: " + exception);
        exception.printStackTrace(System.err);
        throw exception;
    }
    return successful;
}
Also used : Control(org.omg.CosTransactions.Control) AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Example 94 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class Test21 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        boolean correct = true;
        Current current = OTS.get_current();
        Control control = current.suspend();
        correct = (control == null);
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Test21.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Test21.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) Current(org.omg.CosTransactions.Current)

Example 95 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class Test27 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        boolean correct = true;
        Current current = OTS.get_current();
        current.begin();
        Control control = current.get_control();
        current.commit(false);
        try {
            current.resume(control);
        } catch (InvalidControl invalidControl) {
            System.err.println("Failed to resume committed transaction!");
            correct = false;
        }
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Test27.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Testt27.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) InvalidControl(org.omg.CosTransactions.InvalidControl) Current(org.omg.CosTransactions.Current) InvalidControl(org.omg.CosTransactions.InvalidControl)

Aggregations

Control (org.omg.CosTransactions.Control)103 Test (org.junit.Test)40 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)24 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)20 ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)18 TransactionFactory (org.omg.CosTransactions.TransactionFactory)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)14 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)13 Coordinator (org.omg.CosTransactions.Coordinator)13 SystemException (org.omg.CORBA.SystemException)11 IntHolder (org.omg.CORBA.IntHolder)10 Current (org.omg.CosTransactions.Current)9 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)6 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)6 Services (com.arjuna.orbportability.Services)6 PropagationContext (org.omg.CosTransactions.PropagationContext)6 ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5