/**
* It will cleanup all the records for completed pages
* */
public void cleanupEntries() throws Exception
{
Transaction tx = new TransactionImpl(store);
boolean persist = false;
final ArrayList<PageCursorInfo> completedPages = new ArrayList<PageCursorInfo>();
// First get the completed pages using a lock
synchronized (this)
{
for (Entry<Long, PageCursorInfo> entry : consumedPages.entrySet())
{
PageCursorInfo info = entry.getValue();
if (info.isDone() && !info.isPendingDelete() && lastAckedPosition != null)
{
if (entry.getKey() == lastAckedPosition.getPageNr())
{
// PageSubscriptionImpl.trace("We can't clear page " + entry.getKey() +
// " now since it's the current page");
}
else
{
info.setPendingDelete();
completedPages.add(entry.getValue());
}
}
}
}
for (int i = 0; i < completedPages.size(); i++)
{
PageCursorInfo info = completedPages.get(i);
for (PagePosition pos : info.acks)
{
if (pos.getRecordID() > 0)
{
store.deleteCursorAcknowledgeTransactional(tx.getID(), pos.getRecordID());
if (!persist)
{
// only need to set it once
tx.setContainsPersistent();
persist = true;
}
}
}
}
tx.addOperation(new TransactionOperationAbstract()
{
@Override
public void afterCommit(final Transaction tx)
{
executor.execute(new Runnable()
{
public void run()
{
synchronized (PageSubscriptionImpl.this)
{
for (PageCursorInfo completePage : completedPages)
{
if (isTrace)
{
PageSubscriptionImpl.trace("Removing page " + completePage.getPageId());
}
if (consumedPages.remove(completePage.getPageId()) == null)
{
PageSubscriptionImpl.log.warn("Couldn't remove page " + completePage.getPageId() +
" from consumed pages on cursor for address " +
pageStore.getAddress());
}
}
}
cursorProvider.scheduleCleanup();
}
});
}
});
tx.commit();
}