final long toMessageId,
String queueName,
final StoreContext storeContext)
{
AMQQueue toQueue = getVirtualHost().getQueueRegistry().getQueue(new AMQShortString(queueName));
MessageStore store = getVirtualHost().getMessageStore();
List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter()
{
public boolean accept(QueueEntry entry)
{
final long messageId = entry.getMessage().getMessageId();
if ((messageId >= fromMessageId)
&& (messageId <= toMessageId))
{
if (!entry.isDeleted())
{
return entry.getMessage().incrementReference();
}
}
return false;
}
public boolean filterComplete()
{
return false;
}
});
try
{
store.beginTran(storeContext);
// Move the messages in on the message store.
for (QueueEntry entry : entries)
{
AMQMessage message = entry.getMessage();
if (message.isReferenced() && message.isPersistent() && toQueue.isDurable())
{
store.enqueueMessage(storeContext, toQueue, message.getMessageId());
}
}
// Commit and flush the move transcations.
try
{
store.commitTran(storeContext);
}
catch (AMQException e)
{
throw new RuntimeException("Failed to commit transaction whilst moving messages on message store.", e);
}
}
catch (AMQException e)
{
try
{
store.abortTran(storeContext);
}
catch (AMQException rollbackEx)
{
_logger.error("Failed to rollback transaction when error occured moving messages", rollbackEx);
}