public void executeTransaction(TransactionalOperation op)
{
MessageStore store = getMessageStore();
final LocalTransaction txn = new LocalTransaction(store);
op.withinTransaction(new Transaction()
{
public void dequeue(final MessageInstance messageInstance)
{
boolean acquired = messageInstance.acquire();
if(!acquired && messageInstance instanceof QueueEntry)
{
QueueEntry entry = (QueueEntry) messageInstance;
QueueConsumer consumer = (QueueConsumer) entry.getDeliveredConsumer();
acquired = messageInstance.removeAcquisitionFromConsumer(consumer);
if(acquired)
{
consumer.acquisitionRemoved((QueueEntry)messageInstance);
}
}
if(acquired)
{
txn.dequeue(messageInstance.getOwningResource(), messageInstance.getMessage(), new ServerTransaction.Action()
{
public void postCommit()
{
messageInstance.delete();
}
public void onRollback()
{
}
});
}
}
public void copy(MessageInstance entry, Queue queue)
{
final ServerMessage message = entry.getMessage();
final AMQQueue toQueue = (AMQQueue)queue;
txn.enqueue(toQueue, message, new ServerTransaction.Action()
{
public void postCommit()
{
toQueue.enqueue(message, null);
}
public void onRollback()
{
}
});
}
public void move(final MessageInstance entry, Queue queue)
{
final ServerMessage message = entry.getMessage();
final AMQQueue toQueue = (AMQQueue)queue;
if(entry.acquire())
{
txn.enqueue(toQueue, message,
new ServerTransaction.Action()
{
public void postCommit()
{
toQueue.enqueue(message, null);
}
public void onRollback()
{
entry.release();
}
});
txn.dequeue(entry.getOwningResource(), message,
new ServerTransaction.Action()
{
public void postCommit()
{
entry.delete();
}
public void onRollback()
{
}
});
}
}
});
txn.commit();
}