use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageSubscriptionImpl method getPageInfo.
private PageCursorInfo getPageInfo(final long pageNr) {
synchronized (consumedPages) {
PageCursorInfo pageInfo = consumedPages.get(pageNr);
if (pageInfo == null) {
PageCache cache = cursorProvider.getPageCache(pageNr);
if (cache == null) {
return null;
}
pageInfo = new PageCursorInfo(pageNr, cache.getNumberOfMessages(), cache);
consumedPages.put(pageNr, pageInfo);
}
return pageInfo;
}
}
use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageCursorProviderImpl method getPageCache.
@Override
public PageCache getPageCache(final long pageId) {
try {
PageCache cache;
synchronized (softCache) {
if (pageId > pagingStore.getCurrentWritingPage()) {
return null;
}
cache = softCache.get(pageId);
if (cache == null) {
if (!pagingStore.checkPageFileExists((int) pageId)) {
return null;
}
cache = createPageCache(pageId);
// anyone reading from this cache will have to wait reading to finish first
// we also want only one thread reading this cache
logger.tracef("adding pageCache pageNr=%d into cursor = %s", pageId, this.pagingStore.getAddress());
readPage((int) pageId, cache);
softCache.put(pageId, cache);
}
}
return cache;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageCursorStressTest method testReadNextPage.
@Test
public void testReadNextPage() throws Exception {
final int NUM_MESSAGES = 1;
int numberOfPages = addMessages(NUM_MESSAGES, 1024);
System.out.println("NumberOfPages = " + numberOfPages);
PageCursorProvider cursorProvider = lookupCursorProvider();
PageCache cache = cursorProvider.getPageCache(2);
assertNull(cache);
}
use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageSubscriptionImpl method internalGetNext.
private PagedReference internalGetNext(final PagePosition pos) {
PagePosition retPos = pos.nextMessage();
PageCache cache = cursorProvider.getPageCache(pos.getPageNr());
if (cache != null && !cache.isLive() && retPos.getMessageNr() >= cache.getNumberOfMessages()) {
// The next message is beyond what's available at the current page, so we need to move to the next page
cache = null;
}
// it will scan for the next available page
while ((cache == null && retPos.getPageNr() <= pageStore.getCurrentWritingPage()) || (cache != null && retPos.getPageNr() <= pageStore.getCurrentWritingPage() && cache.getNumberOfMessages() == 0)) {
retPos = moveNextPage(retPos);
cache = cursorProvider.getPageCache(retPos.getPageNr());
}
if (cache == null) {
// it will be null in the case of the current writing page
return null;
} else {
PagedMessage serverMessage = cache.getMessage(retPos.getMessageNr());
if (serverMessage != null) {
return cursorProvider.newReference(retPos, serverMessage, this);
} else {
return null;
}
}
}
use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageSubscriptionImpl method installTXCallback.
/**
* @param tx
* @param position
*/
private void installTXCallback(final Transaction tx, final PagePosition position) {
if (position.getRecordID() >= 0) {
// It needs to persist, otherwise the cursor will return to the fist page position
tx.setContainsPersistent();
}
PageCursorInfo info = getPageInfo(position);
PageCache cache = info.getCache();
long size = 0;
if (cache != null) {
size = getPersistentSize(cache.getMessage(position.getMessageNr()));
position.setPersistentSize(size);
}
logger.tracef("InstallTXCallback looking up pagePosition %s, result=%s", position, info);
info.remove(position);
PageCursorTX cursorTX = (PageCursorTX) tx.getProperty(TransactionPropertyIndexes.PAGE_CURSOR_POSITIONS);
if (cursorTX == null) {
cursorTX = new PageCursorTX();
tx.putProperty(TransactionPropertyIndexes.PAGE_CURSOR_POSITIONS, cursorTX);
tx.addOperation(cursorTX);
}
cursorTX.addPositionConfirmation(this, position);
}
Aggregations