Search in sources :

Example 1 with QueueBindingInfo

use of org.apache.activemq.artemis.core.persistence.QueueBindingInfo in project activemq-artemis by apache.

the class AbstractJournalStorageManager method locateSubscription.

/**
 * @param queueID
 * @param pageSubscriptions
 * @param queueInfos
 * @return
 */
private static PageSubscription locateSubscription(final long queueID, final Map<Long, PageSubscription> pageSubscriptions, final Map<Long, QueueBindingInfo> queueInfos, final PagingManager pagingManager) throws Exception {
    PageSubscription subs = pageSubscriptions.get(queueID);
    if (subs == null) {
        QueueBindingInfo queueInfo = queueInfos.get(queueID);
        if (queueInfo != null) {
            SimpleString address = queueInfo.getAddress();
            PagingStore store = pagingManager.getPageStore(address);
            subs = store.getCursorProvider().getSubscription(queueID);
            pageSubscriptions.put(queueID, subs);
        }
    }
    return subs;
}
Also used : QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Example 2 with QueueBindingInfo

use of org.apache.activemq.artemis.core.persistence.QueueBindingInfo in project activemq-artemis by apache.

the class ActiveMQServerImpl method loadJournals.

private JournalLoadInformation[] loadJournals() throws Exception {
    JournalLoader journalLoader = activation.createJournalLoader(postOffice, pagingManager, storageManager, queueFactory, nodeManager, managementService, groupingHandler, configuration, parentServer);
    JournalLoadInformation[] journalInfo = new JournalLoadInformation[2];
    List<QueueBindingInfo> queueBindingInfos = new ArrayList<>();
    List<GroupingInfo> groupingInfos = new ArrayList<>();
    List<AddressBindingInfo> addressBindingInfos = new ArrayList<>();
    journalInfo[0] = storageManager.loadBindingJournal(queueBindingInfos, groupingInfos, addressBindingInfos);
    recoverStoredConfigs();
    Map<Long, AddressBindingInfo> addressBindingInfosMap = new HashMap<>();
    journalLoader.initAddresses(addressBindingInfosMap, addressBindingInfos);
    Map<Long, QueueBindingInfo> queueBindingInfosMap = new HashMap<>();
    journalLoader.initQueues(queueBindingInfosMap, queueBindingInfos);
    journalLoader.handleGroupingBindings(groupingInfos);
    Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap = new HashMap<>();
    HashSet<Pair<Long, Long>> pendingLargeMessages = new HashSet<>();
    List<PageCountPending> pendingNonTXPageCounter = new LinkedList<>();
    journalInfo[1] = storageManager.loadMessageJournal(postOffice, pagingManager, resourceManager, queueBindingInfosMap, duplicateIDMap, pendingLargeMessages, pendingNonTXPageCounter, journalLoader);
    journalLoader.handleDuplicateIds(duplicateIDMap);
    for (Pair<Long, Long> msgToDelete : pendingLargeMessages) {
        ActiveMQServerLogger.LOGGER.deletingPendingMessage(msgToDelete);
        LargeServerMessage msg = storageManager.createLargeMessage();
        msg.setMessageID(msgToDelete.getB());
        msg.setPendingRecordID(msgToDelete.getA());
        msg.setDurable(true);
        msg.deleteFile();
    }
    if (pendingNonTXPageCounter.size() != 0) {
        try {
            journalLoader.recoverPendingPageCounters(pendingNonTXPageCounter);
        } catch (Throwable e) {
            ActiveMQServerLogger.LOGGER.errorRecoveringPageCounter(e);
        }
    }
    journalLoader.cleanUp();
    return journalInfo;
}
Also used : PageCountPending(org.apache.activemq.artemis.core.persistence.impl.PageCountPending) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.apache.activemq.artemis.api.core.Pair) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) HashSet(java.util.HashSet) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) LinkedList(java.util.LinkedList) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage)

Example 3 with QueueBindingInfo

use of org.apache.activemq.artemis.core.persistence.QueueBindingInfo 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 4 with QueueBindingInfo

use of org.apache.activemq.artemis.core.persistence.QueueBindingInfo in project activemq-artemis by apache.

the class DeleteMessagesOnStartupTest method testDeleteMessagesOnStartup.

@Test
public void testDeleteMessagesOnStartup() throws Exception {
    createStorage();
    Queue theQueue = new FakeQueue(new SimpleString(""));
    HashMap<Long, Queue> queues = new HashMap<>();
    queues.put(100L, theQueue);
    Message msg = new CoreMessage(1, 100);
    journal.storeMessage(msg);
    for (int i = 2; i < 100; i++) {
        journal.storeMessage(new CoreMessage(i, 100));
    }
    journal.storeReference(100, 1, true);
    journal.stop();
    journal.start();
    journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
    FakePostOffice postOffice = new FakePostOffice();
    journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new PostOfficeJournalLoader(postOffice, null, journal, null, null, null, null, null, queues));
    Assert.assertEquals(98, deletedMessage.size());
    for (Long messageID : deletedMessage) {
        Assert.assertTrue("messageID = " + messageID, messageID.longValue() >= 2 && messageID <= 99);
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) Test(org.junit.Test)

Example 5 with QueueBindingInfo

use of org.apache.activemq.artemis.core.persistence.QueueBindingInfo in project activemq-artemis by apache.

the class StorageManagerTestBase method createStorage.

/**
 * @throws Exception
 */
protected void createStorage() throws Exception {
    if (storeType == StoreConfiguration.StoreType.DATABASE) {
        journal = createJDBCJournalStorageManager(createDefaultJDBCConfig(true));
    } else {
        journal = createJournalStorageManager(createDefaultInVMConfig());
    }
    journal.start();
    journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
    journal.loadMessageJournal(new FakePostOffice(), null, null, null, null, null, null, new FakeJournalLoader());
}
Also used : GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) FakeJournalLoader(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo)

Aggregations

QueueBindingInfo (org.apache.activemq.artemis.core.persistence.QueueBindingInfo)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 AddressBindingInfo (org.apache.activemq.artemis.core.persistence.AddressBindingInfo)5 GroupingInfo (org.apache.activemq.artemis.core.persistence.GroupingInfo)5 FakePostOffice (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 List (java.util.List)2 Pair (org.apache.activemq.artemis.api.core.Pair)2 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)2 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)2 Queue (org.apache.activemq.artemis.core.server.Queue)2 PostOfficeJournalLoader (org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader)2 FakeJournalLoader (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1