Search in sources :

Example 11 with StorageManager

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

the class PagingCounterTest method testPrepareCounter.

@Test
public void testPrepareCounter() throws Exception {
    Xid xid = newXID();
    Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
    PageSubscriptionCounter counter = locateCounter(queue);
    StorageManager storage = server.getStorageManager();
    Transaction tx = new TransactionImpl(xid, server.getStorageManager(), 300);
    for (int i = 0; i < 2000; i++) {
        counter.increment(tx, 1, 1000);
    }
    assertEquals(0, counter.getValue());
    tx.prepare();
    storage.waitOnOperations();
    assertEquals(0, counter.getValue());
    server.stop();
    server = newActiveMQServer();
    server.start();
    storage = server.getStorageManager();
    queue = server.locateQueue(new SimpleString("A1"));
    assertNotNull(queue);
    counter = locateCounter(queue);
    tx = server.getResourceManager().removeTransaction(xid);
    assertNotNull(tx);
    assertEquals(0, counter.getValue());
    tx.commit(false);
    storage.waitOnOperations();
    assertEquals(2000, counter.getValue());
}
Also used : Xid(javax.transaction.xa.Xid) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 12 with StorageManager

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

the class PagingCounterTest method testCounter.

@Test
public void testCounter() throws Exception {
    ClientSessionFactory sf = createSessionFactory(sl);
    ClientSession session = sf.createSession();
    try {
        server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
        Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
        PageSubscriptionCounter counter = locateCounter(queue);
        StorageManager storage = server.getStorageManager();
        Transaction tx = new TransactionImpl(server.getStorageManager());
        counter.increment(tx, 1, 1000);
        assertEquals(0, counter.getValue());
        assertEquals(0, counter.getPersistentSize());
        tx.commit();
        storage.waitOnOperations();
        assertEquals(1, counter.getValue());
        assertEquals(1000, counter.getPersistentSize());
    } finally {
        sf.close();
        session.close();
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 13 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager 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)

Example 14 with StorageManager

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

the class PagingManagerImplTest method testPagingManager.

@Test
public void testPagingManager() throws Exception {
    HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
    addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
    final StorageManager storageManager = new NullStorageManager();
    PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
    PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
    managerImpl.start();
    PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
    ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    store.startPaging();
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    page.close();
    Assert.assertEquals(1, msgs.size());
    ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) 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) Page(org.apache.activemq.artemis.core.paging.impl.Page) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Test(org.junit.Test)

Example 15 with StorageManager

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

the class StompSession method sendInternalLarge.

public void sendInternalLarge(CoreMessage message, boolean direct) throws Exception {
    int headerSize = message.getHeadersAndPropertiesEncodeSize();
    if (headerSize >= connection.getMinLargeMessageSize()) {
        throw BUNDLE.headerTooBig();
    }
    StorageManager storageManager = ((ServerSessionImpl) session).getStorageManager();
    long id = storageManager.generateID();
    LargeServerMessage largeMessage = storageManager.createLargeMessage(id, message);
    ActiveMQBuffer body = message.getReadOnlyBodyBuffer();
    byte[] bytes = new byte[body.readableBytes()];
    body.readBytes(bytes);
    largeMessage.addBytes(bytes);
    largeMessage.releaseResources();
    largeMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, bytes.length);
    session.send(largeMessage, direct);
    largeMessage = null;
}
Also used : StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ServerSessionImpl(org.apache.activemq.artemis.core.server.impl.ServerSessionImpl) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)22 Test (org.junit.Test)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)15 Queue (org.apache.activemq.artemis.core.server.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)7 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)5 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)5 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)5 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)5 ExecutorService (java.util.concurrent.ExecutorService)4 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)4 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)4