Search in sources :

Example 6 with TransportConfiguration

use of org.apache.activemq.artemis.api.core.TransportConfiguration in project spring-boot by spring-projects.

the class ArtemisConnectionFactoryFactory method createNativeConnectionFactory.

private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Class<T> factoryClass) throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.HOST_PROP_NAME, this.properties.getHost());
    params.put(TransportConstants.PORT_PROP_NAME, this.properties.getPort());
    TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
    Constructor<T> constructor = factoryClass.getConstructor(boolean.class, TransportConfiguration[].class);
    T connectionFactory = constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
    String user = this.properties.getUser();
    if (StringUtils.hasText(user)) {
        connectionFactory.setUser(user);
        connectionFactory.setPassword(this.properties.getPassword());
    }
    return connectionFactory;
}
Also used : NettyConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory) HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 7 with TransportConfiguration

use of org.apache.activemq.artemis.api.core.TransportConfiguration in project spring-boot by spring-projects.

the class ArtemisEmbeddedConfigurationFactory method createConfiguration.

public Configuration createConfiguration() {
    ConfigurationImpl configuration = new ConfigurationImpl();
    configuration.setSecurityEnabled(false);
    configuration.setPersistenceEnabled(this.properties.isPersistent());
    String dataDir = getDataDir();
    configuration.setJournalDirectory(dataDir + "/journal");
    if (this.properties.isPersistent()) {
        configuration.setJournalType(JournalType.NIO);
        configuration.setLargeMessagesDirectory(dataDir + "/largemessages");
        configuration.setBindingsDirectory(dataDir + "/bindings");
        configuration.setPagingDirectory(dataDir + "/paging");
    }
    TransportConfiguration transportConfiguration = new TransportConfiguration(InVMAcceptorFactory.class.getName(), this.properties.generateTransportParameters());
    configuration.getAcceptorConfigurations().add(transportConfiguration);
    if (this.properties.isDefaultClusterPassword()) {
        logger.debug("Using default Artemis cluster password: " + this.properties.getClusterPassword());
    }
    configuration.setClusterPassword(this.properties.getClusterPassword());
    return configuration;
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory)

Example 8 with TransportConfiguration

use of org.apache.activemq.artemis.api.core.TransportConfiguration in project wildfly by wildfly.

