Search in sources :

Example 1 with RecoverableContainer

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

Example 2 with RecoverableContainer

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

Example 3 with RecoverableContainer

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

Example 4 with RecoverableContainer

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

Example 5 with RecoverableContainer

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;
}
Also used : RecoverableContainer(org.jboss.stm.internal.RecoverableContainer) PersistentContainer(org.jboss.stm.internal.PersistentContainer) OptimisticLockManagerProxy(org.jboss.stm.internal.proxy.OptimisticLockManagerProxy) LockManagerProxy(org.jboss.stm.internal.proxy.LockManagerProxy) OptimisticLockManagerProxy(org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)

Aggregations

RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)7 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)6 OptimisticLockManagerProxy (org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)2 PersistentContainer (org.jboss.stm.internal.PersistentContainer)1 LockManagerProxy (org.jboss.stm.internal.proxy.LockManagerProxy)1