Search in sources :

Example 6 with TransactionReaper

use of com.arjuna.ats.arjuna.coordinator.TransactionReaper in project narayana by jbosstm.

the class ReaperTestCase3 method testReaperWait.

@Test
public void testReaperWait() throws Exception {
    TransactionReaper reaper = TransactionReaper.transactionReaper();
    // give the reaper worker time to start too
    Thread.sleep(1000);
    // create test reapables some of which will not respond immediately to cancel requests
    Uid uid0 = new Uid();
    Uid uid1 = new Uid();
    Uid uid2 = new Uid();
    Uid uid3 = new Uid();
    // reapable0 will return CANCELLED from cancel and will rendezvous inside the cancel call
    // so we can delay it. prevent_commit should not get called so we don't care about the arguments
    TestReapable reapable0 = new TestReapable(uid0, true, false, false, false);
    // reapable1 will return CANCELLED from cancel and will not rendezvous inside the cancel call
    // prevent_commit should not get called so we don't care about the arguments
    TestReapable reapable1 = new TestReapable(uid1, true, false, false, false);
    // reapable2 will return CANCELLED from cancel and will not rendezvous inside the cancel call
    // prevent_commit should not get called so we don't care about the arguments
    TestReapable reapable2 = new TestReapable(uid2, true, false, false, false);
    // reapable3 will return CANCELLED from cancel and will not rendezvous inside the cancel call
    // prevent_commit should not get called so we don't care about the arguments
    TestReapable reapable3 = new TestReapable(uid3, true, false, false, false);
    // enable a repeatable rendezvous before checking the reapable queue
    enableRendezvous("reaper1", true);
    // enable a repeatable rendezvous before processing a timed out reapable
    // enableRendezvous("reaper2", true);
    // enable a repeatable rendezvous before scheduling a reapable in the worker queue for cancellation
    // enableRendezvous("reaper3", true);
    // enable a repeatable rendezvous before rescheduling a reapable in the worker queue for cancellation
    // enableRendezvous("reaper4", true);
    // enable a repeatable rendezvous before interrupting a cancelled reapable
    // enableRendezvous("reaper5", true);
    // enable a repeatable rendezvous before marking a worker thread as a zombie
    // enableRendezvous("reaper6", true);
    // enable a repeatable rendezvous before marking a reapable as rollback only from the reaper thread
    // enableRendezvous("reaper7", true);
    // enable a repeatable rendezvous before checking the worker queue
    enableRendezvous("reaperworker1", true);
    // enable a repeatable rendezvous before marking a reapable as cancel
    // enableRendezvous("reaperworker2", true);
    // enable a repeatable rendezvous before calling cancel
    // enableRendezvous("reaperworker3", true);
    // enable a repeatable rendezvous before marking a reapable as rollback only from the worker thread
    // enableRendezvous("reaperworker4", true);
    // enable a repeatable rendezvous for each of the test reapables which we have marked to
    // perform a rendezvous
    // enableRendezvous(uid0, true);
    // insert reapables so they timeout at 1 second intervals then
    // check progress of cancellations and rollbacks
    reaper.insert(reapable0, 1);
    reaper.insert(reapable1, 2);
    reaper.insert(reapable2, 3);
    reaper.insert(reapable3, 4);
    // latch the reaper before it checks the queue
    triggerRendezvous("reaper1");
    // make sure they were all registered
    assertEquals(4, reaper.numberOfTransactions());
    assertEquals(4, reaper.numberOfTimeouts());
    // ensure the first reapable is ready
    triggerWait(1000);
    // let the reaper process the first reapable then latch it again before it checks the queue
    triggerRendezvous("reaper1");
    triggerRendezvous("reaper1");
    // latch the worker before it checks the worker queue
    triggerRendezvous("reaperworker1");
    // let the worker process the first reapable then latch it again before it checks the queue
    triggerRendezvous("reaperworker1");
    triggerRendezvous("reaperworker1");
    // force a termination waiting for the normal timeout periods
    // byteman rules will ensure that the reaper and reaperworker rendezvous get deleted
    // under this call
    TransactionReaper.terminate(true);
    assertEquals(0, reaper.numberOfTransactions());
    assertTrue(reapable0.getCancelTried());
    assertTrue(reapable1.getCancelTried());
    assertTrue(reapable2.getCancelTried());
    assertTrue(reapable3.getCancelTried());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) Test(org.junit.Test)

Example 7 with TransactionReaper

use of com.arjuna.ats.arjuna.coordinator.TransactionReaper in project narayana by jbosstm.

the class ServerFactory method create_transaction.

