Search in sources :

Example 46 with ActiveMQServerImpl

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

the class EmbeddedActiveMQ method initStart.

protected void initStart() throws Exception {
    if (configuration == null) {
        if (configResourcePath == null)
            configResourcePath = "broker.xml";
        FileDeploymentManager deploymentManager = new FileDeploymentManager(configResourcePath);
        FileConfiguration config = new FileConfiguration();
        deploymentManager.addDeployable(config);
        deploymentManager.readConfiguration();
        configuration = config;
    }
    if (securityManager == null) {
        securityManager = new ActiveMQJAASSecurityManager();
    }
    if (mbeanServer == null) {
        activeMQServer = new ActiveMQServerImpl(configuration, securityManager);
    } else {
        activeMQServer = new ActiveMQServerImpl(configuration, mbeanServer, securityManager);
    }
}
Also used : FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)

Example 47 with ActiveMQServerImpl

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

the class JMSConfigurationTest method testSetupJMSConfiguration.

@Test
public void testSetupJMSConfiguration() throws Exception {
    Context context = new InVMNamingContext();
    ActiveMQServer coreServer = new ActiveMQServerImpl(createDefaultInVMConfig());
    JMSConfiguration jmsConfiguration = new JMSConfigurationImpl();
    TransportConfiguration connectorConfig = new TransportConfiguration(InVMConnectorFactory.class.getName());
    List<TransportConfiguration> transportConfigs = new ArrayList<>();
    transportConfigs.add(connectorConfig);
    ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName(RandomUtil.randomString()).setConnectorNames(registerConnectors(coreServer, transportConfigs)).setBindings("/cf/binding1", "/cf/binding2");
    jmsConfiguration.getConnectionFactoryConfigurations().add(cfConfig);
    JMSQueueConfigurationImpl queueConfig = new JMSQueueConfigurationImpl().setName(RandomUtil.randomString()).setDurable(false).setBindings("/queue/binding1", "/queue/binding2");
    jmsConfiguration.getQueueConfigurations().add(queueConfig);
    TopicConfiguration topicConfig = new TopicConfigurationImpl().setName(RandomUtil.randomString()).setBindings("/topic/binding1", "/topic/binding2");
    jmsConfiguration.getTopicConfigurations().add(topicConfig);
    JMSServerManager server = new JMSServerManagerImpl(coreServer, jmsConfiguration);
    server.setRegistry(new JndiBindingRegistry(context));
    server.start();
    for (String binding : cfConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof ConnectionFactory);
        ConnectionFactory cf = (ConnectionFactory) o;
        Connection connection = cf.createConnection();
        connection.close();
    }
    for (String binding : queueConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Queue);
        Queue queue = (Queue) o;
        Assert.assertEquals(queueConfig.getName(), queue.getQueueName());
    }
    for (String binding : topicConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Topic);
        Topic topic = (Topic) o;
        Assert.assertEquals(topicConfig.getName(), topic.getTopicName());
    }
    server.stop();
}
Also used : InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Context(javax.naming.Context) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) ArrayList(java.util.ArrayList) Connection(javax.jms.Connection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConnectionFactory(javax.jms.ConnectionFactory) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ConnectionFactoryConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) JMSQueueConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) Topic(javax.jms.Topic) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) Queue(javax.jms.Queue) TopicConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Test(org.junit.Test)

Example 48 with ActiveMQServerImpl

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

the class GlobalPagingTest method testPagingOverFullDisk.

