Search in sources :

Example 1 with LivePageCacheImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.LivePageCacheImpl in project activemq-artemis by apache.

the class PagingStoreImpl method openNewPage.

private void openNewPage() throws Exception {
    lock.writeLock().lock();
    try {
        numberOfPages++;
        int tmpCurrentPageId = currentPageId + 1;
        if (logger.isTraceEnabled()) {
            logger.trace("new pageNr=" + tmpCurrentPageId, new Exception("trace"));
        }
        if (currentPage != null) {
            currentPage.close(true);
        }
        currentPage = createPage(tmpCurrentPageId);
        LivePageCache pageCache = new LivePageCacheImpl(currentPage);
        currentPage.setLiveCache(pageCache);
        cursorProvider.addPageCache(pageCache);
        currentPageSize.set(0);
        currentPage.open();
        currentPageId = tmpCurrentPageId;
        if (currentPageId < firstPageId) {
            firstPageId = currentPageId;
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : LivePageCache(org.apache.activemq.artemis.core.paging.cursor.LivePageCache) LivePageCacheImpl(org.apache.activemq.artemis.core.paging.cursor.impl.LivePageCacheImpl)

Example 2 with LivePageCacheImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.LivePageCacheImpl in project activemq-artemis by apache.

the class PagingStoreImpl method start.

@Override
public void start() throws Exception {
    lock.writeLock().lock();
    try {
        if (running) {
            // need to be ignored
            return;
        } else {
            running = true;
            firstPageId = Integer.MAX_VALUE;
            // There are no files yet on this Storage. We will just return it empty
            if (fileFactory != null) {
                currentPageId = 0;
                if (currentPage != null) {
                    currentPage.close(false);
                }
                currentPage = null;
                List<String> files = fileFactory.listFiles("page");
                numberOfPages = files.size();
                for (String fileName : files) {
                    final int fileId = PagingStoreImpl.getPageIdFromFileName(fileName);
                    if (fileId > currentPageId) {
                        currentPageId = fileId;
                    }
                    if (fileId < firstPageId) {
                        firstPageId = fileId;
                    }
                }
                if (currentPageId != 0) {
                    currentPage = createPage(currentPageId);
                    currentPage.open();
                    List<PagedMessage> messages = currentPage.read(storageManager);
                    LivePageCache pageCache = new LivePageCacheImpl(currentPage);
                    for (PagedMessage msg : messages) {
                        pageCache.addLiveMessage(msg);
                        if (msg.getMessage().isLargeMessage()) {
                            // We have to do this since addLIveMessage will increment an extra one
                            ((LargeServerMessage) msg.getMessage()).decrementDelayDeletionCount();
                        }
                    }
                    currentPage.setLiveCache(pageCache);
                    currentPageSize.set(currentPage.getSize());
                    cursorProvider.addPageCache(pageCache);
                }
                // We will not mark it for paging if there's only a single empty file
                if (currentPage != null && !(numberOfPages == 1 && currentPage.getSize() == 0)) {
                    startPaging();
                }
            }
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) LivePageCache(org.apache.activemq.artemis.core.paging.cursor.LivePageCache) LivePageCacheImpl(org.apache.activemq.artemis.core.paging.cursor.impl.LivePageCacheImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage)

Aggregations

LivePageCache (org.apache.activemq.artemis.core.paging.cursor.LivePageCache)2 LivePageCacheImpl (org.apache.activemq.artemis.core.paging.cursor.impl.LivePageCacheImpl)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)1 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)1