use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObject method get.
public int get() throws TestException {
AtomicAction A = new AtomicAction();
int value = -1;
A.begin();
if (setlock(new Lock(LockMode.READ), retry) == LockResult.GRANTED) {
value = state;
if (A.commit() == ActionStatus.COMMITTED)
return value;
else
throw new TestException("Action commit error.");
} else {
if (printDebug)
System.out.println("Error - could not set read lock.");
}
A.abort();
throw new TestException("Read lock error.");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObject method set.
public void set(int value) throws TestException {
AtomicAction A = new AtomicAction();
A.begin();
if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED) {
state = value;
if (A.commit() != ActionStatus.COMMITTED)
throw new TestException("Action commit error.");
else
return;
} else {
if (printDebug)
System.out.println("Error - could not set write lock.");
}
A.abort();
throw new TestException("Write lock error.");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class SampleVerticle2 method start.
public void start() {
LocalMap<String, String> map = vertx.sharedData().getLocalMap("demo.mymap");
Container<Sample> theContainer = new Container<>("Demo", Container.TYPE.PERSISTENT, Container.MODEL.SHARED);
String uidName = map.get(ClientVerticle.LEADER);
Sample obj1 = theContainer.clone(new SampleLockable(10), new Uid(uidName));
AtomicAction A = new AtomicAction();
int value = -1;
int initialValue = -1;
boolean shouldCommit = true;
A.begin();
try {
initialValue = obj1.value();
obj1.increment();
} catch (final Throwable ex) {
ex.printStackTrace();
shouldCommit = false;
}
try {
if (shouldCommit) {
obj1.increment();
value = obj1.value();
}
} catch (final Throwable ex) {
ex.printStackTrace();
shouldCommit = false;
}
if (shouldCommit)
A.commit();
else {
A.abort();
value = -1;
}
System.err.println("SampleVerticle2 initialised state with: " + value);
if (value == initialValue + 2)
System.err.println("SampleVerticle2 SUCCEEDED!");
else
System.err.println("SampleVerticle2 FAILED!");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class ReactivateUnitTest method test.
@Test
public void test() {
try {
AtomicObject obj = new AtomicObject();
Uid objRef = obj.get_uid();
AtomicAction A = new AtomicAction();
A.begin();
obj.set(1234);
A.commit();
AtomicObject recObj = new AtomicObject(objRef);
AtomicAction B = new AtomicAction();
B.begin();
assertEquals(1234, recObj.get());
B.abort();
} catch (Exception ex) {
fail(ex.toString());
}
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObject method set.
public void set(int value) throws TestException {
AtomicAction A = new AtomicAction();
A.begin();
if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED) {
state = value;
if (A.commit() != ActionStatus.COMMITTED)
throw new TestException("Action commit error.");
else
return;
} else {
if (printDebug)
System.out.println("Error - could not set write lock.");
}
A.abort();
throw new TestException("Write lock error.");
}
Aggregations