}
public void recoverSubscription(Subscription subscription, MessageIdentity lastDispatchedMessage) throws JMSException {
checkClosed();
SecondaryCursor cursor = null;
try {
DatabaseEntry lastAckKey = getLastAcknowledgedMessageID(subscription, 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: " + subscription + ". 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);
subscription.addMessage(getContainer(), message);
}
}
}
}
catch (DatabaseException e) {
throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
+ subscription + ". Reason: " + e, e);
}
catch (IOException e) {
throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
+ subscription + ". Reason: " + e, e);
}
finally {
if (cursor != null) {
try {
cursor.close();
}
catch (DatabaseException e) {
log.warn("Caught exception closing cursor: " + e, e);
}
}