use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.
the class ComparisonUnitTest method testExampleSTM.
public void testExampleSTM() throws Exception {
RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
ExampleSTM basic = new ExampleSTM();
boolean success = true;
Atomic obj = null;
try {
obj = theContainer.enlist(basic);
} catch (final Throwable ex) {
ex.printStackTrace();
success = false;
}
assertTrue(success);
AtomicAction a = new AtomicAction();
a.begin();
obj.set(1234);
a.commit();
assertEquals(obj.get(), 1234);
a = new AtomicAction();
a.begin();
obj.incr(1);
a.abort();
assertEquals(obj.get(), 1234);
}
use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.
the class BasicIntUnitTest method testExampleSTM.
public void testExampleSTM() throws Exception {
RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
ExampleSTM basic = new ExampleSTM();
boolean success = true;
Atomic obj = null;
try {
obj = theContainer.enlist(basic);
} catch (final Throwable ex) {
ex.printStackTrace();
success = false;
}
assertTrue(success);
AtomicAction a = new AtomicAction();
a.begin();
obj.set(1234);
a.commit();
assertEquals(obj.get(), 1234);
a = new AtomicAction();
a.begin();
obj.change(1);
a.abort();
assertEquals(obj.get(), 1234);
}
use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.
the class ArrayIntUnitTest method testMultiArrayType.
public void testMultiArrayType() throws Exception {
RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
ArrayType basic = new ArrayType();
boolean success = true;
Atomic obj = null;
// arbitrary value
int index = 5;
try {
obj = theContainer.enlist(basic);
} catch (final Throwable ex) {
ex.printStackTrace();
success = false;
}
assertTrue(success);
AtomicAction a = new AtomicAction();
a.begin();
obj.set(index, 1234);
a.commit();
assertEquals(obj.get(index), 1234);
a = new AtomicAction();
a.begin();
obj.change(index, 1);
a.abort();
assertEquals(obj.get(index), 1234);
}
use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.
the class ArrayIntUnitTest method testArrayType.
public void testArrayType() throws Exception {
RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
ArrayType basic = new ArrayType();
boolean success = true;
Atomic obj = null;
// arbitrary value
int index = 5;
try {
obj = theContainer.enlist(basic);
} catch (final Throwable ex) {
ex.printStackTrace();
success = false;
}
assertTrue(success);
AtomicAction a = new AtomicAction();
a.begin();
obj.set(index, 1234);
a.commit();
assertEquals(obj.get(index), 1234);
a = new AtomicAction();
a.begin();
obj.change(index, 1);
a.abort();
assertEquals(obj.get(index), 1234);
}
use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.
the class Container method getContainer.
/**
* Given the proxy return the container that is managing it.
*
* @param proxy the instance within the container we're looking for.
* @return the container or null. Shouldn't really be possible to get null!
*/
public static final Container<?> getContainer(Object proxy) {
/*
* Rather than maintain a list of Container instances and iterate through them
* we create a clone of the Container using the real container within the
* proxy itself. Container is essentially a (almost) stateless wrapper class
* anyway so hopefully this is a lightweight and faster way of achieving this.
* Can revisit later if this creates too many instances.
*/
Container<?> toReturn = null;
if (proxy instanceof OptimisticLockManagerProxy<?>) {
RecoverableContainer<?> cont = ((OptimisticLockManagerProxy<?>) proxy).getContainer();
toReturn = new Container(cont);
} else {
if (proxy instanceof LockManagerProxy<?>) {
RecoverableContainer<?> cont = ((LockManagerProxy<?>) proxy).getContainer();
toReturn = new Container(cont);
} else
throw new IllegalArgumentException("Not a proxy object!");
}
return toReturn;
}
Aggregations