Search in sources :

Example 1 with QueueStatusEncoding

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

the class PostOfficeJournalLoader method initQueues.

@Override
public void initQueues(Map<Long, QueueBindingInfo> queueBindingInfosMap, List<QueueBindingInfo> queueBindingInfos) throws Exception {
    int duplicateID = 0;
    for (final QueueBindingInfo queueBindingInfo : queueBindingInfos) {
        queueBindingInfosMap.put(queueBindingInfo.getId(), queueBindingInfo);
        final Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());
        final boolean isTopicIdentification = FilterUtils.isTopicIdentification(filter);
        if (postOffice.getBinding(queueBindingInfo.getQueueName()) != null) {
            if (isTopicIdentification) {
                final long tx = storageManager.generateID();
                storageManager.deleteQueueBinding(tx, queueBindingInfo.getId());
                storageManager.commitBindings(tx);
                continue;
            } else {
                final SimpleString newName = queueBindingInfo.getQueueName().concat("-" + (duplicateID++));
                ActiveMQServerLogger.LOGGER.queueDuplicatedRenaming(queueBindingInfo.getQueueName().toString(), newName.toString());
                queueBindingInfo.replaceQueueName(newName);
            }
        }
        final QueueConfig.Builder queueConfigBuilder;
        if (queueBindingInfo.getAddress() == null) {
            queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName());
        } else {
            queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName(), queueBindingInfo.getAddress());
        }
        queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(queueBindingInfo.getUser()).durable(true).temporary(false).autoCreated(queueBindingInfo.isAutoCreated()).purgeOnNoConsumers(queueBindingInfo.isPurgeOnNoConsumers()).maxConsumers(queueBindingInfo.getMaxConsumers()).exclusive(queueBindingInfo.isExclusive()).lastValue(queueBindingInfo.isLastValue()).routingType(RoutingType.getType(queueBindingInfo.getRoutingType()));
        final Queue queue = queueFactory.createQueueWith(queueConfigBuilder.build());
        queue.setConsumersRefCount(new QueueManagerImpl(((PostOfficeImpl) postOffice).getServer(), queueBindingInfo.getQueueName()));
        if (queueBindingInfo.getQueueStatusEncodings() != null) {
            for (QueueStatusEncoding encoding : queueBindingInfo.getQueueStatusEncodings()) {
                if (encoding.getStatus() == QueueStatus.PAUSED)
                    queue.reloadPause(encoding.getId());
            }
        }
        final Binding binding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
        queues.put(queue.getID(), queue);
        postOffice.addBinding(binding);
        managementService.registerQueue(queue, queue.getAddress(), storageManager);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) GroupBinding(org.apache.activemq.artemis.core.server.group.impl.GroupBinding) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) QueueStatusEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) Queue(org.apache.activemq.artemis.core.server.Queue) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Example 2 with QueueStatusEncoding

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding 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 3 with QueueStatusEncoding

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

the class AbstractJournalStorageManager method newQueueStatusEncoding.

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

Example 4 with QueueStatusEncoding

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

the class AbstractJournalStorageManager method storeQueueStatus.

@Override
public long storeQueueStatus(long queueID, QueueStatus status) throws Exception {
    long recordID = idGenerator.generateID();
    readLock();
    try {
        bindingsJournal.appendAddRecord(recordID, JournalRecordIds.QUEUE_STATUS_RECORD, new QueueStatusEncoding(queueID, status), true);
    } finally {
        readUnLock();
    }
    return recordID;
}
Also used : QueueStatusEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding)

Aggregations

QueueStatusEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding)4 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 Filter (org.apache.activemq.artemis.core.filter.Filter)1 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)1 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)1 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)1 QueueBindingInfo (org.apache.activemq.artemis.core.persistence.QueueBindingInfo)1 PersistedAddressSetting (org.apache.activemq.artemis.core.persistence.config.PersistedAddressSetting)1 PersistedRoles (org.apache.activemq.artemis.core.persistence.config.PersistedRoles)1 GroupingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.GroupingEncoding)1 PersistentAddressBindingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding)1 PersistentQueueBindingEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding)1 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)1