private PageCursorInfo getPageInfo(final PagePosition pos) { return getPageInfo(pos.getPageNr()); }
@Override public void redeliver(final PageIterator iterator, final PagePosition position) { iterator.redeliver(position); synchronized (consumedPages) { PageCursorInfo pageInfo = consumedPages.get(position.getPageNr()); if (pageInfo != null) { pageInfo.decrementPendingTX(); } else { // this shouldn't really happen. } } }
private PagePosition moveNextPage(final PagePosition pos) { PagePosition retPos = pos; while (true) { retPos = retPos.nextPage(); synchronized (consumedPages) { PageCursorInfo pageInfo = consumedPages.get(retPos.getPageNr()); // any deleted or complete page will be ignored on the moveNextPage, we will just keep going if (pageInfo == null || (!pageInfo.isPendingDelete() && pageInfo.getCompleteInfo() == null)) { return retPos; } } } }
/** * A page marked as complete will be ignored until it's cleared. * <p> * Usually paging is a stream of messages but in certain scenarios (such as a pending prepared * TX) we may have big holes on the page streaming, and we will need to ignore such pages on the * cursor/subscription. */ @Override public boolean reloadPageCompletion(PagePosition position) throws Exception { if (!pageStore.checkPageFileExists((int)position.getPageNr())) { return false; } // if the current page is complete, we must move it out of the way if (pageStore.getCurrentPage() != null && pageStore.getCurrentPage().getPageId() == position.getPageNr()) { pageStore.forceAnotherPage(); } PageCursorInfo info = new PageCursorInfo(position.getPageNr(), position.getMessageNr(), null); info.setCompleteInfo(position); synchronized (consumedPages) { consumedPages.put(Long.valueOf(position.getPageNr()), info); } return true; }
@Override public void encode(ActiveMQBuffer buffer) { buffer.writeLong(queueID); buffer.writeLong(position.getPageNr()); buffer.writeInt(position.getMessageNr()); }
private PageCursorInfo processACK(final PagePosition pos) { if (lastAckedPosition == null || pos.compareTo(lastAckedPosition) > 0) { if (logger.isTraceEnabled()) { logger.trace("a new position is being processed as ACK"); } if (lastAckedPosition != null && lastAckedPosition.getPageNr() != pos.getPageNr()) { if (logger.isTraceEnabled()) { logger.trace("Scheduling cleanup on pageSubscription for address = " + pageStore.getAddress() + " queue = " + this.getQueue().getName()); } // there's a different page being acked, we will do the check right away if (autoCleanup) { scheduleCleanupCheck(); } } lastAckedPosition = pos; } PageCursorInfo info = getPageInfo(pos); // This could be null if the page file was removed if (info == null) { // This could become null if the page file was deleted, or if the queue was removed maybe? // it's better to diagnose it (based on support tickets) instead of NPE ActiveMQServerLogger.LOGGER.nullPageCursorInfo(this.getPagingStore().getAddress().toString(), pos.toString(), cursorId); } else { info.addACK(pos); } return info; }
@Override public PagedMessage getMessage(final PagePosition pos) { PageCache cache = getPageCache(pos.getPageNr()); if (cache == null || pos.getMessageNr() >= cache.getNumberOfMessages()) { // sanity check, this should never happen unless there's a bug throw new NonExistentPage("Invalid messageNumber passed = " + pos + " on " + cache); } return cache.getMessage(pos.getMessageNr()); }
Long pageNR = Long.valueOf(encoding.position.getPageNr());
private PagedReference internalGetNext(final PagePosition pos) { PagePosition retPos = pos.nextMessage(); PageCache cache = cursorProvider.getPageCache(pos.getPageNr()); while ((cache == null && retPos.getPageNr() <= pageStore.getCurrentWritingPage()) || (cache != null && retPos.getPageNr() <= pageStore.getCurrentWritingPage() && cache.getNumberOfMessages() == 0)) { emptyCache = cache; retPos = moveNextPage(retPos); cache = cursorProvider.getPageCache(retPos.getPageNr());
Long pageNR = Long.valueOf(encoding.position.getPageNr());
if (!sub.reloadPageCompletion(encoding.position)) { if (logger.isDebugEnabled()) { logger.debug("Complete page " + encoding.position.getPageNr() + " doesn't exist on page manager " + sub.getPagingStore().getAddress());
PageCursorInfo info = getPageInfo(message.getPosition().getPageNr());