the class ActiveMQServerService method start.

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
    PathManager pathManager = this.pathManager.getValue();
    configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager));
    configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager));
    configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager));
    configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager));
    pathConfig.registerCallbacks(pathManager);
    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();
        if (connectors != null) {
            for (TransportConfiguration tc : connectors) {
                // 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();
                    String host;
                    int port;
                    OutboundSocketBinding binding = outboundSocketBindings.get(name);
                    if (binding == null) {
                        final SocketBinding socketBinding = socketBindings.get(name);
                        if (socketBinding == null) {
                            throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                        }
                        InetSocketAddress sa = socketBinding.getSocketAddress();
                        port = sa.getPort();
                        // resolve the host name of the address only if a loopback address has been set
                        if (sa.getAddress().isLoopbackAddress()) {
                            host = NetworkUtils.canonize(sa.getAddress().getHostName());
                        } else {
                            host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
                        }
                    } else {
                        port = binding.getDestinationPort();
                        host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
                        if (binding.getSourceAddress() != null) {
                            tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
                        }
                        if (binding.getSourcePort() != null) {
                            // Use absolute port to account for source port offset/fixation
                            tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
                        }
                    }
                    tc.getParams().put(HOST, host);
                    tc.getParams().put(PORT, port);
                }
            }
        }
        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);
                    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<BroadcastGroupConfiguration>();
            for (final BroadcastGroupConfiguration config : broadcastGroups) {
                final String name = config.getName();
                final String key = "broadcast" + name;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = (JChannel) channelFactory.createChannel(channelName);
                    channels.put(channelName, channel);
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, channel, channelName));
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
                }
            }
            configuration.getBroadcastGroupConfigurations().clear();
            configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
        }
        if (discoveryGroups != null) {
            configuration.setDiscoveryGroupConfigurations(new HashMap<String, DiscoveryGroupConfiguration>());
            for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
                final String name = entry.getKey();
                final String key = "discovery" + name;
                DiscoveryGroupConfiguration config = null;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = channels.get(channelName);
                    if (channel == null) {
                        channel = (JChannel) channelFactory.createChannel(key);
                        channels.put(channelName, channel);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), channel, channelName);
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding);
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                }
                configuration.getDiscoveryGroupConfigurations().put(name, config);
            }
        }
        // security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
        ActiveMQSecurityManager securityManager = null;
        final SecurityDomain elytronDomain = this.elytronSecurityDomain.getOptionalValue();
        if (elytronDomain != null) {
            securityManager = new ElytronSecurityManager(elytronDomain);
        } else {
            securityManager = new WildFlySecurityManager(securityDomainContextValue.getValue());
        }
        // insert possible credential source hold passwords
        setBridgePasswordsFromCredentialSource();
        setClusterPasswordFromCredentialSource();
        DataSource ds = dataSource.getOptionalValue();
        if (ds != null) {
            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
            PropertySQLProviderFactory sqlProviderFactory = (PropertySQLProviderFactory) dbConfiguration.getSqlProviderFactory();
            sqlProviderFactory.investigateDialect(ds);
            configuration.setStoreConfiguration(dbConfiguration);
            ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
        }
        // Now start the server
        server = new ActiveMQServerImpl(configuration, mbeanServer.getOptionalValue(), securityManager);
        if (ActiveMQDefaultConfiguration.getDefaultClusterPassword().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 JMSService.
    } 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) JChannel(org.jgroups.JChannel) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) 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) PathManager(org.jboss.as.controller.services.path.PathManager) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with TransportConfiguration

use of org.apache.activemq.artemis.api.core.TransportConfiguration in project wildfly by wildfly.

the class PooledConnectionFactoryService method createService.

