Search in sources :

Example 1 with JMSFactoryType

use of org.apache.activemq.artemis.api.jms.JMSFactoryType in project activemq-artemis by apache.

the class ActiveMQInitialContextFactory method getInitialContext.

@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    // lets create a factory
    Map<String, Object> data = new ConcurrentHashMap<>();
    String providerUrl = (String) environment.get(javax.naming.Context.PROVIDER_URL);
    if (providerUrl != null) {
        try {
            JMSFactoryType providedFactoryType = getFactoryType(providerUrl);
            if (providedFactoryType == null) {
                for (JMSFactoryType factoryType : JMSFactoryType.values()) {
                    String factoryName = factoryType.connectionFactoryInterface().getSimpleName();
                    data.put(factoryName, createConnectionFactory(providerUrl, Collections.singletonMap("type", factoryType.toString()), factoryName));
                }
            } else {
                String factoryName = providedFactoryType.connectionFactoryInterface().getSimpleName();
                data.put(factoryName, createConnectionFactory(providerUrl, factoryName));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new NamingException("Invalid broker URL");
        }
    }
    for (Map.Entry<?, ?> entry : environment.entrySet()) {
        String key = entry.getKey().toString();
        if (key.startsWith(connectionFactoryPrefix)) {
            String jndiName = key.substring(connectionFactoryPrefix.length());
            try {
                data.put(jndiName, createConnectionFactory((String) environment.get(key), jndiName));
            } catch (Exception e) {
                e.printStackTrace();
                throw new NamingException("Invalid broker URL");
            }
        }
    }
    createQueues(data, environment);
    createTopics(data, environment);
    data.put(DYNAMIC_QUEUE_CONTEXT, new LazyCreateContext() {

        private static final long serialVersionUID = 6503881346214855588L;

        @Override
        protected Object createEntry(String name) {
            return ActiveMQJMSClient.createQueue(name);
        }
    });
    data.put(DYNAMIC_TOPIC_CONTEXT, new LazyCreateContext() {

        private static final long serialVersionUID = 2019166796234979615L;

        @Override
        protected Object createEntry(String name) {
            return ActiveMQJMSClient.createTopic(name);
        }
    });
    return createContext(environment, data);
}
Also used : JMSFactoryType(org.apache.activemq.artemis.api.jms.JMSFactoryType) NamingException(javax.naming.NamingException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) NamingException(javax.naming.NamingException)

Example 2 with JMSFactoryType

use of org.apache.activemq.artemis.api.jms.JMSFactoryType in project wildfly by wildfly.

the class ConnectionFactoryAdd method createConfiguration.

