/**
*
*/
public void recoverSubscription(String subscriptionId, MessageIdentity lastDispatchedMessage, final RecoveryListener listener) throws JMSException {
checkClosed();
SecondaryCursor cursor = null;
try {
DatabaseEntry lastAckKey = getLastAcknowledgedMessageID(subscriptionId, lastDispatchedMessage);
if (lastAckKey != null) {
cursor = getSecondaryDatabase().openSecondaryCursor(BDbHelper.getTransaction(), getCursorConfig());
DatabaseEntry valueEntry = new DatabaseEntry();
OperationStatus status = cursor.getSearchKey(lastAckKey, valueEntry, LockMode.DEFAULT);
if (status != OperationStatus.SUCCESS) {
log.error("Could not find the last acknowledged record for: " + subscriptionId + ". Status: " + status);
}
else {
while (true) {
// lets pass straight over the first entry, which we've already ack'd
status = cursor.getNext(lastAckKey, valueEntry, LockMode.DEFAULT);
if (status != OperationStatus.SUCCESS) {
if (status != OperationStatus.NOTFOUND) {
log.warn("Strange result when iterating to end of collection: " + status);
}
break;
}
ActiveMQMessage message = extractMessage(valueEntry);
listener.recoverMessage(message.getJMSMessageIdentity());
}
}
}
}
catch (DatabaseException e) {
throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
+ subscriptionId + ". Reason: " + e, e);
}
catch (IOException e) {
throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
+ subscriptionId + ". Reason: " + e, e);
}
finally {
if (cursor != null) {
try {
cursor.close();
}
catch (DatabaseException e) {
log.warn("Caught exception closing cursor: " + e, e);
}
}