public static ServerControl create_transaction(Uid u, Control parentControl, ArjunaTransactionImple parentImpl, Coordinator realCoord, Terminator realTerm, int time_out) {
    ServerControl tranControl = new ServerControl(u, parentControl, parentImpl, realCoord, realTerm);
    if ((time_out != 0) && (parentImpl == null)) {
        TransactionReaper reaper = TransactionReaper.transactionReaper();
        reaper.insert(new ServerControlWrapper((ControlImple) tranControl), time_out);
    }
    return tranControl;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Example 8 with TransactionReaper

use of com.arjuna.ats.arjuna.coordinator.TransactionReaper in project narayana by jbosstm.

the class TransactionFactoryImple method getGlobalInfo.

/*
	 * @return information on the transactions known by this object.
	 * 
	 * @since JTS 2.1.
	 */
public GlobalTransactionInfo getGlobalInfo() throws SystemException {
    GlobalTransactionInfo info = new GlobalTransactionInfo();
    info.totalNumberOfTransactions = (int) com.arjuna.ats.arjuna.coordinator.TxStats.getInstance().getNumberOfTransactions();
    info.numberOfCommittedTransactions = (int) com.arjuna.ats.arjuna.coordinator.TxStats.getInstance().getNumberOfCommittedTransactions();
    info.numberOfAbortedTransactions = (int) com.arjuna.ats.arjuna.coordinator.TxStats.getInstance().getNumberOfAbortedTransactions();
    if (info.totalNumberOfTransactions > 0)
        info.averageLifetime = (float) (TransactionReaper.transactionLifetime() / info.totalNumberOfTransactions);
    else
        info.averageLifetime = (float) 0.0;
    info.numberOfHeuristics = (int) com.arjuna.ats.arjuna.coordinator.TxStats.getInstance().getNumberOfHeuristics();
    TransactionReaper reaper = TransactionReaper.transactionReaper();
    if (reaper.checkingPeriod() == Long.MAX_VALUE)
        info.reaperTimeout = 0;
    else
        info.reaperTimeout = (int) reaper.checkingPeriod();
    info.defaultTimeout = TxControl.getDefaultTimeout();
    return info;
}
Also used : TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) GlobalTransactionInfo(com.arjuna.ArjunaOTS.GlobalTransactionInfo)

Example 9 with TransactionReaper

use of com.arjuna.ats.arjuna.coordinator.TransactionReaper in project narayana by jbosstm.

the class TransactionFactoryImple method getTransactionInfo.

/**
 * @return information on a specific transaction.
 * @since JTS 2.1.2.
 */
public TransactionInfo getTransactionInfo(Uid u) throws org.omg.CosTransactions.NoTransaction, SystemException {
    if (!u.valid())
        throw new BAD_PARAM(jtsLogger.i18NLogger.get_orbspecific_invaliduid() + " " + u);
    else {
        try {
            synchronized (ControlImple.allControls) {
                ControlImple ctx = (ControlImple) ControlImple.allControls.get(u);
                if (ctx != null) {
                    TransactionInfo info = new TransactionInfo();
                    info.currentDepth = ctx.getImplHandle().getHierarchy().depth();
                    TransactionReaper reaper = TransactionReaper.transactionReaper();
                    info.timeout = reaper.getTimeout(ctx);
                    info.numberOfThreads = ctx.getImplHandle().activeThreads();
                    return info;
                } else
                    throw new NoTransaction();
            }
        } catch (NoTransaction ex) {
            throw ex;
        } catch (Exception e) {
            e.printStackTrace();
            throw new UNKNOWN();
        }
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) BAD_PARAM(org.omg.CORBA.BAD_PARAM) TransactionInfo(com.arjuna.ArjunaOTS.TransactionInfo) GlobalTransactionInfo(com.arjuna.ArjunaOTS.GlobalTransactionInfo) UNKNOWN(org.omg.CORBA.UNKNOWN) TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) SystemException(org.omg.CORBA.SystemException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Aggregations

TransactionReaper (com.arjuna.ats.arjuna.coordinator.TransactionReaper)9 Test (org.junit.Test)5 Uid (com.arjuna.ats.arjuna.common.Uid)4 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 TransactionInfo (com.arjuna.ArjunaOTS.TransactionInfo)1 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 Reapable (com.arjuna.ats.arjuna.coordinator.Reapable)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 ReaperElement (com.arjuna.ats.internal.arjuna.coordinator.ReaperElement)1 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 BAD_PARAM (org.omg.CORBA.BAD_PARAM)1 NO_MEMORY (org.omg.CORBA.NO_MEMORY)1 SystemException (org.omg.CORBA.SystemException)1 UNKNOWN (org.omg.CORBA.UNKNOWN)1 NoTransaction (org.omg.CosTransactions.NoTransaction)1