}
public void executeTransaction(TransactionalOperation op)
{
MessageStore store = _virtualHost.getMessageStore();
final LocalTransaction txn = new LocalTransaction(store);
op.withinTransaction(new Transaction()
{
public void dequeue(final QueueEntry entry)
{
if(entry.acquire())
{
txn.dequeue(entry.getQueue(), entry.getMessage(), new ServerTransaction.Action()
{
public void postCommit()
{
entry.discard();
}
public void onRollback()
{
}
});
}
}
public void copy(QueueEntry entry, Queue queue)
{
final ServerMessage message = entry.getMessage();
final AMQQueue toQueue = ((QueueAdapter)queue).getAMQQueue();
txn.enqueue(toQueue, message, new ServerTransaction.Action()
{
public void postCommit()
{
try
{
toQueue.enqueue(message);
}
catch(AMQException e)
{
throw new RuntimeException(e);
}
}
public void onRollback()
{
}
});
}
public void move(final QueueEntry entry, Queue queue)
{
final ServerMessage message = entry.getMessage();
final AMQQueue toQueue = ((QueueAdapter)queue).getAMQQueue();
if(entry.acquire())
{
txn.enqueue(toQueue, message,
new ServerTransaction.Action()
{
public void postCommit()
{
try
{
toQueue.enqueue(message);
}
catch (AMQException e)
{
throw new RuntimeException(e);
}
}
public void onRollback()
{
entry.release();
}
});
txn.dequeue(entry.getQueue(), message,
new ServerTransaction.Action()
{
public void postCommit()
{
entry.discard();
}
public void onRollback()
{
}
});
}
}
});
txn.commit();
}