@Test
public void testPagingOverFullDisk() throws Exception {
    if (storeType == StoreConfiguration.StoreType.DATABASE)
        return;
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.getConfiguration().setGlobalMaxSize(-1);
    server.start();
    ActiveMQServerImpl serverImpl = (ActiveMQServerImpl) server;
    // stop the scheduled executor, we will do it manually only
    serverImpl.getMonitor().stop();
    serverImpl.getMonitor().tick();
    final int numberOfMessages = 500;
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, false, false);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    final ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message = null;
    final byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    Queue queue = server.locateQueue(ADDRESS);
    queue.getPageSubscription().getPagingStore().forceAnotherPage();
    sendFewMessages(numberOfMessages, session, producer, body);
    // forcing disk full (faking it)
    serverImpl.getMonitor().setMaxUsage(0);
    serverImpl.getMonitor().tick();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                sendFewMessages(numberOfMessages, session, producer, body);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    t.start();
    t.join(1000);
    Assert.assertTrue(t.isAlive());
    // releasing the disk
    serverImpl.getMonitor().setMaxUsage(1).tick();
    t.join(5000);
    Assert.assertFalse(t.isAlive());
    session.start();
    assertEquals(numberOfMessages * 2, getMessageCount(queue));
    // The consumer has to be created after the getMessageCount(queue) assertion
    // otherwise delivery could alter the messagecount and give us a false failure
    ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
    ClientMessage msg = null;
    for (int i = 0; i < numberOfMessages * 2; i++) {
        msg = consumer.receive(1000);
        assertNotNull(msg);
        msg.acknowledge();
        if (i % 500 == 0) {
            session.commit();
        }
    }
    session.commit();
    assertEquals(0, getMessageCount(queue));
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ByteBuffer(java.nio.ByteBuffer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 49 with ActiveMQServerImpl

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

the class ActiveMQServerService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    // Validate whether the AIO native layer can be used
    JournalType jtype = configuration.getJournalType();
    if (jtype == JournalType.ASYNCIO) {
        boolean supportsAIO = AIOSequentialFileFactory.isSupported();
        if (supportsAIO == false) {
            String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
            if (osName.contains("nux")) {
                ROOT_LOGGER.aioInfoLinux();
            } else {
                ROOT_LOGGER.aioInfo();
            }
            configuration.setJournalType(JournalType.NIO);
        }
    }
    // Setup paths
    configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager.get()));
    configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager.get()));
    configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager.get()));
    configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager.get()));
    pathConfig.registerCallbacks(pathManager.get());
    try {
        // Update the acceptor/connector port/host values from the
        // Map the socket bindings onto the connectors/acceptors
        Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
        Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
        Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
        Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
        TransportConfigOperationHandlers.processConnectorBindings(connectors, socketBindings, outboundSocketBindings);
        if (acceptors != null) {
            for (TransportConfiguration tc : acceptors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    SocketBinding binding = socketBindings.get(name).get();
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    InetSocketAddress socketAddress = binding.getSocketAddress();
                    tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
                    tc.getParams().put(PORT, socketAddress.getPort());
                }
            }
        }
        if (broadcastGroups != null) {
            final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<>();
            for (final BroadcastGroupConfiguration config : broadcastGroups) {
                final String name = config.getName();
                final String key = "broadcast" + name;
                if (commandDispatcherFactories.containsKey(key)) {
                    BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
                    String clusterName = clusterNames.get(key);
                    newConfigs.add(JGroupsBroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, commandDispatcherFactory, clusterName));
                } else {
                    final Supplier<SocketBinding> bindingSupplier = groupBindings.get(key);
                    if (bindingSupplier == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
                    }
                    final SocketBinding binding = bindingSupplier.get();
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    newConfigs.add(SocketBroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
                }
            }
            configuration.getBroadcastGroupConfigurations().clear();
            configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
        }
        if (discoveryGroups != null) {
            configuration.setDiscoveryGroupConfigurations(new HashMap<>());
            for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
                final String name = entry.getKey();
                final String key = "discovery" + name;
                final DiscoveryGroupConfiguration config;
                if (commandDispatcherFactories.containsKey(key)) {
                    BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
                    String clusterName = clusterNames.get(key);
                    config = JGroupsDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), commandDispatcherFactory, clusterName);
                } else {
                    final Supplier<SocketBinding> binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                    }
                    config = SocketDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding.get());
                    binding.get().getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding.get()));
                }
                configuration.getDiscoveryGroupConfigurations().put(name, config);
            }
        }
        // security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
        final ActiveMQSecurityManager securityManager;
        if (configuration.isSecurityEnabled()) {
            if (elytronSecurityDomain.isPresent()) {
                securityManager = new ElytronSecurityManager(elytronSecurityDomain.get().get());
            } else {
                securityManager = new WildFlySecurityManager();
            }
        } else {
            securityManager = null;
        }
        // insert possible credential source hold passwords
        setBridgePasswordsFromCredentialSource();
        setClusterPasswordFromCredentialSource();
        if (dataSource.isPresent()) {
            final DataSource ds = dataSource.get().get();
            DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
            dbConfiguration.setDataSource(ds);
            // inject the datasource into the PropertySQLProviderFactory to be able to determine the
            // type of database for the datasource metadata
            PropertySQLProvider.Factory sqlProviderFactory = new PropertySQLProvider.Factory(ds);
            dbConfiguration.setSqlProvider(sqlProviderFactory);
            configuration.setStoreConfiguration(dbConfiguration);
            ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
        }
        final MBeanServer mbs = mbeanServer.isPresent() ? mbeanServer.get().get() : null;
        // Now start the server
        server = new ActiveMQServerImpl(configuration, mbs, securityManager);
        if (ServerDefinition.CLUSTER_PASSWORD.getDefaultValue().asString().equals(server.getConfiguration().getClusterPassword())) {
            server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
        }
        for (Interceptor incomingInterceptor : incomingInterceptors) {
            server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
        }
        for (Interceptor outgoingInterceptor : outgoingInterceptors) {
            server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
        }
    // the server is actually started by the Jakarta Messaging Service.
    } catch (Exception e) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
    } finally {
        org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) BroadcastCommandDispatcherFactory(org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) BroadcastCommandDispatcherFactory(org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) MBeanServer(javax.management.MBeanServer) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) StartException(org.jboss.msc.service.StartException) DataSource(javax.sql.DataSource) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) JournalType(org.apache.activemq.artemis.core.server.JournalType) HashMap(java.util.HashMap) Map(java.util.Map)

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