use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class JGroupsDiscoveryGroupAdd method createDiscoveryGroupConfiguration.
public static DiscoveryGroupConfiguration createDiscoveryGroupConfiguration(final String name, final DiscoveryGroupConfiguration config, final BroadcastCommandDispatcherFactory commandDispatcherFactory, final String channelName) throws Exception {
final long refreshTimeout = config.getRefreshTimeout();
final long initialWaitTimeout = config.getDiscoveryInitialWaitTimeout();
final BroadcastEndpointFactory endpointFactory = new CommandDispatcherBroadcastEndpointFactory(commandDispatcherFactory, channelName);
return new DiscoveryGroupConfiguration().setName(name).setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialWaitTimeout).setBroadcastEndpointFactory(endpointFactory);
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class JMSConnectionFactoryDefinitionInjectionSource method startedPooledConnectionFactory.
private void startedPooledConnectionFactory(ResolutionContext context, String name, ServiceBuilder<?> serviceBuilder, ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, Injector<ManagedReferenceFactory> injector, boolean external) throws DeploymentUnitProcessingException, OperationFailedException {
Map<String, String> props = new HashMap<>(properties);
List<String> connectors = getConnectors(props);
clearUnknownProperties(properties);
ModelNode model = new ModelNode();
for (String connector : connectors) {
model.get(CONNECTORS).add(connector);
}
for (Map.Entry<String, String> entry : properties.entrySet()) {
model.get(entry.getKey()).set(entry.getValue());
}
model.get(MIN_POOL_SIZE.getName()).set(minPoolSize);
model.get(MAX_POOL_SIZE.getName()).set(maxPoolSize);
if (user != null && !user.isEmpty()) {
model.get(ConnectionFactoryAttributes.Pooled.USER.getName()).set(user);
}
if (password != null && !password.isEmpty()) {
model.get(ConnectionFactoryAttributes.Pooled.PASSWORD.getName()).set(password);
}
if (clientId != null && !clientId.isEmpty()) {
model.get(CommonAttributes.CLIENT_ID.getName()).set(clientId);
}
final String discoveryGroupName = properties.containsKey(DISCOVERY_GROUP.getName()) ? properties.get(DISCOVERY_GROUP.getName()) : null;
if (discoveryGroupName != null) {
model.get(DISCOVERY_GROUP.getName()).set(discoveryGroupName);
}
final String jgroupsChannelName = properties.containsKey(JGROUPS_CLUSTER.getName()) ? properties.get(JGROUPS_CLUSTER.getName()) : null;
if (jgroupsChannelName != null) {
model.get(JGROUPS_CLUSTER.getName()).set(jgroupsChannelName);
}
final String managedConnectionPoolClassName = properties.containsKey(MANAGED_CONNECTION_POOL.getName()) ? properties.get(MANAGED_CONNECTION_POOL.getName()) : null;
if (managedConnectionPoolClassName != null) {
model.get(MANAGED_CONNECTION_POOL.getName()).set(managedConnectionPoolClassName);
}
final Boolean enlistmentTrace = properties.containsKey(ENLISTMENT_TRACE.getName()) ? Boolean.valueOf(properties.get(ENLISTMENT_TRACE.getName())) : null;
List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(model);
String txSupport = transactional ? XA_TX : NO_TX;
final String serverName;
final String pcfName = uniqueName(context, name);
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), name);
if (external) {
serverName = null;
Set<String> connectorsSocketBindings = new HashSet<>();
ExternalBrokerConfigurationService configuration = (ExternalBrokerConfigurationService) deploymentUnit.getServiceRegistry().getRequiredService(MessagingSubsystemRootResourceDefinition.CONFIGURATION_CAPABILITY.getCapabilityServiceName()).getService().getValue();
TransportConfiguration[] tcs = new TransportConfiguration[connectors.size()];
for (int i = 0; i < tcs.length; i++) {
tcs[i] = configuration.getConnectors().get(connectors.get(i));
if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
}
}
DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
if (discoveryGroupName != null) {
discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(discoveryGroupName);
}
if (connectors.isEmpty() && discoveryGroupConfiguration == null) {
tcs = getExternalPooledConnectionFactory(resourceAdapter, deploymentUnit.getServiceRegistry()).getConnectors();
for (int i = 0; i < tcs.length; i++) {
if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
}
}
}
ExternalPooledConnectionFactoryService.installService(serviceTarget, configuration, pcfName, tcs, discoveryGroupConfiguration, connectorsSocketBindings, null, jgroupsChannelName, adapterParams, bindInfo, Collections.emptyList(), txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, deploymentUnit.getAttachment(CAPABILITY_SERVICE_SUPPORT));
} else {
serverName = getActiveMQServerName(properties);
PooledConnectionFactoryService.installService(serviceTarget, pcfName, serverName, connectors, discoveryGroupName, jgroupsChannelName, adapterParams, bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, true);
}
final ServiceName referenceFactoryServiceName = ConnectionFactoryReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
serviceBuilder.addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, injector);
// create the management registration
String managementName = managementName(context, name);
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
final PathElement pcfPath = PathElement.pathElement(POOLED_CONNECTION_FACTORY, managementName);
PathAddress registration;
if (external) {
deploymentResourceSupport.getDeploymentSubsystemModel(MessagingExtension.SUBSYSTEM_NAME);
registration = PathAddress.pathAddress(pcfPath);
} else {
final PathElement serverElement = PathElement.pathElement(SERVER, serverName);
deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
registration = PathAddress.pathAddress(serverElement, pcfPath);
}
MessagingXmlInstallDeploymentUnitProcessor.createDeploymentSubModel(registration, deploymentUnit);
PooledConnectionFactoryConfigurationRuntimeHandler.INSTANCE.registerResource(serverName, managementName, model);
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class ExternalPooledConnectionFactoryAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
PathAddress address = context.getCurrentAddress();
final String name = context.getCurrentAddressValue();
final ModelNode resolvedModel = model.clone();
for (final AttributeDefinition attribute : attributes) {
resolvedModel.get(attribute.getName()).set(attribute.resolveModelAttribute(context, resolvedModel));
}
// We validated that jndiName part of the model in populateModel
final List<String> jndiNames = new ArrayList<>();
for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
jndiNames.add(node.asString());
}
final BindInfo bindInfo = ContextNames.bindInfoFor(jndiNames.get(0));
List<String> jndiAliases;
if (jndiNames.size() > 1) {
jndiAliases = new ArrayList<>(jndiNames.subList(1, jndiNames.size()));
} else {
jndiAliases = Collections.emptyList();
}
String managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asStringOrNull();
final int minPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MIN_POOL_SIZE.getName()).asInt();
final int maxPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MAX_POOL_SIZE.getName()).asInt();
Boolean enlistmentTrace = resolvedModel.get(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName()).asBooleanOrNull();
String txSupport = getTxSupport(resolvedModel);
List<String> connectors = Common.CONNECTORS.unwrap(context, model);
String discoveryGroupName = getDiscoveryGroup(resolvedModel);
String jgroupClusterName = null;
String jgroupsChannelName = null;
final PathAddress serverAddress = MessagingServices.getActiveMQServerPathAddress(address);
if (discoveryGroupName != null) {
Resource dgResource;
if (isSubsystemResource(context)) {
PathAddress dgAddress = address.getParent().append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName);
try {
dgResource = context.readResourceFromRoot(dgAddress, false);
} catch (Resource.NoSuchResourceException ex) {
dgAddress = address.getParent().append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName);
dgResource = context.readResourceFromRoot(dgAddress, false);
}
} else {
PathAddress dgAddress = serverAddress.append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName);
try {
dgResource = context.readResourceFromRoot(dgAddress, false);
} catch (Resource.NoSuchResourceException ex) {
dgAddress = address.getParent().append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName);
dgResource = context.readResourceFromRoot(dgAddress, false);
}
}
ModelNode dgModel = dgResource.getModel();
ModelNode jgroupCluster = JGROUPS_CLUSTER.resolveModelAttribute(context, dgModel);
if (jgroupCluster.isDefined()) {
jgroupClusterName = jgroupCluster.asString();
ModelNode channel = DiscoveryGroupDefinition.JGROUPS_CHANNEL.resolveModelAttribute(context, dgModel);
if (channel.isDefined()) {
jgroupsChannelName = channel.asString();
}
}
}
List<PooledConnectionFactoryConfigProperties> adapterParams = PooledConnectionFactoryAdd.getAdapterParams(resolvedModel, context, ExternalPooledConnectionFactoryDefinition.ATTRIBUTES);
DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
if (discoveryGroupName != null) {
discoveryGroupConfiguration = ExternalConnectionFactoryAdd.getDiscoveryGroup(context, discoveryGroupName);
}
Set<String> connectorsSocketBindings = new HashSet<>();
TransportConfiguration[] transportConfigurations = TransportConfigOperationHandlers.processConnectors(context, connectors, connectorsSocketBindings);
ExternalPooledConnectionFactoryService.installService(context, name, transportConfigurations, discoveryGroupConfiguration, connectorsSocketBindings, jgroupClusterName, jgroupsChannelName, adapterParams, bindInfo, jndiAliases, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
if (statsEnabled) {
// Add the stats resource. This is kind of a hack as we are modifying the resource
// in runtime, but oh well. We don't use readResourceForUpdate for this reason.
// This only runs in this add op anyway, and because it's an add we know readResource
// is going to be returning the current write snapshot of the model, i.e. the one we want
PooledConnectionFactoryStatisticsService.registerStatisticsResources(resource);
installStatistics(context, name);
}
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class ExternalConnectionFactoryService method start.
@Override
public void start(StartContext context) throws StartException {
try {
if (connectors != null && connectors.length > 0) {
TransportConfigOperationHandlers.processConnectorBindings(Arrays.asList(connectors), socketBindings, outboundSocketBindings);
if (ha) {
factory = ActiveMQJMSClient.createConnectionFactoryWithHA(type, connectors);
} else {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(type, connectors);
}
} else {
final String name = groupConfiguration.getName();
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, groupConfiguration, commandDispatcherFactory, clusterName);
} else {
final SocketBinding binding = groupBindings.get(key).get();
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
}
config = SocketDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, groupConfiguration, binding);
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
}
if (ha) {
factory = ActiveMQJMSClient.createConnectionFactoryWithHA(config, type);
} else {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(config, type);
}
}
if (config != null) {
factory.setAutoGroup(config.isAutoGroup());
factory.setBlockOnAcknowledge(config.isBlockOnAcknowledge());
factory.setBlockOnDurableSend(config.isBlockOnDurableSend());
factory.setBlockOnNonDurableSend(config.isBlockOnNonDurableSend());
factory.setCacheLargeMessagesClient(config.isCacheLargeMessagesClient());
factory.setCallFailoverTimeout(config.getCallFailoverTimeout());
factory.setCallTimeout(config.getCallTimeout());
factory.setClientID(config.getClientID());
factory.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
factory.setCompressLargeMessage(config.isCompressLargeMessages());
factory.setConfirmationWindowSize(config.getConfirmationWindowSize());
factory.setConnectionTTL(config.getConnectionTTL());
factory.setConsumerMaxRate(config.getConsumerMaxRate());
factory.setConsumerWindowSize(config.getConsumerWindowSize());
factory.setDeserializationBlackList(config.getDeserializationBlackList());
factory.setDeserializationWhiteList(config.getDeserializationWhiteList());
factory.setDupsOKBatchSize(config.getDupsOKBatchSize());
factory.setEnableSharedClientID(config.isEnableSharedClientID());
factory.setFailoverOnInitialConnection(config.isFailoverOnInitialConnection());
factory.setGroupID(config.getGroupID());
factory.setInitialMessagePacketSize(config.getInitialMessagePacketSize());
factory.setMaxRetryInterval(config.getMaxRetryInterval());
factory.setMinLargeMessageSize(config.getMinLargeMessageSize());
factory.setPreAcknowledge(config.isPreAcknowledge());
factory.setProducerMaxRate(config.getProducerMaxRate());
factory.setProducerWindowSize(config.getProducerWindowSize());
factory.setProtocolManagerFactoryStr(config.getProtocolManagerFactoryStr());
factory.setConnectionLoadBalancingPolicyClassName(config.getLoadBalancingPolicyClassName());
factory.setReconnectAttempts(config.getReconnectAttempts());
factory.setRetryInterval(config.getRetryInterval());
factory.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
factory.setScheduledThreadPoolMaxSize(config.getScheduledThreadPoolMaxSize());
factory.setThreadPoolMaxSize(config.getThreadPoolMaxSize());
factory.setTransactionBatchSize(config.getTransactionBatchSize());
factory.setUseGlobalPools(config.isUseGlobalPools());
factory.setUseTopologyForLoadBalancing(config.getUseTopologyForLoadBalancing());
}
factory.setEnable1xPrefixes(enable1Prefixes);
} catch (Throwable e) {
throw MessagingLogger.ROOT_LOGGER.failedToCreate(e, "connection-factory");
}
}
use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.
the class DiscoveryGroupAdd method createDiscoveryGroupConfiguration.
static DiscoveryGroupConfiguration createDiscoveryGroupConfiguration(final String name, final DiscoveryGroupConfiguration config, final SocketBinding socketBinding) throws Exception {
final String localAddress = socketBinding.getAddress().getHostAddress();
final String groupAddress = socketBinding.getMulticastAddress().getHostAddress();
final int groupPort = socketBinding.getMulticastPort();
final long refreshTimeout = config.getRefreshTimeout();
final long initialWaitTimeout = config.getDiscoveryInitialWaitTimeout();
final BroadcastEndpointFactory endpointFactory = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort).setLocalBindAddress(localAddress).setLocalBindPort(-1);
return new DiscoveryGroupConfiguration().setName(name).setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialWaitTimeout).setBroadcastEndpointFactory(endpointFactory);
}
Aggregations