Search in sources :

Example 6 with Transaction

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

the class PageCursorProviderImpl method onPageModeCleared.

/**
 * Delete everything associated with any queue on this address.
 * This is to be called when the address is about to be released from paging.
 * Hence the PagingStore will be holding a write lock, meaning no messages are going to be paged at this time.
 * So, we shouldn't lock anything after this method, to avoid dead locks between the writeLock and any synchronization with the CursorProvider.
 */
@Override
public void onPageModeCleared() {
    ArrayList<PageSubscription> subscriptions = cloneSubscriptions();
    Transaction tx = new TransactionImpl(storageManager);
    for (PageSubscription sub : subscriptions) {
        try {
            sub.onPageModeCleared(tx);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorCleaningPagingOnQueue(e, sub.getQueue().getName().toString());
        }
    }
    try {
        tx.commit();
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.errorCleaningPagingDuringCommit(e);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)

Example 7 with Transaction

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

the class MQTTRetainMessageManager method addRetainedMessagesToQueue.

// SEND to Queue.
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception {
    // The address filter that matches all retained message queues.
    String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration());
    BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress));
    // Iterate over all matching retain queues and add the queue
    Transaction tx = session.getServerSession().newTransaction();
    try {
        synchronized (queue) {
            for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) {
                Queue retainedQueue = session.getServer().locateQueue(retainedQueueName);
                try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) {
                    if (i.hasNext()) {
                        Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID());
                        sendToQueue(message, queue, tx);
                    }
                }
            }
        }
    } catch (Throwable t) {
        tx.rollback();
        throw t;
    }
    tx.commit();
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 8 with Transaction

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

the class OpenWireConnection method lookupTX.

private Transaction lookupTX(TransactionId txID, AMQSession session, boolean remove) throws IllegalStateException {
    if (txID == null) {
        return null;
    }
    Xid xid = null;
    Transaction transaction;
    if (txID.isXATransaction()) {
        xid = OpenWireUtil.toXID(txID);
        transaction = remove ? server.getResourceManager().removeTransaction(xid) : server.getResourceManager().getTransaction(xid);
    } else {
        transaction = remove ? txMap.remove(txID) : txMap.get(txID);
    }
    if (transaction == null) {
        return null;
    }
    if (session != null && transaction.getProtocolData() != session) {
        transaction.setProtocolData(session);
    }
    return transaction;
}
Also used : Xid(javax.transaction.xa.Xid) Transaction(org.apache.activemq.artemis.core.transaction.Transaction)

Example 9 with Transaction

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

the class AMQPConnectionCallback method newTransaction.

public Binary newTransaction() {
    XidImpl xid = newXID();
    Binary binary = new Binary(xid.getGlobalTransactionId());
    Transaction transaction = new ProtonTransactionImpl(xid, server.getStorageManager(), -1);
    transactions.put(binary, transaction);
    return binary;
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) Binary(org.apache.qpid.proton.amqp.Binary) ProtonTransactionImpl(org.apache.activemq.artemis.protocol.amqp.proton.transaction.ProtonTransactionImpl)

Example 10 with Transaction

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

the class AMQPConnectionCallback method close.

public void close() {
    try {
        if (registeredConnectionId.getAndSet(false)) {
            server.removeClientConnection(remoteContainerId);
        }
        connection.close();
        amqpConnection.close(null);
    } finally {
        for (Transaction tx : transactions.values()) {
            try {
                tx.rollback();
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)

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