use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class TransactionLog method getStatus.
public int getStatus(Uid uid) {
AtomicAction action = new AtomicAction(uid);
action.activate();
return action.status();
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class ExampleXAResource method recover.
/**
* @param param1 <description>
* @return <description>
* @throws javax.transaction.xa.XAException
* <description>
*/
public Xid[] recover(int flag) throws XAException {
myLog("recover");
Xid[] xids = new Xid[2];
if (ExampleXAResource.toRecover == null) {
AtomicAction a = new AtomicAction();
ExampleXAResource.toRecover = new XidImple(new AtomicAction());
}
xids[0] = ExampleXAResource.toRecover;
xids[1] = new XidImple(new AtomicAction());
return xids;
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class EchoClient method start.
@Override
public void start() throws Exception {
vertx.createNetClient().connect(1234, "localhost", res -> {
if (res.succeeded()) {
NetSocket socket = res.result();
socket.handler(buffer -> {
System.out.println("Net client receiving: " + buffer.toString("UTF-8"));
});
// Now send some data
for (int i = 0; i < 10; i++) {
String str = "hello " + i + "\n";
System.out.println("Net client sending: " + str);
socket.write(str);
}
/*
* If you are running this for the first time then leave as is.
* If you are running this more than once and want clients to share the STM objects between
* address spaces then go into the ObjectStore dir and look for the Uid that represents the state
* you want to share. Then uncomment the Uid line below and replace the Uid in quotes with the Uid
* you have selected. Uncomment the other obj1 creation line and comment out the original.
*
* If you want to see how this might work then just go with the example state in the ObjectStore
* shipped as part of this example and uncomment the lines.
*/
/*
* STM states are identified by Uids in the ObjectStore. This is an example.
*/
// Modify this line if sharing state and uncomment.
// Uid u = new Uid("0:ffffc0a80003:c915:529f59de:1");
Container<Sample> theContainer = new Container<Sample>("Demo", Container.TYPE.PERSISTENT, Container.MODEL.SHARED);
// Modify this line if sharing state and uncomment.
// Sample obj1 = theContainer.clone(new SampleLockable(10), u);
Sample obj1 = theContainer.create(new SampleLockable(10));
System.out.println("Object name: " + theContainer.getIdentifier(obj1));
// Now send some data
for (int i = 0; i < 10; i++) {
AtomicAction A = new AtomicAction();
A.begin();
obj1.increment();
String str = "hello" + obj1.value() + "\n";
System.out.print("Net client sending: " + str);
socket.write(str);
A.commit();
}
} else {
System.out.println("Failed to connect " + res.cause());
}
});
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class BasicUnitTest method testExampleSTM.
@Test
public void testExampleSTM() throws Exception {
/*
* Create the container for the Transactional interface.
*/
Container<Atomic> theContainer = new Container<Atomic>();
/*
* Create the instance of the class. But this won't be an STM object yet, so don't
* manipulate it just yet.
*/
ExampleSTM basic = new ExampleSTM();
boolean success = true;
/*
* This object will be the one we actually use.
*/
Atomic obj = null;
try {
/*
* Pass the instance we created previously to the Container so it
* can then create an STM object which we then use to manipulate
* the first object in a transactional manner.
*/
obj = theContainer.create(basic);
} catch (final Throwable ex) {
ex.printStackTrace();
success = false;
}
assertTrue(success);
// a transaction!
AtomicAction a = new AtomicAction();
a.begin();
obj.set(1234);
a.commit();
assertEquals(obj.get(), 1234);
a = new AtomicAction();
a.begin();
// the value at this stage will be 1235
obj.change(1);
a.abort();
// we aborted, so the value should be back to 1234
assertEquals(obj.get(), 1234);
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class HammerThreadedObject method run.
public void run() {
for (int i = 0; i < HammerThreadedObject.iter; i++) {
AtomicAction A = new AtomicAction();
float f = HammerThreadedObject.rand.nextFloat();
try {
Thread.yield();
try {
Thread.sleep((int) HammerThreadedObject.rand.nextFloat() * 1000);
} catch (InterruptedException e) {
}
A.begin();
int v = HammerThreadedObject.object.get();
if (f > 0.25)
System.out.println(_uid + ": atomic object value: " + v);
else {
int nv = v + _value;
HammerThreadedObject.object.set(nv);
System.out.println(_uid + ": atomic object value set to : " + nv);
}
A.commit();
try {
Thread.sleep((int) HammerThreadedObject.rand.nextFloat() * 1000);
} catch (InterruptedException e) {
}
} catch (TestException e) {
System.out.println(_uid + ": AtomicObject exception raised: " + e);
A.abort();
Thread.yield();
}
}
}
Aggregations