Search in sources :

Example 6 with PagePosition

use of org.apache.activemq.artemis.core.paging.cursor.PagePosition 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;
        }
    }
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition) PageCache(org.apache.activemq.artemis.core.paging.cursor.PageCache)

Example 7 with PagePosition

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

the class PageSubscriptionImpl method processReload.

@Override
public void processReload() throws Exception {
    if (recoveredACK != null) {
        if (logger.isTraceEnabled()) {
            logger.trace("********** processing reload!!!!!!!");
        }
        Collections.sort(recoveredACK);
        long txDeleteCursorOnReload = -1;
        for (PagePosition pos : recoveredACK) {
            lastAckedPosition = pos;
            PageCursorInfo pageInfo = getPageInfo(pos);
            if (pageInfo == null) {
                ActiveMQServerLogger.LOGGER.pageNotFound(pos);
                if (txDeleteCursorOnReload == -1) {
                    txDeleteCursorOnReload = store.generateID();
                }
                store.deleteCursorAcknowledgeTransactional(txDeleteCursorOnReload, pos.getRecordID());
            } else {
                pageInfo.loadACK(pos);
            }
        }
        if (txDeleteCursorOnReload >= 0) {
            store.commit(txDeleteCursorOnReload);
        }
        recoveredACK.clear();
        recoveredACK = null;
    }
}
Also used : PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition)

Example 8 with PagePosition

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

the class PageSubscriptionImpl method onDeletePage.

@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();
    }
}
Also used : PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Aggregations

PagePosition (org.apache.activemq.artemis.core.paging.cursor.PagePosition)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 Page (org.apache.activemq.artemis.core.paging.impl.Page)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)2 PagePositionImpl (org.apache.activemq.artemis.core.paging.cursor.impl.PagePositionImpl)2 LinkedHashSet (java.util.LinkedHashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)1 PageCache (org.apache.activemq.artemis.core.paging.cursor.PageCache)1 PageTransactionInfoImpl (org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl)1 CursorAckRecordEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding)1 PageUpdateTXEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageUpdateTXEncoding)1 PersistentQueueBindingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding)1 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)1