Search in sources :

Example 46 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class PagingOrderTest method testPagingOverCreatedDestinationQueues.

@Test
public void testPagingOverCreatedDestinationQueues() throws Exception {
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
    server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    server.getActiveMQServerControl().addAddressSettings("Q1", "DLQ", "DLQ", -1, false, 5, 100 * 1024, 10 * 1024, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);
    jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");
    MessageProducer prod = sess.createProducer(queue);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    BytesMessage bmt = sess.createBytesMessage();
    bmt.writeBytes(new byte[1024]);
    for (int i = 0; i < 500; i++) {
        prod.send(bmt);
    }
    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
    jmsServer.stop();
    server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
    server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    AddressSettings settings = server.getAddressSettingsRepository().getMatch("Q1");
    assertEquals(100 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());
    store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) BytesMessage(javax.jms.BytesMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 47 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class AMQPSessionCallback method offerProducerCredit.

public void offerProducerCredit(final SimpleString address, final int credits, final int threshold, final Receiver receiver) {
    try {
        if (address == null) {
            connection.lock();
            try {
                receiver.flow(credits);
            } finally {
                connection.unlock();
            }
            connection.flush();
            return;
        }
        final PagingStore store = manager.getServer().getPagingManager().getPageStore(address);
        store.checkMemory(new Runnable() {

            @Override
            public void run() {
                connection.lock();
                try {
                    if (receiver.getRemoteCredit() <= threshold) {
                        receiver.flow(credits);
                    }
                } finally {
                    connection.unlock();
                }
                connection.flush();
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)

Example 48 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.

the class AMQPSessionCallback method serverSend.

public void serverSend(final ProtonServerReceiverContext context, final Transaction transaction, final Receiver receiver, final Delivery delivery, SimpleString address, int messageFormat, byte[] data) throws Exception {
    AMQPMessage message = new AMQPMessage(messageFormat, data, coreMessageObjectPools);
    if (address != null) {
        message.setAddress(address);
    } else {
        // Anonymous relay must set a To value
        address = message.getAddressSimpleString();
        if (address == null) {
            rejectMessage(delivery, Symbol.valueOf("failed"), "Missing 'to' field for message sent to an anonymous producer");
            return;
        }
    }
    // here check queue-autocreation
    RoutingType routingType = context.getRoutingType(receiver, address);
    if (!bindingQuery(address, routingType)) {
        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
    }
    OperationContext oldcontext = recoverContext();
    try {
        PagingStore store = manager.getServer().getPagingManager().getPageStore(message.getAddressSimpleString());
        if (store.isRejectingMessages()) {
            // We drop pre-settled messages (and abort any associated Tx)
            if (delivery.remotelySettled()) {
                if (transaction != null) {
                    String amqpAddress = delivery.getLink().getTarget().getAddress();
                    ActiveMQException e = new ActiveMQAMQPResourceLimitExceededException("Address is full: " + amqpAddress);
                    transaction.markAsRollbackOnly(e);
                }
            } else {
                rejectMessage(delivery, AmqpError.RESOURCE_LIMIT_EXCEEDED, "Address is full: " + address);
            }
        } else {
            serverSend(transaction, message, delivery, receiver);
        }
    } finally {
        resetContext(oldcontext);
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Aggregations

PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)48 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)24 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)17 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)17 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)17 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)16 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)15 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)15 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)11 HashMap (java.util.HashMap)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)9 Queue (org.apache.activemq.artemis.core.server.Queue)9 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)8 ArrayList (java.util.ArrayList)7 Page (org.apache.activemq.artemis.core.paging.impl.Page)6