private static final Logger _logger = Logger.getLogger(SynchronousMessageStoreRecoverer.class);
@Override
public void recover(VirtualHostImpl virtualHost)
{
EventLogger eventLogger = virtualHost.getEventLogger();
MessageStore store = virtualHost.getMessageStore();
MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
Map<String, Integer> queueRecoveries = new TreeMap<>();
Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
Map<Long, StoredMessage<?>> unusedMessages = new HashMap<>();
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
store.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
store.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries,
recoveredMessages, unusedMessages));
for(Map.Entry<String,Integer> entry : queueRecoveries.entrySet())
{
eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(entry.getValue(), entry.getKey()));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(entry.getKey(), true));
virtualHost.getQueue(entry.getKey()).completeRecovery();
}
Collection<AMQQueue> allQueues = virtualHost.getQueues();
for(AMQQueue q : allQueues)
{
if(!queueRecoveries.containsKey(q.getName()))
{
q.completeRecovery();
}
}
store.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, store, eventLogger,
logSubject, recoveredMessages, unusedMessages));
for(StoredMessage<?> m : unusedMessages.values())
{
_logger.warn("Message id " + m.getMessageNumber() + " in store, but not in any queue - removing....");
m.remove();
}
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
eventLogger.message(logSubject,
MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
}