Search in sources :

Example 11 with SequentialFileFactory

use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.

the class ActiveMQTestBase method countBindingJournal.

protected HashMap<Integer, AtomicInteger> countBindingJournal(Configuration config) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
    JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
    List<JournalFile> filesToRead = messagesJournal.orderFiles();
    for (JournalFile file : filesToRead) {
        JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
    }
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 12 with SequentialFileFactory

use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method newFileFactory.

@Override
public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception {
    String tableName = "" + storageManager.generateID();
    SequentialFileFactory factory = newFileFactory(tableName, true);
    factory.start();
    SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE);
    file.open();
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address));
    buffer.writeSimpleString(address);
    file.write(buffer, true);
    file.close();
    return factory;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 13 with SequentialFileFactory

use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryNIO method reloadStores.

@Override
public List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception {
    File[] files = directory.listFiles();
    if (files == null) {
        return Collections.<PagingStore>emptyList();
    } else {
        ArrayList<PagingStore> storesReturn = new ArrayList<>(files.length);
        for (File file : files) {
            final String guid = file.getName();
            final File addressFile = new File(file, PagingStoreFactoryNIO.ADDRESS_FILE);
            if (!addressFile.exists()) {
                // This means this folder is from a replication copy, nothing to worry about it, we just skip it
                if (!file.getName().contains(FileMoveManager.PREFIX)) {
                    ActiveMQServerLogger.LOGGER.pageStoreFactoryNoIdFile(file.toString(), PagingStoreFactoryNIO.ADDRESS_FILE);
                }
                continue;
            }
            String addressString;
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(addressFile)))) {
                addressString = reader.readLine();
            }
            SimpleString address = new SimpleString(addressString);
            SequentialFileFactory factory = newFileFactory(guid);
            AddressSettings settings = addressSettingsRepository.getMatch(address.toString());
            PagingStore store = new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, factory, this, address, settings, executorFactory.getExecutor(), syncNonTransactional);
            storesReturn.add(store);
        }
        return storesReturn;
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FileInputStream(java.io.FileInputStream) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) BufferedReader(java.io.BufferedReader) File(java.io.File) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Example 14 with SequentialFileFactory

use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryNIO method newFileFactory.

@Override
public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception {
    String guid = UUIDGenerator.getInstance().generateStringUUID();
    SequentialFileFactory factory = newFileFactory(guid);
    factory.createDirs();
    File fileWithID = new File(directory, guid + File.separatorChar + PagingStoreFactoryNIO.ADDRESS_FILE);
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileWithID)))) {
        writer.write(address.toString());
        writer.newLine();
    }
    return factory;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) File(java.io.File) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) BufferedWriter(java.io.BufferedWriter)

Example 15 with SequentialFileFactory

use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.

the class HangConsumerTest method testDuplicateDestinationsOnTopic.

/**
 * This will simulate what would happen with topic creationg where a single record is supposed to be created on the journal
 *
 * @throws Exception
 */
@Test
public void testDuplicateDestinationsOnTopic() throws Exception {
    try {
        for (int i = 0; i < 5; i++) {
            if (server.locateQueue(SimpleString.toSimpleString("tt")) == null) {
                server.createQueue(SimpleString.toSimpleString("tt"), RoutingType.ANYCAST, SimpleString.toSimpleString("tt"), SimpleString.toSimpleString(Filter.GENERIC_IGNORED_FILTER), true, false);
            }
            server.stop();
            SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null, 1);
            JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 2, 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
            messagesJournal.start();
            LinkedList<RecordInfo> infos = new LinkedList<>();
            messagesJournal.load(infos, null, null);
            int bindings = 0;
            for (RecordInfo info : infos) {
                System.out.println("info: " + info);
                if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
                    bindings++;
                }
            }
            assertEquals(1, bindings);
            System.out.println("Bindings: " + bindings);
            messagesJournal.stop();
            if (i < 4)
                server.start();
        }
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Aggregations

SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)30 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)25 Test (org.junit.Test)16 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)13 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)10 File (java.io.File)9 ArrayList (java.util.ArrayList)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)8 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)5 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)5 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4