Search in sources :

Example 26 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class JMSJournalStorageManagerImpl method addBindings.

@Override
public void addBindings(PersistedType type, String name, String... address) throws Exception {
    Pair<PersistedType, String> key = new Pair<>(type, name);
    long tx = idGenerator.generateID();
    PersistedBindings currentBindings = mapBindings.get(key);
    if (currentBindings != null) {
        jmsJournal.appendDeleteRecordTransactional(tx, currentBindings.getId());
    } else {
        currentBindings = new PersistedBindings(type, name);
    }
    mapBindings.put(key, currentBindings);
    for (String adItem : address) {
        currentBindings.addBinding(adItem);
    }
    long newId = idGenerator.generateID();
    currentBindings.setId(newId);
    jmsJournal.appendAddRecordTransactional(tx, newId, BINDING_RECORD, currentBindings);
    jmsJournal.appendCommitRecord(tx, true);
}
Also used : PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 27 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class JMSJournalStorageManagerImpl method load.

@Override
public void load() throws Exception {
    mapFactories.clear();
    List<RecordInfo> data = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> list = new ArrayList<>();
    jmsJournal.load(data, list, null);
    for (RecordInfo record : data) {
        long id = record.id;
        ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
        byte rec = record.getUserRecordType();
        if (rec == CF_RECORD) {
            PersistedConnectionFactory cf = new PersistedConnectionFactory();
            cf.decode(buffer);
            cf.setId(id);
            mapFactories.put(cf.getName(), cf);
        } else if (rec == DESTINATION_RECORD) {
            PersistedDestination destination = new PersistedDestination();
            destination.decode(buffer);
            destination.setId(id);
            destinations.put(new Pair<>(destination.getType(), destination.getName()), destination);
        } else if (rec == BINDING_RECORD) {
            PersistedBindings bindings = new PersistedBindings();
            bindings.decode(buffer);
            bindings.setId(id);
            Pair<PersistedType, String> key = new Pair<>(bindings.getType(), bindings.getName());
            mapBindings.put(key, bindings);
        } else {
            throw new IllegalStateException("Invalid record type " + rec);
        }
    }
}
Also used : PersistedDestination(org.apache.activemq.artemis.jms.persistence.config.PersistedDestination) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) ArrayList(java.util.ArrayList) PersistedConnectionFactory(org.apache.activemq.artemis.jms.persistence.config.PersistedConnectionFactory) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 28 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class NIOJournalCompactTest method testControlFile.

// General tests
// =============
@Test
public void testControlFile() throws Exception {
    ArrayList<JournalFile> dataFiles = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst");
        dataFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<JournalFile> newFiles = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst.new");
        newFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<Pair<String, String>> renames = new ArrayList<>();
    renames.add(new Pair<>("a", "b"));
    renames.add(new Pair<>("c", "d"));
    AbstractJournalUpdateTask.writeControlFile(fileFactory, dataFiles, newFiles, renames);
    ArrayList<String> strDataFiles = new ArrayList<>();
    ArrayList<String> strNewFiles = new ArrayList<>();
    ArrayList<Pair<String, String>> renamesRead = new ArrayList<>();
    Assert.assertNotNull(JournalCompactor.readControlFile(fileFactory, strDataFiles, strNewFiles, renamesRead));
    Assert.assertEquals(dataFiles.size(), strDataFiles.size());
    Assert.assertEquals(newFiles.size(), strNewFiles.size());
    Assert.assertEquals(renames.size(), renamesRead.size());
    Iterator<String> iterDataFiles = strDataFiles.iterator();
    for (JournalFile file : dataFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterDataFiles.next());
    }
    Assert.assertFalse(iterDataFiles.hasNext());
    Iterator<String> iterNewFiles = strNewFiles.iterator();
    for (JournalFile file : newFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterNewFiles.next());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
    Iterator<Pair<String, String>> iterRename = renames.iterator();
    for (Pair<String, String> rename : renamesRead) {
        Pair<String, String> original = iterRename.next();
        Assert.assertEquals(original.getA(), rename.getA());
        Assert.assertEquals(original.getB(), rename.getB());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) JournalFileImpl(org.apache.activemq.artemis.core.journal.impl.JournalFileImpl) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Example 29 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class ActiveMQTestBase method loadMessageJournal.

/**
 * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
 * independent of being deleted or not
 *
 * @param config
 * @return
 * @throws Exception
 */
protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception {
    JournalImpl messagesJournal = null;
    try {
        SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1);
        messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
        final List<RecordInfo> committedRecords = new LinkedList<>();
        final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
        messagesJournal.start();
        messagesJournal.load(committedRecords, preparedTransactions, null, false);
        return new Pair<>(committedRecords, preparedTransactions);
    } finally {
        try {
            if (messagesJournal != null) {
                messagesJournal.stop();
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) File(java.io.File) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

Pair (org.apache.activemq.artemis.api.core.Pair)29 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 List (java.util.List)6 Map (java.util.Map)6 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)5 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)5 HashSet (java.util.HashSet)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 Message (org.apache.activemq.artemis.api.core.Message)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)3 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)3 PersistedBindings (org.apache.activemq.artemis.jms.persistence.config.PersistedBindings)3 PersistedType (org.apache.activemq.artemis.jms.persistence.config.PersistedType)3