Search in sources :

Example 6 with ExplicitInterposition

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

the class ExplicitStackImple method pop.

public int pop(IntHolder 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 pop interposed transaction: " + name);
    name = null;
    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;
    }
    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 7 with ExplicitInterposition

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

the class setget_i method set.

public void set(short n, Control control) throws SystemException {
    System.out.println("setget_i.set " + n);
    try {
        if (control != null) {
            ExplicitInterposition manager = new ExplicitInterposition();
            manager.registerTransaction(control);
            System.out.println("setget_i.set - managed to set up interposition hierarchy");
            CurrentImple current = OTSImpleManager.current();
            Control cont = current.get_control();
            if (cont == null)
                System.err.println("setget_i.set error - current returned no control!");
            else {
                System.out.println("setget_i.set - current returned a control!");
                cont = null;
            }
            System.out.println("setget_i.set - beginning nested action");
            current.begin();
            cont = current.get_control();
            if (cont != null) {
                Coordinator coord = cont.get_coordinator();
                System.out.println("setget_i.set - registering self");
                coord.register_resource(ref);
                coord = null;
                cont = null;
            } else
                System.err.println("setget_i.set - current did not return control after begin!");
            value = n;
            System.out.println("setget_i.set - committing nested action");
            current.commit(true);
            manager.unregisterTransaction();
            manager = null;
        } else
            System.err.println("setget_i::set error - no control!");
    } catch (InterpositionFailed ex) {
        System.err.println("setget_i.set - error in setting up hierarchy");
        throw new UNKNOWN();
    } catch (Throwable e) {
        System.err.println("setget_i::set - caught exception: " + e);
    }
    System.out.println("setget_i.set - finished");
}
Also used : Control(org.omg.CosTransactions.Control) InterpositionFailed(com.arjuna.ArjunaOTS.InterpositionFailed) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) UNKNOWN(org.omg.CORBA.UNKNOWN) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) Coordinator(org.omg.CosTransactions.Coordinator)

Example 8 with ExplicitInterposition

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

the class HammerObject method set.

public boolean set(int value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.set - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            _value = value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.set: " + e);
        res = false;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Aggregations

ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)8 Lock (com.arjuna.ats.txoj.Lock)5 IOException (java.io.IOException)5 SystemException (org.omg.CORBA.SystemException)5 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)4 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)2 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)1 ExplicitStackImple (com.hp.mwtests.ts.jts.orbspecific.resources.ExplicitStackImple)1 Transaction (javax.transaction.Transaction)1 Test (org.junit.Test)1 UNKNOWN (org.omg.CORBA.UNKNOWN)1 Control (org.omg.CosTransactions.Control)1 Coordinator (org.omg.CosTransactions.Coordinator)1