Search in sources :

Example 1 with PersistentQueueBindingEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding in project activemq-artemis by apache.

the class AbstractJournalStorageManager method newQueueBindingEncoding.

/**
 * @param id
 * @param buffer
 * @return
 */
protected static PersistentQueueBindingEncoding newQueueBindingEncoding(long id, ActiveMQBuffer buffer) {
    PersistentQueueBindingEncoding bindingEncoding = new PersistentQueueBindingEncoding();
    bindingEncoding.decode(buffer);
    bindingEncoding.setId(id);
    return bindingEncoding;
}
Also used : PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding)

Example 2 with PersistentQueueBindingEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding in project activemq-artemis by apache.

the class XmlDataExporter method printPagedMessagesAsXML.

/**
 * Reads from the page files and prints messages as it finds them (making sure to check acks and transactions
 * from the journal).
 */
private void printPagedMessagesAsXML() {
    try {
        pagingmanager.start();
        SimpleString[] stores = pagingmanager.getStoreNames();
        for (SimpleString store : stores) {
            PagingStore pageStore = pagingmanager.getPageStore(store);
            if (pageStore != null) {
                File folder = pageStore.getFolder();
                ActiveMQServerLogger.LOGGER.debug("Reading page store " + store + " folder = " + folder);
                int pageId = (int) pageStore.getFirstPage();
                for (int i = 0; i < pageStore.getNumberOfPages(); i++) {
                    ActiveMQServerLogger.LOGGER.debug("Reading page " + pageId);
                    Page page = pageStore.createPage(pageId);
                    page.open();
                    List<PagedMessage> messages = page.read(storageManager);
                    page.close();
                    int messageId = 0;
                    for (PagedMessage message : messages) {
                        message.initMessage(storageManager);
                        long[] queueIDs = message.getQueueIDs();
                        List<String> queueNames = new ArrayList<>();
                        for (long queueID : queueIDs) {
                            PagePosition posCheck = new PagePositionImpl(pageId, messageId);
                            boolean acked = false;
                            Set<PagePosition> positions = cursorRecords.get(queueID);
                            if (positions != null) {
                                acked = positions.contains(posCheck);
                            }
                            if (!acked) {
                                PersistentQueueBindingEncoding queueBinding = queueBindings.get(queueID);
                                if (queueBinding != null) {
                                    SimpleString queueName = queueBinding.getQueueName();
                                    queueNames.add(queueName.toString());
                                }
                            }
                        }
                        if (queueNames.size() > 0 && (message.getTransactionID() == -1 || pgTXs.contains(message.getTransactionID()))) {
                            printSingleMessageAsXML(message.getMessage().toCore(), queueNames);
                        }
                        messageId++;
                    }
                    pageId++;
                }
            } else {
                ActiveMQServerLogger.LOGGER.debug("Page store was null");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagePositionImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PagePositionImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) XMLStreamException(javax.xml.stream.XMLStreamException) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) File(java.io.File)

Example 3 with PersistentQueueBindingEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding in project activemq-artemis by apache.

the class AbstractJournalStorageManager method internalQueueBinding.

private void internalQueueBinding(boolean update, final long tx, final Binding binding) throws Exception {
    Queue queue = (Queue) binding.getBindable();
    Filter filter = queue.getFilter();
    SimpleString filterString = filter == null ? null : filter.getFilterString();
    PersistentQueueBindingEncoding bindingEncoding = new PersistentQueueBindingEncoding(queue.getName(), binding.getAddress(), filterString, queue.getUser(), queue.isAutoCreated(), queue.getMaxConsumers(), queue.isPurgeOnNoConsumers(), queue.isExclusive(), queue.isLastValue(), queue.getRoutingType().getType());
    readLock();
    try {
        if (update) {
            bindingsJournal.appendUpdateRecordTransactional(tx, binding.getID(), JournalRecordIds.QUEUE_BINDING_RECORD, bindingEncoding);
        } else {
            bindingsJournal.appendAddRecordTransactional(tx, binding.getID(), JournalRecordIds.QUEUE_BINDING_RECORD, bindingEncoding);
        }
    } finally {
        readUnLock();
    }
}
Also used : Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 4 with PersistentQueueBindingEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding in project activemq-artemis by apache.

the class AbstractJournalStorageManager method loadBindingJournal.

@Override
public JournalLoadInformation loadBindingJournal(final List<QueueBindingInfo> queueBindingInfos, final List<GroupingInfo> groupingInfos, final List<AddressBindingInfo> addressBindingInfos) throws Exception {
    List<RecordInfo> records = new ArrayList<>();
    List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
    JournalLoadInformation bindingsInfo = bindingsJournal.load(records, preparedTransactions, null);
    HashMap<Long, PersistentQueueBindingEncoding> mapBindings = new HashMap<>();
    for (RecordInfo record : records) {
        long id = record.id;
        ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
        byte rec = record.getUserRecordType();
        if (rec == JournalRecordIds.QUEUE_BINDING_RECORD) {
            PersistentQueueBindingEncoding bindingEncoding = newQueueBindingEncoding(id, buffer);
            mapBindings.put(bindingEncoding.getId(), bindingEncoding);
        } else if (rec == JournalRecordIds.ID_COUNTER_RECORD) {
            idGenerator.loadState(record.id, buffer);
        } else if (rec == JournalRecordIds.ADDRESS_BINDING_RECORD) {
            PersistentAddressBindingEncoding bindingEncoding = newAddressBindingEncoding(id, buffer);
            addressBindingInfos.add(bindingEncoding);
        } else if (rec == JournalRecordIds.GROUP_RECORD) {
            GroupingEncoding encoding = newGroupEncoding(id, buffer);
            groupingInfos.add(encoding);
        } else if (rec == JournalRecordIds.ADDRESS_SETTING_RECORD) {
            PersistedAddressSetting setting = newAddressEncoding(id, buffer);
            mapPersistedAddressSettings.put(setting.getAddressMatch(), setting);
        } else if (rec == JournalRecordIds.SECURITY_RECORD) {
            PersistedRoles roles = newSecurityRecord(id, buffer);
            mapPersistedRoles.put(roles.getAddressMatch(), roles);
        } else if (rec == JournalRecordIds.QUEUE_STATUS_RECORD) {
            QueueStatusEncoding statusEncoding = newQueueStatusEncoding(id, buffer);
            PersistentQueueBindingEncoding queueBindingEncoding = mapBindings.get(statusEncoding.queueID);
            if (queueBindingEncoding != null) {
                queueBindingEncoding.addQueueStatusEncoding(statusEncoding);
            } else {
                // unlikely to happen, so I didn't bother about the Logger method
                ActiveMQServerLogger.LOGGER.infoNoQueueWithID(statusEncoding.queueID, statusEncoding.getId());
                this.deleteQueueStatus(statusEncoding.getId());
            }
        } else {
            // unlikely to happen
            ActiveMQServerLogger.LOGGER.invalidRecordType(rec, new Exception("invalid record type " + rec));
        }
    }
    for (PersistentQueueBindingEncoding queue : mapBindings.values()) {
        queueBindingInfos.add(queue);
    }
    // just to give a hand to GC
    mapBindings.clear();
    // This will instruct the IDGenerator to beforeStop old records
    idGenerator.cleanup();
    return bindingsInfo;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) QueueStatusEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PersistedRoles(org.apache.activemq.artemis.core.persistence.config.PersistedRoles) PersistedAddressSetting(org.apache.activemq.artemis.core.persistence.config.PersistedAddressSetting) ArrayList(java.util.ArrayList) InvalidParameterException(java.security.InvalidParameterException) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) PersistentAddressBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding) GroupingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.GroupingEncoding) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 5 with PersistentQueueBindingEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding in project activemq-artemis by apache.

