Search in sources :

Example 21 with Transaction

use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.

the class SimpleOpenWireTest method testXAResourceCommitSuspendedNotRemoved.

@Test
public void testXAResourceCommitSuspendedNotRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        session.getXAResource().end(xid, XAResource.TMSUSPEND);
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        // amq5.x doesn't pass suspend flags to broker,
        // directly suspend the tx
        transaction.suspend();
        session.getXAResource().commit(xid, true);
    } catch (XAException ex) {
    // ignore
    } finally {
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        assertNotNull(transaction);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 22 with Transaction

use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.

the class SimpleOpenWireTest method testXAResourceCommittedRemoved.

@Test
public void testXAResourceCommittedRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("xa message"));
        session.getXAResource().end(xid, XAResource.TMSUCCESS);
        session.getXAResource().commit(xid, true);
    }
    XidImpl xid1 = new XidImpl(xid);
    Transaction transaction = server.getResourceManager().getTransaction(xid1);
    assertNull(transaction);
}
Also used : Xid(javax.transaction.xa.Xid) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 23 with Transaction

use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.

the class SimpleOpenWireTest method testXAResourceRolledBackSuspendedNotRemoved.

@Test
public void testXAResourceRolledBackSuspendedNotRemoved() throws Exception {
    Queue queue = null;
    Xid xid = newXID();
    try (XAConnection xaconnection = xaFactory.createXAConnection()) {
        XASession session = xaconnection.createXASession();
        queue = session.createQueue(queueName);
        session.getXAResource().start(xid, XAResource.TMNOFLAGS);
        session.getXAResource().end(xid, XAResource.TMSUSPEND);
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        // directly suspend the tx
        transaction.suspend();
        session.getXAResource().rollback(xid);
    } catch (XAException ex) {
    // ignore
    } finally {
        XidImpl xid1 = new XidImpl(xid);
        Transaction transaction = server.getResourceManager().getTransaction(xid1);
        assertNotNull(transaction);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XASession(javax.jms.XASession) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 24 with Transaction

use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.

the class ServerSessionImpl method individualAcknowledge.

@Override
public void individualAcknowledge(final long consumerID, final long messageID) throws Exception {
    ServerConsumer consumer = findConsumer(consumerID);
    if (tx != null && tx.getState() == State.ROLLEDBACK) {
        // JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just
        // have these messages to be stuck on the limbo until the server is restarted
        // The tx has already timed out, so we need to ack and rollback immediately
        Transaction newTX = newTransaction();
        consumer.individualAcknowledge(tx, messageID);
        newTX.rollback();
    } else {
        consumer.individualAcknowledge(autoCommitAcks ? null : tx, messageID);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 25 with Transaction

use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.

the class ServerSessionImpl method findConsumer.

private ServerConsumer findConsumer(long consumerID) throws Exception {
    ServerConsumer consumer = locateConsumer(consumerID);
    if (consumer == null) {
        Transaction currentTX = tx;
        ActiveMQIllegalStateException exception = ActiveMQMessageBundle.BUNDLE.consumerDoesntExist(consumerID);
        if (currentTX != null) {
            currentTX.markAsRollbackOnly(exception);
        }
        throw exception;
    }
    return consumer;
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Aggregations

Transaction (org.apache.activemq.artemis.core.transaction.Transaction)52 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)24 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)14 Test (org.junit.Test)14 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 Xid (javax.transaction.xa.Xid)12 Queue (org.apache.activemq.artemis.core.server.Queue)11 ArrayList (java.util.ArrayList)10 Message (org.apache.activemq.artemis.api.core.Message)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 Map (java.util.Map)8 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)8 HashMap (java.util.HashMap)7 PageSubscriptionCounter (org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter)7 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 BindingsTransactionImpl (org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4