static ConnectionFactoryConfiguration createConfiguration(final OperationContext context, final String name, final ModelNode model) throws OperationFailedException {
    final List<String> entries = Common.ENTRIES.unwrap(context, model);
    final ConnectionFactoryConfiguration config = new ConnectionFactoryConfigurationImpl().setName(name).setHA(false).setBindings(entries.toArray(new String[entries.size()]));
    config.setHA(HA.resolveModelAttribute(context, model).asBoolean());
    config.setAutoGroup(Common.AUTO_GROUP.resolveModelAttribute(context, model).asBoolean());
    config.setBlockOnAcknowledge(Common.BLOCK_ON_ACKNOWLEDGE.resolveModelAttribute(context, model).asBoolean());
    config.setBlockOnDurableSend(Common.BLOCK_ON_DURABLE_SEND.resolveModelAttribute(context, model).asBoolean());
    config.setBlockOnNonDurableSend(Common.BLOCK_ON_NON_DURABLE_SEND.resolveModelAttribute(context, model).asBoolean());
    config.setCacheLargeMessagesClient(Common.CACHE_LARGE_MESSAGE_CLIENT.resolveModelAttribute(context, model).asBoolean());
    config.setCallTimeout(CALL_TIMEOUT.resolveModelAttribute(context, model).asLong());
    config.setClientFailureCheckPeriod(Common.CLIENT_FAILURE_CHECK_PERIOD.resolveModelAttribute(context, model).asInt());
    config.setCallFailoverTimeout(CALL_FAILOVER_TIMEOUT.resolveModelAttribute(context, model).asLong());
    final ModelNode clientId = CLIENT_ID.resolveModelAttribute(context, model);
    if (clientId.isDefined()) {
        config.setClientID(clientId.asString());
    }
    config.setCompressLargeMessages(Common.COMPRESS_LARGE_MESSAGES.resolveModelAttribute(context, model).asBoolean());
    config.setConfirmationWindowSize(Common.CONFIRMATION_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    config.setConnectionTTL(Common.CONNECTION_TTL.resolveModelAttribute(context, model).asLong());
    List<String> connectorNames = Common.CONNECTORS.unwrap(context, model);
    config.setConnectorNames(connectorNames);
    config.setConsumerMaxRate(Common.CONSUMER_MAX_RATE.resolveModelAttribute(context, model).asInt());
    config.setConsumerWindowSize(Common.CONSUMER_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    final ModelNode discoveryGroupName = Common.DISCOVERY_GROUP.resolveModelAttribute(context, model);
    if (discoveryGroupName.isDefined()) {
        config.setDiscoveryGroupName(discoveryGroupName.asString());
    }
    config.setDupsOKBatchSize(Common.DUPS_OK_BATCH_SIZE.resolveModelAttribute(context, model).asInt());
    config.setFailoverOnInitialConnection(Common.FAILOVER_ON_INITIAL_CONNECTION.resolveModelAttribute(context, model).asBoolean());
    final ModelNode groupId = Common.GROUP_ID.resolveModelAttribute(context, model);
    if (groupId.isDefined()) {
        config.setGroupID(groupId.asString());
    }
    final ModelNode lbcn = Common.CONNECTION_LOAD_BALANCING_CLASS_NAME.resolveModelAttribute(context, model);
    if (lbcn.isDefined()) {
        config.setLoadBalancingPolicyClassName(lbcn.asString());
    }
    config.setMaxRetryInterval(Common.MAX_RETRY_INTERVAL.resolveModelAttribute(context, model).asLong());
    config.setMinLargeMessageSize(Common.MIN_LARGE_MESSAGE_SIZE.resolveModelAttribute(context, model).asInt());
    config.setPreAcknowledge(Common.PRE_ACKNOWLEDGE.resolveModelAttribute(context, model).asBoolean());
    config.setProducerMaxRate(Common.PRODUCER_MAX_RATE.resolveModelAttribute(context, model).asInt());
    config.setProducerWindowSize(Common.PRODUCER_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    config.setReconnectAttempts(Common.RECONNECT_ATTEMPTS.resolveModelAttribute(context, model).asInt());
    config.setRetryInterval(Common.RETRY_INTERVAL.resolveModelAttribute(context, model).asLong());
    config.setRetryIntervalMultiplier(Common.RETRY_INTERVAL_MULTIPLIER.resolveModelAttribute(context, model).asDouble());
    config.setScheduledThreadPoolMaxSize(Common.SCHEDULED_THREAD_POOL_MAX_SIZE.resolveModelAttribute(context, model).asInt());
    config.setThreadPoolMaxSize(Common.THREAD_POOL_MAX_SIZE.resolveModelAttribute(context, model).asInt());
    config.setTransactionBatchSize(Common.TRANSACTION_BATCH_SIZE.resolveModelAttribute(context, model).asInt());
    config.setUseGlobalPools(Common.USE_GLOBAL_POOLS.resolveModelAttribute(context, model).asBoolean());
    config.setLoadBalancingPolicyClassName(Common.CONNECTION_LOAD_BALANCING_CLASS_NAME.resolveModelAttribute(context, model).asString());
    final ModelNode clientProtocolManagerFactory = Common.PROTOCOL_MANAGER_FACTORY.resolveModelAttribute(context, model);
    if (clientProtocolManagerFactory.isDefined()) {
        config.setProtocolManagerFactoryStr(clientProtocolManagerFactory.asString());
    }
    List<String> deserializationBlackList = Common.DESERIALIZATION_BLACKLIST.unwrap(context, model);
    if (!deserializationBlackList.isEmpty()) {
        config.setDeserializationBlackList(String.join(",", deserializationBlackList));
    }
    List<String> deserializationWhiteList = Common.DESERIALIZATION_WHITELIST.unwrap(context, model);
    if (!deserializationWhiteList.isEmpty()) {
        config.setDeserializationWhiteList(String.join(",", deserializationWhiteList));
    }
    JMSFactoryType jmsFactoryType = ConnectionFactoryType.valueOf(ConnectionFactoryAttributes.Regular.FACTORY_TYPE.resolveModelAttribute(context, model).asString()).getType();
    config.setFactoryType(jmsFactoryType);
    config.setInitialMessagePacketSize(ConnectionFactoryAttributes.Common.INITIAL_MESSAGE_PACKET_SIZE.resolveModelAttribute(context, model).asInt());
    config.setEnableSharedClientID(true);
    config.setEnable1xPrefixes(true);
    config.setUseTopologyForLoadBalancing(ConnectionFactoryAttributes.Common.USE_TOPOLOGY.resolveModelAttribute(context, model).asBoolean());
    return config;
}
Also used : JMSFactoryType(org.apache.activemq.artemis.api.jms.JMSFactoryType) ConnectionFactoryConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl) ModelNode(org.jboss.dmr.ModelNode) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)

Example 3 with JMSFactoryType

use of org.apache.activemq.artemis.api.jms.JMSFactoryType in project wildfly by wildfly.

the class ExternalConnectionFactoryAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final ServiceName serviceName = ExternalConnectionFactoryDefinition.CAPABILITY.getCapabilityServiceName(context.getCurrentAddress());
    boolean ha = HA.resolveModelAttribute(context, model).asBoolean();
    boolean enable1Prefixes = ENABLE_AMQ1_PREFIX.resolveModelAttribute(context, model).asBoolean();
    final ModelNode discoveryGroupName = Common.DISCOVERY_GROUP.resolveModelAttribute(context, model);
    final ConnectionFactoryConfiguration config = ConnectionFactoryAdd.createConfiguration(context, name, model);
    JMSFactoryType jmsFactoryType = ConnectionFactoryType.valueOf(ConnectionFactoryAttributes.Regular.FACTORY_TYPE.resolveModelAttribute(context, model).asString()).getType();
    List<String> connectorNames = Common.CONNECTORS.unwrap(context, model);
    ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName).addAliases(JMSServices.getConnectionFactoryBaseServiceName(MessagingServices.getActiveMQServiceName()).append(name));
    ExternalConnectionFactoryService service;
    if (discoveryGroupName.isDefined()) {
        // mapping between the {discovery}-groups and the cluster names they use
        Map<String, String> clusterNames = new HashMap<>();
        Map<String, Supplier<SocketBinding>> groupBindings = new HashMap<>();
        // mapping between the {discovery}-groups and the command dispatcher factory they use
        Map<String, Supplier<BroadcastCommandDispatcherFactory>> commandDispatcherFactories = new HashMap<>();
        final String dgname = discoveryGroupName.asString();
        final String key = "discovery" + dgname;
        ModelNode discoveryGroupModel;
        try {
            discoveryGroupModel = context.readResourceFromRoot(context.getCurrentAddress().getParent().append(JGROUPS_DISCOVERY_GROUP, dgname)).getModel();
        } catch (Resource.NoSuchResourceException ex) {
            discoveryGroupModel = new ModelNode();
        }
        if (discoveryGroupModel.hasDefined(JGROUPS_CLUSTER.getName())) {
            ModelNode channel = JGroupsDiscoveryGroupDefinition.JGROUPS_CHANNEL.resolveModelAttribute(context, discoveryGroupModel);
            ServiceName commandDispatcherFactoryServiceName = MessagingServices.getBroadcastCommandDispatcherFactoryServiceName(channel.asStringOrNull());
            Supplier<BroadcastCommandDispatcherFactory> commandDispatcherFactorySupplier = builder.requires(commandDispatcherFactoryServiceName);
            commandDispatcherFactories.put(key, commandDispatcherFactorySupplier);
            String clusterName = JGROUPS_CLUSTER.resolveModelAttribute(context, discoveryGroupModel).asString();
            clusterNames.put(key, clusterName);
        } else {
            final ServiceName groupBinding = GroupBindingService.getDiscoveryBaseServiceName(JBOSS_MESSAGING_ACTIVEMQ).append(dgname);
            Supplier<SocketBinding> groupBindingSupplier = builder.requires(groupBinding);
            groupBindings.put(key, groupBindingSupplier);
        }
        service = new ExternalConnectionFactoryService(getDiscoveryGroup(context, dgname), commandDispatcherFactories, groupBindings, clusterNames, jmsFactoryType, ha, enable1Prefixes, config);
    } else {
        Map<String, Supplier<SocketBinding>> socketBindings = new HashMap<>();
        Map<String, Supplier<OutboundSocketBinding>> outboundSocketBindings = new HashMap<>();
        Set<String> connectorsSocketBindings = new HashSet<>();
        TransportConfiguration[] transportConfigurations = TransportConfigOperationHandlers.processConnectors(context, connectorNames, connectorsSocketBindings);
        Map<String, Boolean> outbounds = TransportConfigOperationHandlers.listOutBoundSocketBinding(context, connectorsSocketBindings);
        for (final String connectorSocketBinding : connectorsSocketBindings) {
            // find whether the connectorSocketBinding references a SocketBinding or an OutboundSocketBinding
            if (outbounds.get(connectorSocketBinding)) {
                final ServiceName outboundSocketName = OutboundSocketBinding.OUTBOUND_SOCKET_BINDING_BASE_SERVICE_NAME.append(connectorSocketBinding);
                Supplier<OutboundSocketBinding> outboundSupplier = builder.requires(outboundSocketName);
                outboundSocketBindings.put(connectorSocketBinding, outboundSupplier);
            } else {
                final ServiceName socketName = SocketBinding.JBOSS_BINDING_NAME.append(connectorSocketBinding);
                Supplier<SocketBinding> socketBindingsSupplier = builder.requires(socketName);
                socketBindings.put(connectorSocketBinding, socketBindingsSupplier);
            }
        }
        service = new ExternalConnectionFactoryService(transportConfigurations, socketBindings, outboundSocketBindings, jmsFactoryType, ha, enable1Prefixes, config);
    }
    builder.setInstance(service);
    builder.install();
    for (String entry : Common.ENTRIES.unwrap(context, model)) {
        MessagingLogger.ROOT_LOGGER.debugf("Referencing %s with JNDI name %s", serviceName, entry);
        BinderServiceUtil.installBinderService(context.getServiceTarget(), entry, service, serviceName);
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) HashMap(java.util.HashMap) BroadcastCommandDispatcherFactory(org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Supplier(java.util.function.Supplier) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) HashSet(java.util.HashSet) Resource(org.jboss.as.controller.registry.Resource) JMSFactoryType(org.apache.activemq.artemis.api.jms.JMSFactoryType) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

JMSFactoryType (org.apache.activemq.artemis.api.jms.JMSFactoryType)3 ConnectionFactoryConfiguration (org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)2 ModelNode (org.jboss.dmr.ModelNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Supplier (java.util.function.Supplier)1 NamingException (javax.naming.NamingException)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ConnectionFactoryConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl)1 Resource (org.jboss.as.controller.registry.Resource)1 OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)1 SocketBinding (org.jboss.as.network.SocketBinding)1 ServiceName (org.jboss.msc.service.ServiceName)1 BroadcastCommandDispatcherFactory (org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory)1