Search in sources :

Example 1 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class FileJMSConfiguration method buildService.

@Override
public void buildService(ActiveMQSecurityManager securityManager, MBeanServer mBeanServer, Map<String, Deployable> deployables, Map<String, ActiveMQComponent> components) throws Exception {
    ActiveMQServerImpl server = (ActiveMQServerImpl) components.get("core");
    components.put(CONFIGURATION_SCHEMA_ROOT_ELEMENT, new JMSServerManagerImpl(server, this));
}
Also used : JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)

Example 2 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class HangConsumerTest method testHangDuplicateQueues.

/**
 * This would recreate the scenario where a queue was duplicated
 *
 * @throws Exception
 */
@Test
public void testHangDuplicateQueues() throws Exception {
    final Semaphore blocked = new Semaphore(1);
    final CountDownLatch latchDelete = new CountDownLatch(1);
    class MyQueueWithBlocking extends QueueImpl {

        /**
         * @param id
         * @param address
         * @param name
         * @param filter
         * @param pageSubscription
         * @param durable
         * @param temporary
         * @param scheduledExecutor
         * @param postOffice
         * @param storageManager
         * @param addressSettingsRepository
         * @param executor
         */
        MyQueueWithBlocking(final long id, final SimpleString address, final SimpleString name, final Filter filter, final SimpleString user, final PageSubscription pageSubscription, final boolean durable, final boolean temporary, final boolean autoCreated, final RoutingType deliveryMode, final Integer maxConsumers, final Boolean purgeOnNoConsumers, final ScheduledExecutorService scheduledExecutor, final PostOffice postOffice, final StorageManager storageManager, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final ArtemisExecutor executor, final ActiveMQServer server) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, deliveryMode, maxConsumers, purgeOnNoConsumers, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, null);
        }

        @Override
        public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter) throws Exception {
            latchDelete.countDown();
            blocked.acquire();
            blocked.release();
            return super.deleteMatchingReferences(flushLimit, filter);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    class LocalFactory extends QueueFactoryImpl {

        LocalFactory(final ExecutorFactory executorFactory, final ScheduledExecutorService scheduledExecutor, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final StorageManager storageManager, final ActiveMQServer server) {
            super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager, server);
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            queue = new MyQueueWithBlocking(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), config.deliveryMode(), config.maxConsumers(), config.isPurgeOnNoConsumers(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }

        @Deprecated
        @Override
        public Queue createQueue(final long persistenceID, final SimpleString address, final SimpleString name, final Filter filter, final PageSubscription pageSubscription, final SimpleString user, final boolean durable, final boolean temporary, final boolean autoCreated) {
            queue = new MyQueueWithBlocking(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }
    }
    LocalFactory queueFactory = new LocalFactory(server.getExecutorFactory(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getStorageManager(), server);
    queueFactory.setPostOffice(server.getPostOffice());
    ((ActiveMQServerImpl) server).replaceQueueFactory(queueFactory);
    queue = server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    blocked.acquire();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ClientProducer producer = session.createProducer(QUEUE);
    producer.send(session.createMessage(true));
    session.commit();
    Thread tDelete = new Thread() {

        @Override
        public void run() {
            try {
                server.destroyQueue(QUEUE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    tDelete.start();
    Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));
    try {
        server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    } catch (Exception expected) {
    }
    blocked.release();
    server.stop();
    tDelete.join();
    session.close();
    // a duplicate binding would impede the server from starting
    server.start();
    waitForServerToStart(server);
    server.stop();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) Semaphore(java.util.concurrent.Semaphore) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) QueueFactoryImpl(org.apache.activemq.artemis.core.server.impl.QueueFactoryImpl) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) Test(org.junit.Test)

Example 3 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class InterruptedLargeMessageTest method testRestartBeforeDelete.

@Test
public void testRestartBeforeDelete() throws Exception {
    class NoPostACKQueue extends QueueImpl {

        NoPostACKQueue(long id, SimpleString address, SimpleString name, Filter filter, SimpleString user, PageSubscription pageSubscription, boolean durable, boolean temporary, boolean autoCreated, ScheduledExecutorService scheduledExecutor, PostOffice postOffice, StorageManager storageManager, HierarchicalRepository<AddressSettings> addressSettingsRepository, ArtemisExecutor executor) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, null, null);
        }

        @Override
        public void postAcknowledge(final MessageReference ref) {
            System.out.println("Ignoring postACK on message " + ref);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    final class NoPostACKQueueFactory implements QueueFactory {

        final StorageManager storageManager;

        final PostOffice postOffice;

        final ScheduledExecutorService scheduledExecutor;

        final HierarchicalRepository<AddressSettings> addressSettingsRepository;

        final ExecutorFactory execFactory;

        NoPostACKQueueFactory(StorageManager storageManager, PostOffice postOffice, ScheduledExecutorService scheduledExecutor, HierarchicalRepository<AddressSettings> addressSettingsRepository, final ExecutorFactory execFactory) {
            this.storageManager = storageManager;
            this.postOffice = postOffice;
            this.scheduledExecutor = scheduledExecutor;
            this.addressSettingsRepository = addressSettingsRepository;
            this.execFactory = execFactory;
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            return new NoPostACKQueue(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        @Deprecated
        @Override
        public Queue createQueue(long persistenceID, SimpleString address, SimpleString name, Filter filter, PageSubscription pageSubscription, SimpleString user, boolean durable, boolean temporary, boolean autoCreated) {
            return new NoPostACKQueue(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        /* (non-Javadoc)
          * @see org.apache.activemq.artemis.core.server.QueueFactory#setPostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)
          */
        @Override
        public void setPostOffice(PostOffice postOffice) {
        }
    }
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    QueueFactory original = server.getQueueFactory();
    ((ActiveMQServerImpl) server).replaceQueueFactory(new NoPostACKQueueFactory(server.getStorageManager(), server.getPostOffice(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getExecutorFactory()));
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = cons.receive(5000);
        Assert.assertNotNull(msg);
        msg.saveToOutputStream(new java.io.OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        });
        msg.acknowledge();
        session.commit();
    }
    ((ActiveMQServerImpl) server).replaceQueueFactory(original);
    server.fail(false);
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) IOException(java.io.IOException) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 4 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class DivertTest method testInjectedTransformer.

@Test
public void testInjectedTransformer() throws Exception {
    final SimpleString ADDRESS = new SimpleString("myAddress");
    final String DIVERT = "myDivert";
    ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl();
    Transformer transformer = new Transformer() {

        @Override
        public Message transform(Message message) {
            return null;
        }
    };
    serviceRegistry.addDivertTransformer(DIVERT, transformer);
    ActiveMQServer server = addServer(new ActiveMQServerImpl(null, null, null, null, serviceRegistry));
    server.start();
    server.waitForActivation(100, TimeUnit.MILLISECONDS);
    server.createQueue(ADDRESS, RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, false, false);
    server.deployDivert(new DivertConfiguration().setName(DIVERT).setAddress(ADDRESS.toString()).setForwardingAddress(ADDRESS.toString()));
    Collection<Binding> bindings = server.getPostOffice().getBindingsForAddress(ADDRESS).getBindings();
    Divert divert = null;
    for (Binding binding : bindings) {
        if (binding instanceof DivertBinding) {
            divert = ((DivertBinding) binding).getDivert();
        }
    }
    assertNotNull(divert);
    assertEquals(transformer, divert.getTransformer());
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceRegistryImpl(org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Divert(org.apache.activemq.artemis.core.server.Divert) Test(org.junit.Test)

Example 5 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class ShutdownServerTest method testShutdownServer.

@Test
public void testShutdownServer() throws Throwable {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true, false);
    session.createQueue(QUEUE, QUEUE, null, true);
    ClientConsumer consumer = session.createConsumer(QUEUE);
    ClientProducer producer = session.createProducer(QUEUE);
    ClientMessage message = session.createMessage(Message.TEXT_TYPE, true, 0, System.currentTimeMillis(), (byte) 4);
    message.getBodyBuffer().writeString("hi");
    message.putStringProperty("hello", "elo");
    producer.send(message);
    ActiveMQServerImpl impl = (ActiveMQServerImpl) server;
    JournalStorageManager journal = (JournalStorageManager) impl.getStorageManager();
    JDBCJournalImpl journalimpl = (JDBCJournalImpl) journal.getMessageJournal();
    journalimpl.handleException(null, new Exception("failure"));
    Wait.waitFor(() -> !server.isStarted());
    Assert.assertFalse(server.isStarted());
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JDBCJournalImpl(org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Aggregations

ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)49 Test (org.junit.Test)35 Configuration (org.apache.activemq.artemis.core.config.Configuration)28 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)19 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)16 Activation (org.apache.activemq.artemis.core.server.impl.Activation)16 SharedNothingBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)16 HAPolicy (org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy)15 ColocatedActivation (org.apache.activemq.artemis.core.server.impl.ColocatedActivation)15 LiveOnlyActivation (org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation)15 SharedNothingLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation)15 SharedStoreBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation)15 SharedStoreLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation)15 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)14 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ScaleDownPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy)9 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)8