Search in sources :

Example 1 with CheckedActionFactory

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

the class CoordinatorEnvironmentBean method getCheckedActionFactory.

/**
 * Returns an instance of a class implementing CheckedActionFactory.
 *
 * If there is no pre-instantiated instance set and classloading or instantiation fails,
 * this method will log appropriate warning and return null, not throw an exception.
 *
 * @return a CheckedActionFactory implementation instance, or null.
 */
public CheckedActionFactory getCheckedActionFactory() {
    if (checkedActionFactory == null && checkedActionFactoryClassName != null) {
        synchronized (this) {
            if (checkedActionFactory == null && checkedActionFactoryClassName != null) {
                CheckedActionFactory instance = ClassloadingUtility.loadAndInstantiateClass(CheckedActionFactory.class, checkedActionFactoryClassName, null);
                checkedActionFactory = instance;
            }
        }
    }
    return checkedActionFactory;
}
Also used : CheckedActionFactory(com.arjuna.ats.arjuna.coordinator.CheckedActionFactory)

Example 2 with CheckedActionFactory

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

the class CoordinatorEnvironmentBean method setCheckedActionFactory.

/**
 * Sets the instance of CheckedActionFactory.
 *
 * @param instance an Object that implements CheckedActionFactory, or null.
 */
public void setCheckedActionFactory(CheckedActionFactory instance) {
    synchronized (this) {
        if (checkedActionFactoryClassName == null || allowCheckedActionFactoryOverride) {
            CheckedActionFactory oldInstance = this.checkedActionFactory;
            checkedActionFactory = instance;
            if (instance == null) {
                this.checkedActionFactoryClassName = null;
            } else if (instance != oldInstance) {
                String name = ClassloadingUtility.getNameForClass(instance);
                this.checkedActionFactoryClassName = name;
            }
        }
    }
}
Also used : CheckedActionFactory(com.arjuna.ats.arjuna.coordinator.CheckedActionFactory)

Example 3 with CheckedActionFactory

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

the class CheckedActionTest method testCanChangeCheckedActionFactory.

@Test
public void testCanChangeCheckedActionFactory() {
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory1Called++;
                return null;
            }
        });
        arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(false);
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory3Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 0);
    assertTrue(factory3Called == 1);
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(false);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 0);
    assertTrue(factory3Called == 2);
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 1);
    assertTrue(factory3Called == 2);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) CheckedActionFactory(com.arjuna.ats.arjuna.coordinator.CheckedActionFactory) Test(org.junit.Test)

Example 4 with CheckedActionFactory

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

the class ThreadUtilTest method testDisassociateFromDifferentThread.

@Test
public void testDisassociateFromDifferentThread() throws InterruptedException {
    Thread thread = Thread.currentThread();
    AtomicBoolean called = new AtomicBoolean(false);
    CoordinatorEnvironmentBean coordinatorEnvironmentBean = arjPropertyManager.getCoordinatorEnvironmentBean();
    coordinatorEnvironmentBean.setAllowCheckedActionFactoryOverride(true);
    coordinatorEnvironmentBean.setCheckedActionFactory(new CheckedActionFactory() {

        @Override
        public CheckedAction getCheckedAction(Uid txId, String actionType) {
            return new CheckedAction() {

                public void check(boolean isCommit, Uid actUid, Hashtable list) {
                    called.set(true);
                }
            };
        }
    });
    AtomicAction tx = new AtomicAction();
    assertFalse(tx.removeChildThread(ThreadUtil.getThreadId(thread)));
    tx.begin();
    synchronized (tx) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                assertTrue(tx.removeChildThread(ThreadUtil.getThreadId(thread)));
                assertTrue(tx.end(true) == ActionStatus.COMMITTED);
                synchronized (tx) {
                    tx.notify();
                }
            }
        }).start();
        tx.wait();
    }
    assertTrue(called.get() == false);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) CheckedAction(com.arjuna.ats.arjuna.coordinator.CheckedAction) Hashtable(java.util.Hashtable) CoordinatorEnvironmentBean(com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean) CheckedActionFactory(com.arjuna.ats.arjuna.coordinator.CheckedActionFactory) Test(org.junit.Test)

Aggregations

CheckedActionFactory (com.arjuna.ats.arjuna.coordinator.CheckedActionFactory)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 Test (org.junit.Test)2 CoordinatorEnvironmentBean (com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean)1 CheckedAction (com.arjuna.ats.arjuna.coordinator.CheckedAction)1 Hashtable (java.util.Hashtable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1