Search in sources :

Example 6 with BroadcastCommandDispatcherFactory

use of org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory 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

OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)6 SocketBinding (org.jboss.as.network.SocketBinding)6 BroadcastCommandDispatcherFactory (org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory)6 HashMap (java.util.HashMap)3 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 LocalizedXsdString (org.jboss.jca.common.api.metadata.spec.LocalizedXsdString)3 XsdString (org.jboss.jca.common.api.metadata.spec.XsdString)3 ServiceName (org.jboss.msc.service.ServiceName)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ModelNode (org.jboss.dmr.ModelNode)2 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 Supplier (java.util.function.Supplier)1 MBeanServer (javax.management.MBeanServer)1 DataSource (javax.sql.DataSource)1 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)1 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)1