Search in sources :

Example 1 with NullStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager in project activemq-artemis by apache.

the class ActiveMQServerImpl method createStorageManager.

/**
 * This method is protected as it may be used as a hook for creating a custom storage manager (on tests for instance)
 */
protected StorageManager createStorageManager() {
    if (configuration.isPersistenceEnabled()) {
        if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) {
            JDBCJournalStorageManager journal = new JDBCJournalStorageManager(configuration, getCriticalAnalyzer(), getScheduledPool(), executorFactory, ioExecutorFactory, shutdownOnCriticalIO);
            this.getCriticalAnalyzer().add(journal);
            return journal;
        } else {
            // Default to File Based Storage Manager, (Legacy default configuration).
            JournalStorageManager journal = new JournalStorageManager(configuration, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO);
            this.getCriticalAnalyzer().add(journal);
            return journal;
        }
    }
    return new NullStorageManager();
}
Also used : JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)

Example 2 with NullStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager in project activemq-artemis by apache.

the class PagingStoreImplTest method testConcurrentPaging.

protected void testConcurrentPaging(final SequentialFileFactory factory, final int numberOfThreads) throws Exception {
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    final int MAX_SIZE = 1024 * 10;
    final AtomicLong messageIdGenerator = new AtomicLong(0);
    final AtomicInteger aliveProducers = new AtomicInteger(numberOfThreads);
    final CountDownLatch latchStart = new CountDownLatch(numberOfThreads);
    final ConcurrentHashMap<Long, Message> buffers = new ConcurrentHashMap<>();
    final ArrayList<Page> readPages = new ArrayList<>();
    AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    final PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    // Marked the store to be paged
    storeImpl.startPaging();
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    final SimpleString destination = new SimpleString("test");
    class WriterThread extends Thread {

        Exception e;

        @Override
        public void run() {
            try {
                boolean firstTime = true;
                while (true) {
                    long id = messageIdGenerator.incrementAndGet();
                    // Each thread will Keep paging until all the messages are depaged.
                    // This is possible because the depage thread is not actually reading the pages.
                    // Just using the internal API to remove it from the page file system
                    Message msg = createMessage(id, storeImpl, destination, createRandomBuffer(id, 5));
                    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
                    if (storeImpl.page(msg, ctx2.getTransaction(), ctx2.getContextListing(storeImpl.getStoreName()), lock)) {
                        buffers.put(id, msg);
                    } else {
                        break;
                    }
                    if (firstTime) {
                        // We have at least one data paged. So, we can start depaging now
                        latchStart.countDown();
                        firstTime = false;
                    }
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                this.e = e1;
            } finally {
                aliveProducers.decrementAndGet();
            }
        }
    }
    final class ReaderThread extends Thread {

        Exception e;

        @Override
        public void run() {
            try {
                // Wait every producer to produce at least one message
                ActiveMQTestBase.waitForLatch(latchStart);
                while (aliveProducers.get() > 0) {
                    Page page = storeImpl.depage();
                    if (page != null) {
                        readPages.add(page);
                    }
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                this.e = e1;
            }
        }
    }
    WriterThread[] producerThread = new WriterThread[numberOfThreads];
    for (int i = 0; i < numberOfThreads; i++) {
        producerThread[i] = new WriterThread();
        producerThread[i].start();
    }
    ReaderThread consumer = new ReaderThread();
    consumer.start();
    for (int i = 0; i < numberOfThreads; i++) {
        producerThread[i].join();
        if (producerThread[i].e != null) {
            throw producerThread[i].e;
        }
    }
    consumer.join();
    if (consumer.e != null) {
        throw consumer.e;
    }
    final ConcurrentMap<Long, Message> buffers2 = new ConcurrentHashMap<>();
    for (Page page : readPages) {
        page.open();
        List<PagedMessage> msgs = page.read(new NullStorageManager());
        page.close();
        for (PagedMessage msg : msgs) {
            long id = msg.getMessage().toCore().getBodyBuffer().readLong();
            msg.getMessage().toCore().getBodyBuffer().resetReaderIndex();
            Message msgWritten = buffers.remove(id);
            buffers2.put(id, msg.getMessage());
            Assert.assertNotNull(msgWritten);
            Assert.assertEquals(msg.getMessage().getAddress(), msgWritten.getAddress());
            ActiveMQTestBase.assertEqualsBuffers(10, msgWritten.toCore().getBodyBuffer(), msg.getMessage().toCore().getBodyBuffer());
        }
    }
    Assert.assertEquals(0, buffers.size());
    List<String> files = factory.listFiles("page");
    Assert.assertTrue(files.size() != 0);
    for (String file : files) {
        SequentialFile fileTmp = factory.createSequentialFile(file);
        fileTmp.open();
        Assert.assertTrue("The page file size (" + fileTmp.size() + ") shouldn't be > " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
        fileTmp.close();
    }
    PagingStore storeImpl2 = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
    storeImpl2.start();
    int numberOfPages = storeImpl2.getNumberOfPages();
    Assert.assertTrue(numberOfPages != 0);
    storeImpl2.startPaging();
    storeImpl2.startPaging();
    Assert.assertEquals(numberOfPages, storeImpl2.getNumberOfPages());
    long lastMessageId = messageIdGenerator.incrementAndGet();
    Message lastMsg = createMessage(lastMessageId, storeImpl, destination, createRandomBuffer(lastMessageId, 5));
    storeImpl2.forceAnotherPage();
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    storeImpl2.page(lastMsg, ctx.getTransaction(), ctx.getContextListing(storeImpl2.getStoreName()), lock);
    buffers2.put(lastMessageId, lastMsg);
    Page lastPage = null;
    while (true) {
        Page page = storeImpl2.depage();
        if (page == null) {
            break;
        }
        lastPage = page;
        page.open();
        List<PagedMessage> msgs = page.read(new NullStorageManager());
        page.close();
        for (PagedMessage msg : msgs) {
            long id = msg.getMessage().toCore().getBodyBuffer().readLong();
            Message msgWritten = buffers2.remove(id);
            Assert.assertNotNull(msgWritten);
            Assert.assertEquals(msg.getMessage().getAddress(), msgWritten.getAddress());
            ActiveMQTestBase.assertEqualsByteArrays(msgWritten.toCore().getBodyBuffer().writerIndex(), msgWritten.toCore().getBodyBuffer().toByteBuffer().array(), msg.getMessage().toCore().getBodyBuffer().toByteBuffer().array());
        }
    }
    lastPage.open();
    List<PagedMessage> lastMessages = lastPage.read(new NullStorageManager());
    lastPage.close();
    Assert.assertEquals(1, lastMessages.size());
    lastMessages.get(0).getMessage().toCore().getBodyBuffer().resetReaderIndex();
    Assert.assertEquals(lastMessages.get(0).getMessage().toCore().getBodyBuffer().readLong(), lastMessageId);
    Assert.assertEquals(0, buffers2.size());
    Assert.assertEquals(0, storeImpl.getAddressSize());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) Page(org.apache.activemq.artemis.core.paging.impl.Page) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Example 3 with NullStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager in project activemq-artemis by apache.

the class ManagementServiceImplTest method testGetResources.

@Test
public void testGetResources() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ManagementServiceImpl managementService = new ManagementServiceImpl(null, config);
    managementService.setStorageManager(new NullStorageManager());
    SimpleString address = RandomUtil.randomSimpleString();
    managementService.registerAddress(new AddressInfo(address));
    Queue queue = new FakeQueue(RandomUtil.randomSimpleString());
    managementService.registerQueue(queue, RandomUtil.randomSimpleString(), new FakeStorageManager());
    Object[] addresses = managementService.getResources(AddressControl.class);
    Assert.assertEquals(1, addresses.length);
    Assert.assertTrue(addresses[0] instanceof AddressControl);
    AddressControl addressControl = (AddressControl) addresses[0];
    Assert.assertEquals(address.toString(), addressControl.getAddress());
    Object[] queues = managementService.getResources(QueueControl.class);
    Assert.assertEquals(1, queues.length);
    Assert.assertTrue(queues[0] instanceof QueueControl);
    QueueControl queueControl = (QueueControl) queues[0];
    Assert.assertEquals(queue.getName().toString(), queueControl.getName());
}
Also used : ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) FakeStorageManager(org.apache.activemq.artemis.tests.integration.server.FakeStorageManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 4 with NullStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager in project activemq-artemis by apache.

the class FileMoveManagerTest method testMoveOverPaging.

@Test
public void testMoveOverPaging() throws Exception {
    AssertionLoggerHandler.startCapture();
    ExecutorService threadPool = Executors.newCachedThreadPool();
    try {
        manager.setMaxFolders(3);
        for (int i = 1; i <= 10; i++) {
            HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
            AddressSettings settings = new AddressSettings();
            settings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
            addressSettings.setDefault(settings);
            final StorageManager storageManager = new NullStorageManager();
            PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, dataLocation, 100, null, new OrderedExecutorFactory(threadPool), true, null);
            PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings, -1);
            managerImpl.start();
            PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
            store.startPaging();
            store.stop();
            managerImpl.stop();
            manager.doMove();
            Assert.assertEquals(Math.min(i, manager.getMaxFolders()), manager.getNumberOfFolders());
        }
        Assert.assertFalse("The loggers are complaining about address.txt", AssertionLoggerHandler.findText("address.txt"));
    } finally {
        AssertionLoggerHandler.stopCapture();
        threadPool.shutdown();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ExecutorService(java.util.concurrent.ExecutorService) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) Test(org.junit.Test)

Example 5 with NullStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager in project activemq-artemis by apache.

the class PrintData method printPages.

private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) {
    try {
        ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory());
        final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory());
        ExecutorFactory execfactory = new ExecutorFactory() {

            @Override
            public ArtemisExecutor getExecutor() {
                return ArtemisExecutor.delegate(executor);
            }
        };
        final StorageManager sm = new NullStorageManager();
        PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null);
        HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>();
        addressSettingsRepository.setDefault(new AddressSettings());
        PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
        printPages(describeJournal, sm, manager, out, safe);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)

Aggregations

NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)11 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)7 Page (org.apache.activemq.artemis.core.paging.impl.Page)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 Test (org.junit.Test)6 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)5 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)5 ArrayList (java.util.ArrayList)4 Message (org.apache.activemq.artemis.api.core.Message)4 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)4 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)4 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)4 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)3 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)3 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)3 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)3