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);
}
}
Aggregations