@Override public int compareTo(Page otherPage) { return otherPage.getPageId() - this.pageId; }
@Override public long getPageId() { return page.getPageId(); }
@Override public String toString() { return "PageCacheImpl::page=" + page.getPageId() + " numberOfMessages = " + messages.length; }
@Override public long getPageId() { return page.getPageId(); }
@Override public String toString() { return "LivePacheCacheImpl::page=" + page.getPageId() + " number of messages=" + getNumberOfMessages() + " isLive = " + isLive; } }
/** * This is used only on non transactional paging * * @param page * @param increment * @throws Exception */ @Override public synchronized void pendingCounter(Page page, int increment, long size) throws Exception { if (!persistent) { return; // nothing to be done } PendingCounter pendingInfo = pendingCounters.get((long) page.getPageId()); if (pendingInfo == null) { // We have to make sure this is sync here // not syncing this to disk may cause the page files to be out of sync on pages. // we can't afford the case where a page file is written without a record here long id = storage.storePendingCounter(this.subscriptionID, page.getPageId()); pendingInfo = new PendingCounter(id, increment, size); pendingCounters.put((long) page.getPageId(), pendingInfo); } else { pendingInfo.addAndGet(increment, size); } pendingValue.addAndGet(increment); pendingPersistentSize.addAndGet(size); page.addPendingCounter(this); }
@Override public void onDeletePage(Page deletedPage) throws Exception { PageCursorInfo info; synchronized (consumedPages) { info = consumedPages.remove(Long.valueOf(deletedPage.getPageId())); } if (info != null) { PagePosition completeInfo = info.getCompleteInfo(); if (completeInfo != null) { try { store.deletePageComplete(completeInfo.getRecordID()); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorDeletingPageCompleteRecord(e); } info.setCompleteInfo(null); } for (PagePosition deleteInfo : info.acks) { if (deleteInfo.getRecordID() >= 0) { try { store.deleteCursorAcknowledge(deleteInfo.getRecordID()); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorDeletingPageCompleteRecord(e); } } } info.acks.clear(); } }
/** * sendEvent means it's a close happening from a major event such moveNext. * While reading the cache we don't need (and shouldn't inform the backup */ public synchronized void close(boolean sendEvent) throws Exception { if (sendEvent && storageManager != null) { storageManager.pageClosed(storeName, pageId); } if (pageCache != null) { pageCache.close(); // leave it to the soft cache to decide when to release it now pageCache = null; } file.close(); Set<PageSubscriptionCounter> counters = getPendingCounters(); if (counters != null) { for (PageSubscriptionCounter counter : counters) { counter.cleanupNonTXCounters(this.getPageId()); } } }
Page currentPage = pageStore.getCurrentPage(); if (currentPage != null && entry.getKey() == pageStore.getCurrentPage().getPageId() && currentPage.isLive()) { logger.trace("We can't clear page " + entry.getKey() +
" pageNr=" + currentPage.getPageId());
/** * @param cursorList * @param currentPage * @throws Exception */ protected void storeBookmark(ArrayList<PageSubscription> cursorList, Page currentPage) throws Exception { try { // First step: Move every cursor to the next bookmarked page (that was just created) for (PageSubscription cursor : cursorList) { cursor.confirmPosition(new PagePositionImpl(currentPage.getPageId(), -1)); } // we just need to make sure the storage is done.. // if the thread pool is full, we will just log it once instead of looping if (!storageManager.waitOnOperations(5000)) { ActiveMQServerLogger.LOGGER.problemCompletingOperations(storageManager.getContext()); } } finally { for (PageSubscription cursor : cursorList) { cursor.enableAutoCleanup(); } } }
/** * 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; }
Assert.assertEquals(10, impl.getPageId());
/** * Validate if everything we add is recovered */ protected void testAdd(final SequentialFileFactory factory, final int numberOfElements) throws Exception { SequentialFile file = factory.createSequentialFile("00010.page"); Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); Assert.assertEquals(10, impl.getPageId()); impl.open(); Assert.assertEquals(1, factory.listFiles("page").size()); SimpleString simpleDestination = new SimpleString("Test"); addPageElements(simpleDestination, impl, numberOfElements); impl.sync(); impl.close(); file = factory.createSequentialFile("00010.page"); file.open(); impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); List<PagedMessage> msgs = impl.read(new NullStorageManager()); Assert.assertEquals(numberOfElements, msgs.size()); Assert.assertEquals(numberOfElements, impl.getNumberOfMessages()); for (int i = 0; i < msgs.size(); i++) { Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString()); } impl.delete(null); Assert.assertEquals(0, factory.listFiles(".page").size()); }