Search in sources :

Example 6 with AtomicTransaction

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

the class AITMatrixImpl03 method set_value.

public void set_value(int x, int y, int value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
                try {
                    _values[x][y].set_value(value);
                    atomicTransaction.commit(true);
                } catch (InvocationException invocationException) {
                    atomicTransaction.rollback();
                    throw invocationException;
                }
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl03.set_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException(Reason.ReasonUnknown);
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITMatrixImpl03.set_value: " + exception);
        throw new InvocationException(Reason.ReasonUnknown);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 7 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();
                Control control = OTS.current().get_control();
                _matrix.get_value(x0, y0, srcValue, control);
                if (srcValue.value == 1) {
                    _matrix.get_value(x1, y1, dstValue, control);
                    if (dstValue.value == 0) {
                        _matrix.set_value(x0, y0, 0, control);
                        _matrix.set_value(x1, y1, 1, control);
                        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 : Control(org.omg.CosTransactions.Control) AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) IntHolder(org.omg.CORBA.IntHolder)

Example 8 with AtomicTransaction

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

the class AITExplicitObjectImpl01 method tran_commit_readlock.

public void tran_commit_readlock(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.READ), 0) == LockResult.GRANTED) {
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITExplicitObjectImpl01.tran_commit_readlock: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITExplicitObjectImpl01.tran_commit_readlock: " + 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("AITExplicitObjectImpl01.tran_commit_readlock: " + exception);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 9 with AtomicTransaction

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

the class AITExplicitObjectImpl01 method tran_rollback_readlock.

public void tran_rollback_readlock(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.READ), 0) == LockResult.GRANTED) {
                atomicTransaction.rollback();
            } else {
                atomicTransaction.rollback();
                throw new InvocationException();
            }
        } catch (InvocationException invocationException) {
            interposition.unregisterTransaction();
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITExplicitObjectImpl01.tran_rollback_readlock: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITExplicitObjectImpl01.tran_rollback_readlock: " + 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("AITExplicitObjectImpl01.tran_rollback_readlock: " + exception);
        throw new InvocationException();
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 10 with AtomicTransaction

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

the class AITExplicitObjectImpl01 method tran_commit_nulloper.

public void tran_commit_nulloper(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();
            atomicTransaction.commit(true);
        } catch (Exception exception) {
            System.err.println("AITExplicitObjectImpl01.tran_commit_nulloper: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            interposition.unregisterTransaction();
            throw new InvocationException();
        } catch (Error error) {
            System.err.println("AITExplicitObjectImpl01.tran_commit_nulloper: " + 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("AITExplicitObjectImpl01.tran_commit_nulloper: " + exception);
        throw new InvocationException();
    }
}
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