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;
}
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;
}
}
}
}
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);
}
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);
}
Aggregations