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);
}
}
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();
}
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;
}
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;
}
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);
}
}
}
}
Aggregations