the class XmlDataExporter method getBindings.

/**
 * Open the bindings journal and extract all bindings data.
 *
 * @throws Exception will be thrown if anything goes wrong reading the bindings journal
 */
private void getBindings() throws Exception {
    List<RecordInfo> records = new LinkedList<>();
    Journal bindingsJournal = storageManager.getBindingsJournal();
    bindingsJournal.start();
    ActiveMQServerLogger.LOGGER.debug("Reading bindings journal from " + config.getBindingsDirectory());
    bindingsJournal.load(records, null, null);
    for (RecordInfo info : records) {
        if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
            PersistentQueueBindingEncoding bindingEncoding = (PersistentQueueBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
            queueBindings.put(bindingEncoding.getId(), bindingEncoding);
        } else if (info.getUserRecordType() == JournalRecordIds.ADDRESS_BINDING_RECORD) {
            PersistentAddressBindingEncoding bindingEncoding = (PersistentAddressBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
            addressBindings.put(bindingEncoding.getId(), bindingEncoding);
        }
    }
    bindingsJournal.stop();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PersistentAddressBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) LinkedList(java.util.LinkedList)

Aggregations

PersistentQueueBindingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 PersistentAddressBindingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 File (java.io.File)1 InvalidParameterException (java.security.InvalidParameterException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 Filter (org.apache.activemq.artemis.core.filter.Filter)1 Journal (org.apache.activemq.artemis.core.journal.Journal)1 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)1