Search in sources :

Example 1 with AtomicAction

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();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 2 with AtomicAction

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;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Xid(javax.transaction.xa.Xid)

Example 3 with AtomicAction

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());
        }
    });
}
Also used : NetSocket(io.vertx.core.net.NetSocket) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Container(org.jboss.stm.Container)

Example 4 with AtomicAction

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);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Container(org.jboss.stm.Container) Test(org.junit.Test)

Example 5 with AtomicAction

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();
        }
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Aggregations

AtomicAction (com.arjuna.ats.arjuna.AtomicAction)179 Test (org.junit.Test)73 Uid (com.arjuna.ats.arjuna.common.Uid)31 TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)30 AtomicObject (com.hp.mwtests.ts.txoj.common.resources.AtomicObject)18 Lock (com.arjuna.ats.txoj.Lock)17 RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7 PrintWriter (java.io.PrintWriter)7 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)5 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)5 Container (org.jboss.stm.Container)5 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)4 BasicRecord (com.hp.mwtests.ts.arjuna.resources.BasicRecord)4 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)3 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)3 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)3 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)3 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)3 EditableAtomicAction (com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction)3