private void createService(ServiceTarget serviceTarget, ServiceContainer container) throws Exception {
    InputStream is = null;
    InputStream isIj = null;
    List<ConfigProperty> properties = new ArrayList<ConfigProperty>();
    try {
        StringBuilder connectorClassname = new StringBuilder();
        StringBuilder connectorParams = new StringBuilder();
        // pick the first connector available if pickAnyConnectors is true
        if (discoveryGroupName == null && connectors.isEmpty() && pickAnyConnectors) {
            Set<String> connectorNames = activeMQServer.getValue().getConfiguration().getConnectorConfigurations().keySet();
            if (connectorNames.size() > 0) {
                String connectorName = connectorNames.iterator().next();
                MessagingLogger.ROOT_LOGGER.connectorForPooledConnectionFactory(name, connectorName);
                connectors.add(connectorName);
            }
        }
        for (String connector : connectors) {
            TransportConfiguration tc = activeMQServer.getValue().getConfiguration().getConnectorConfigurations().get(connector);
            if (tc == null) {
                throw MessagingLogger.ROOT_LOGGER.connectorNotDefined(connector);
            }
            if (connectorClassname.length() > 0) {
                connectorClassname.append(",");
                connectorParams.append(",");
            }
            connectorClassname.append(tc.getFactoryClassName());
            Map<String, Object> params = tc.getParams();
            boolean multiple = false;
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                if (multiple) {
                    connectorParams.append(";");
                }
                connectorParams.append(entry.getKey()).append("=").append(entry.getValue());
                multiple = true;
            }
        }
        if (connectorClassname.length() > 0) {
            properties.add(simpleProperty15(CONNECTOR_CLASSNAME, STRING_TYPE, connectorClassname.toString()));
        }
        if (connectorParams.length() > 0) {
            properties.add(simpleProperty15(CONNECTION_PARAMETERS, STRING_TYPE, connectorParams.toString()));
        }
        if (discoveryGroupName != null) {
            DiscoveryGroupConfiguration discoveryGroupConfiguration = activeMQServer.getValue().getConfiguration().getDiscoveryGroupConfigurations().get(discoveryGroupName);
            BroadcastEndpointFactory bgCfg = discoveryGroupConfiguration.getBroadcastEndpointFactory();
            if (bgCfg instanceof UDPBroadcastEndpointFactory) {
                UDPBroadcastEndpointFactory udpCfg = (UDPBroadcastEndpointFactory) bgCfg;
                properties.add(simpleProperty15(GROUP_ADDRESS, STRING_TYPE, udpCfg.getGroupAddress()));
                properties.add(simpleProperty15(GROUP_PORT, INTEGER_TYPE, "" + udpCfg.getGroupPort()));
                properties.add(simpleProperty15(DISCOVERY_LOCAL_BIND_ADDRESS, STRING_TYPE, "" + udpCfg.getLocalBindAddress()));
            } else if (bgCfg instanceof ChannelBroadcastEndpointFactory) {
                properties.add(simpleProperty15(JGROUPS_CHANNEL_LOCATOR_CLASS, STRING_TYPE, JGroupsChannelLocator.class.getName()));
                properties.add(simpleProperty15(JGROUPS_CHANNEL_NAME, STRING_TYPE, jgroupsChannelName));
                properties.add(simpleProperty15(JGROUPS_CHANNEL_REF_NAME, STRING_TYPE, serverName + '/' + jgroupsChannelName));
            }
            properties.add(simpleProperty15(DISCOVERY_INITIAL_WAIT_TIMEOUT, LONG_TYPE, "" + discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()));
            properties.add(simpleProperty15(REFRESH_TIMEOUT, LONG_TYPE, "" + discoveryGroupConfiguration.getRefreshTimeout()));
        }
        boolean hasReconnect = false;
        final List<ConfigProperty> inboundProperties = new ArrayList<>();
        final String reconnectName = ConnectionFactoryAttributes.Pooled.RECONNECT_ATTEMPTS_PROP_NAME;
        for (PooledConnectionFactoryConfigProperties adapterParam : adapterParams) {
            hasReconnect |= reconnectName.equals(adapterParam.getName());
            ConfigProperty p = simpleProperty15(adapterParam.getName(), adapterParam.getType(), adapterParam.getValue());
            if (adapterParam.getName().equals(REBALANCE_CONNECTIONS_PROP_NAME)) {
                boolean rebalanceConnections = Boolean.parseBoolean(adapterParam.getValue());
                if (rebalanceConnections) {
                    inboundProperties.add(p);
                }
            } else {
                properties.add(p);
            }
        }
        // The default -1, which will hang forever until a server appears
        if (!hasReconnect) {
            properties.add(simpleProperty15(reconnectName, Integer.class.getName(), DEFAULT_MAX_RECONNECTS));
        }
        WildFlyRecoveryRegistry.container = container;
        OutboundResourceAdapter outbound = createOutbound();
        InboundResourceAdapter inbound = createInbound(inboundProperties);
        ResourceAdapter ra = createResourceAdapter15(properties, outbound, inbound);
        Connector cmd = createConnector15(ra);
        TransactionSupportEnum transactionSupport = getTransactionSupport(txSupport);
        ConnectionDefinition common = createConnDef(transactionSupport, bindInfo.getBindName(), minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);
        Activation activation = createActivation(common, transactionSupport);
        ResourceAdapterActivatorService activator = new ResourceAdapterActivatorService(cmd, activation, PooledConnectionFactoryService.class.getClassLoader(), name);
        activator.setBindInfo(bindInfo);
        activator.setCreateBinderService(createBinderService);
        ServiceController<ResourceAdapterDeployment> controller = Services.addServerExecutorDependency(serviceTarget.addService(getResourceAdapterActivatorsServiceName(name), activator), activator.getExecutorServiceInjector(), false).addDependency(ActiveMQActivationService.getServiceName(getActiveMQServiceName(serverName))).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, activator.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, activator.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, activator.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, activator.getRegistryInjector()).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, activator.getTxIntegrationInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, activator.getConfigInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, activator.getCcmInjector()).addDependency(NamingService.SERVICE_NAME).addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default")).setInitialMode(ServiceController.Mode.PASSIVE).install();
        createJNDIAliases(bindInfo, jndiAliases, controller);
        // Mock the deployment service to allow it to start
        serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(name), Service.NULL).install();
    } finally {
        if (is != null)
            is.close();
        if (isIj != null)
            isIj.close();
    }
}
Also used : Connector(org.jboss.jca.common.api.metadata.spec.Connector) TransactionIntegration(org.jboss.jca.core.spi.transaction.TransactionIntegration) ConnectionDefinition(org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) LocalizedXsdString(org.jboss.jca.common.api.metadata.spec.LocalizedXsdString) XsdString(org.jboss.jca.common.api.metadata.spec.XsdString) CachedConnectionManager(org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager) ResourceAdapter(org.jboss.jca.common.api.metadata.spec.ResourceAdapter) InboundResourceAdapter(org.jboss.jca.common.api.metadata.spec.InboundResourceAdapter) OutboundResourceAdapter(org.jboss.jca.common.api.metadata.spec.OutboundResourceAdapter) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) ResourceAdapterDeployment(org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment) InboundResourceAdapter(org.jboss.jca.common.api.metadata.spec.InboundResourceAdapter) InputStream(java.io.InputStream) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) AS7MetadataRepository(org.jboss.as.connector.services.mdr.AS7MetadataRepository) ChannelBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory) ResourceAdapterActivatorService(org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ConfigProperty(org.jboss.jca.common.api.metadata.spec.ConfigProperty) RequiredConfigProperty(org.jboss.jca.common.api.metadata.spec.RequiredConfigProperty) AdminObject(org.jboss.jca.common.api.metadata.resourceadapter.AdminObject) TransactionSupportEnum(org.jboss.jca.common.api.metadata.common.TransactionSupportEnum) JGroupsChannelLocator(org.wildfly.extension.messaging.activemq.JGroupsChannelLocator) Map(java.util.Map) HashMap(java.util.HashMap) OutboundResourceAdapter(org.jboss.jca.common.api.metadata.spec.OutboundResourceAdapter) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) ChannelBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 10 with TransportConfiguration

use of org.apache.activemq.artemis.api.core.TransportConfiguration in project wildfly by wildfly.

the class ImportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != NORMAL) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("import-journal", NORMAL);
    }
    String file = FILE.resolveModelAttribute(context, operation).asString();
    final XmlDataImporter importer = new XmlDataImporter();
    TransportConfiguration transportConfiguration = createInVMTransportConfiguration(context);
    try (InputStream is = new FileInputStream(new File(file));
        ServerLocator serverLocator = ActiveMQClient.createServerLocator(false, transportConfiguration);
        ClientSessionFactory sf = serverLocator.createSessionFactory()) {
        ClientSession session = sf.createSession();
        importer.process(is, session);
    } catch (Exception e) {
        throw new OperationFailedException(e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) OperationFailedException(org.jboss.as.controller.OperationFailedException) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) OperationFailedException(org.jboss.as.controller.OperationFailedException) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter)

Aggregations

TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)16 HashMap (java.util.HashMap)9 NettyConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory)5 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)3 ModelNode (org.jboss.dmr.ModelNode)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ConfigurationImpl (org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)2 Property (org.jboss.dmr.Property)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 DataSource (javax.sql.DataSource)1 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)1 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)1 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)1