Search in sources :

Example 1 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class OutboundBridge method start.

/**
 * Associate the WS-AT transaction to the current Thread.
 * Typically used by the client side outbound handler.
 *
 * @throws UnknownTransactionException
 * @throws SystemException
 */
public void start() throws UnknownTransactionException, SystemException {
    txbridgeLogger.logger.trace("OutboundBridge.start(BridgeWrapper=" + bridgeWrapper + ")");
    TxContext txContext = bridgeWrapper.getContext();
    TransactionManagerFactory.transactionManager().resume(txContext);
}
Also used : TxContext(com.arjuna.mw.wst.TxContext)

Example 2 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class UserTransactionImple method beginSubordinate.

/**
 * method provided for the benefit of UserSubordinateTransactionImple to allow it
 * to begin a subordinate transaction which requires an existing context to be
 * installed on the thread before it will start and instal la new transaction
 *
 * @param timeout
 * @throws WrongStateException
 * @throws SystemException
 */
public void beginSubordinate(int timeout) throws WrongStateException, SystemException {
    try {
        TxContext current = _ctxManager.currentTransaction();
        if ((current == null) || !(current instanceof TxContextImple))
            throw new WrongStateException();
        TxContextImple currentImple = (TxContextImple) current;
        Context ctx = startTransaction(timeout, currentImple);
        _ctxManager.resume(new TxContextImple(ctx));
    // n.b. we don't enlist the subordinate transaction for completion
    // that ensures that any attempt to commit or rollback will fail
    } catch (com.arjuna.wsc.InvalidCreateParametersException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (com.arjuna.wst.UnknownTransactionException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (SystemException ex) {
        tidyup();
        throw ex;
    }
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) Context(com.arjuna.mw.wsc11.context.Context) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) WrongStateException(com.arjuna.wst.WrongStateException) TxContext(com.arjuna.mw.wst.TxContext) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple)

Example 3 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class SubordinateImporter method importContext.

public static TxContext importContext(CoordinationContextType cc) {
    // get the subordinate transaction manager to install any existing
    // subordinate tx for this one or create and install a new one.
    final String identifier = cc.getIdentifier().getValue();
    TxContext subordinateTxContext = subordinateContextMap.get(identifier);
    if (subordinateTxContext == null) {
        // create a context for a local coordinator
        CoordinationContext context = null;
        try {
            context = atContextFactory.create(AtomicTransactionConstants.WSAT_PROTOCOL, 0L, cc, false);
        } catch (InvalidCreateParametersException e) {
        // should not happen
        }
        subordinateTxContext = new TxContextImple(context);
        subordinateContextMap.put(identifier, subordinateTxContext);
        // register a cleanup callback with the subordinate transactionso that the entry gets removed
        // when the transcation commits or rolls back
        // remove "urn:" prefix
        String subordinateId = context.getIdentifier().getValue().substring(4);
        SubordinateATCoordinator.SubordinateCallback callback = new SubordinateATCoordinator.SubordinateCallback() {

            public String parentId = identifier;

            public void run() {
                subordinateContextMap.remove(parentId);
            }
        };
        SubordinateATCoordinator.addCallback(subordinateId, callback);
    }
    return subordinateTxContext;
}
Also used : SubordinateATCoordinator(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator) TxContext(com.arjuna.mw.wst.TxContext) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)

Example 4 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class SubtransactionCommitRollbackInPrepareTest method testSubTransactionCommitRollbackInPrepare.

@Test
public void testSubTransactionCommitRollbackInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    try {
        ut.commit();
        fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException trbe) {
    // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Example 5 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class SubtransactionRollbackTest method testSubTransactionRollback.

@Test
public void testSubTransactionRollback() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final DemoDurableParticipant p3 = new DemoDurableParticipant();
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, p3.identifier());
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    ut.rollback();
    assertTrue(p1.resolved() && !p1.passed());
    assertTrue(p2.resolved() && !p2.passed());
    assertTrue(p3.resolved() && !p3.passed());
    assertTrue(p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Aggregations

TxContext (com.arjuna.mw.wst.TxContext)20 TransactionManager (com.arjuna.mw.wst11.TransactionManager)11 Test (org.junit.Test)10 UserTransaction (com.arjuna.mw.wst11.UserTransaction)9 DemoDurableParticipant (com.arjuna.wstx.tests.common.DemoDurableParticipant)6 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)5 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)4 DemoVolatileParticipant (com.arjuna.wstx.tests.common.DemoVolatileParticipant)4 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)4 Context (com.arjuna.mw.wsc11.context.Context)3 SystemException (com.arjuna.wst.SystemException)3 WrongStateException (com.arjuna.wst.WrongStateException)3 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)3 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)2 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)2 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)2 FailureParticipant (com.arjuna.wstx.tests.common.FailureParticipant)2 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)2 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)2 com.arjuna.mw.wst11 (com.arjuna.mw.wst11)1