Skip to content

Commit

Permalink
[WFLY-10535]: PooledConnectionFactory JNDI aliases are created in the…
Browse files Browse the repository at this point in the history
… root service container

Using the operationContext serviceTarget instead of the startContext
  • Loading branch information
ehsavoie committed Sep 13, 2018
1 parent 263fdfe commit d5ec48b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 65 deletions.
Expand Up @@ -22,7 +22,6 @@
package org.wildfly.extension.messaging.activemq.jms;

import static org.jboss.as.naming.deployment.ContextNames.BindInfo;
import static org.wildfly.extension.messaging.activemq.BinderServiceUtil.installAliasBinderService;
import static org.wildfly.extension.messaging.activemq.jms.ConnectionFactoryAttributes.Pooled.REBALANCE_CONNECTIONS_PROP_NAME;

import java.io.InputStream;
Expand Down Expand Up @@ -50,7 +49,6 @@
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.NamingService;
import org.jboss.as.network.ManagedBinding;
import org.jboss.as.network.OutboundSocketBinding;
Expand Down Expand Up @@ -180,7 +178,6 @@ public class ExternalPooledConnectionFactoryService implements Service<Void> {
// mapping between the {discovery}-groups and the command dispatcher factory they use
private final Map<String, Supplier<CommandDispatcherFactory>> commandDispatcherFactories = new HashMap<>();
private BindInfo bindInfo;
private List<String> jndiAliases;
private String txSupport;
private int minPoolSize;
private int maxPoolSize;
Expand All @@ -194,14 +191,14 @@ public class ExternalPooledConnectionFactoryService implements Service<Void> {


public ExternalPooledConnectionFactoryService(String name, TransportConfiguration[] connectors, DiscoveryGroupConfiguration groupConfiguration, String jgroupsClusterName,
String jgroupChannelName, List<PooledConnectionFactoryConfigProperties> adapterParams, List<String> jndiNames, String txSupport, int minPoolSize, int maxPoolSize, String managedConnectionPoolClassName, Boolean enlistmentTrace) {
String jgroupChannelName, List<PooledConnectionFactoryConfigProperties> adapterParams, BindInfo bindInfo, String txSupport, int minPoolSize, int maxPoolSize, String managedConnectionPoolClassName, Boolean enlistmentTrace) {
this.name = name;
this.connectors = connectors;
this.discoveryGroupConfiguration = groupConfiguration;
this.jgroupsClusterName = jgroupsClusterName;
this.jgroupChannelName = jgroupChannelName;
this.adapterParams = adapterParams;
initJNDIBindings(jndiNames);
this.bindInfo = bindInfo;
createBinderService = true;
this.txSupport = txSupport;
this.minPoolSize = minPoolSize;
Expand All @@ -210,15 +207,6 @@ public ExternalPooledConnectionFactoryService(String name, TransportConfiguratio
this.enlistmentTrace = enlistmentTrace;
}

private void initJNDIBindings(List<String> jndiNames) {
// create the definition with the 1st jndi names and create jndi aliases for the rest
String jndiName = jndiNames.get(0);
this.bindInfo = ContextNames.bindInfoFor(jndiName);
this.jndiAliases = new ArrayList<>();
if (jndiNames.size() > 1) {
jndiAliases = jndiNames.subList(1, jndiNames.size());
}
}

static ServiceName getResourceAdapterActivatorsServiceName(String name) {
return ConnectorServices.RESOURCE_ADAPTER_ACTIVATOR_SERVICE.append(name);
Expand All @@ -233,7 +221,7 @@ public static ExternalPooledConnectionFactoryService installService(OperationCon
String jgroupClusterName,
String jgroupChannelName,
List<PooledConnectionFactoryConfigProperties> adapterParams,
List<String> jndiNames,
BindInfo bindInfo,
String txSupport,
int minPoolSize,
int maxPoolSize,
Expand All @@ -244,7 +232,7 @@ public static ExternalPooledConnectionFactoryService installService(OperationCon
ServiceName serviceName = JMSServices.getPooledConnectionFactoryBaseServiceName(JBOSS_MESSAGING_ACTIVEMQ).append(name);
ExternalPooledConnectionFactoryService service = new ExternalPooledConnectionFactoryService(name,
connectors, groupConfiguration, jgroupClusterName, jgroupChannelName, adapterParams,
jndiNames, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);
bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);

installService0(context, serviceName, service, groupConfiguration, jgroupClusterName, jgroupChannelName, connectorsSocketBindings, model);
return service;
Expand Down Expand Up @@ -463,8 +451,6 @@ private void createService(ServiceTarget serviceTarget, ServiceContainer contain
.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default"))
.setInitialMode(ServiceController.Mode.PASSIVE).install();

createJNDIAliases(bindInfo, jndiAliases, controller, serviceTarget);

// Mock the deployment service to allow it to start
serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(name), Service.NULL).install();
} finally {
Expand Down Expand Up @@ -499,17 +485,6 @@ private void configureCredential(List<ConfigProperty> properties) {
}
}

private void createJNDIAliases(final BindInfo bindInfo, List<String> aliases, ServiceController<ResourceAdapterDeployment> controller, ServiceTarget serviceTarget) {
for (final String alias : aliases) {
// do not install the alias' binder service if it is already registered
if (controller.getServiceContainer().getService(ContextNames.bindInfoFor(alias).getBinderServiceName()) == null) {
installAliasBinderService(serviceTarget,
bindInfo,
alias);
}
}
}

private static TransactionSupportEnum getTransactionSupport(String txSupport) {
try {
return TransactionSupportEnum.valueOf(txSupport);
Expand Down
Expand Up @@ -22,6 +22,7 @@

package org.wildfly.extension.messaging.activemq.jms;

import static org.wildfly.extension.messaging.activemq.BinderServiceUtil.installAliasBinderService;
import static org.wildfly.extension.messaging.activemq.CommonAttributes.JGROUPS_CLUSTER;
import static org.wildfly.extension.messaging.activemq.CommonAttributes.LOCAL;
import static org.wildfly.extension.messaging.activemq.CommonAttributes.LOCAL_TX;
Expand All @@ -45,9 +46,13 @@
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.deployment.ContextNames.BindInfo;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.extension.messaging.activemq.CommonAttributes;
import org.wildfly.extension.messaging.activemq.DiscoveryGroupDefinition;
import org.wildfly.extension.messaging.activemq.MessagingServices;
Expand Down Expand Up @@ -84,7 +89,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Res
for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
jndiNames.add(node.asString());
}

BindInfo bindInfo = installJNDIAliases(context, jndiNames);
String managedConnectionPoolClassName = null;
if (resolvedModel.hasDefined(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName())) {
managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asString();
Expand Down Expand Up @@ -143,12 +148,12 @@ protected void performRuntime(OperationContext context, ModelNode operation, Res
Set<String> connectorsSocketBindings = new HashSet<>();
TransportConfiguration[] transportConfigurations = TransportConfigOperationHandlers.processConnectors(context, connectors, connectorsSocketBindings);
ExternalPooledConnectionFactoryService.installService(context, name, transportConfigurations, discoveryGroupConfiguration, connectorsSocketBindings,
jgroupClusterName, jgroupsChannelName, adapterParams, jndiNames, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
jgroupClusterName, jgroupsChannelName, adapterParams, bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
} else {
String serverName = serverAddress.getLastElement().getValue();
PooledConnectionFactoryService.installService(context,
name, serverName, connectors, discoveryGroupName, jgroupClusterName,
adapterParams, jndiNames, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
adapterParams, bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
}
boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();

Expand Down Expand Up @@ -206,4 +211,19 @@ private void installStatistics(OperationContext context, String name) {
.setInitialMode(ServiceController.Mode.PASSIVE)
.install();
}

private ContextNames.BindInfo installJNDIAliases(OperationContext context, List<String> entries) {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceRegistry registry = context.getServiceRegistry(false);
final String jndiName = entries.get(0);
final BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
if (entries.size() > 1) {
for (int i = 1; i < entries.size(); i++) {
if (registry.getService(ContextNames.bindInfoFor(entries.get(i)).getBinderServiceName()) == null) {
installAliasBinderService(serviceTarget, bindInfo, entries.get(i));
}
}
}
return bindInfo;
}
}
Expand Up @@ -22,9 +22,7 @@

package org.wildfly.extension.messaging.activemq.jms;

import static java.util.Collections.EMPTY_LIST;
import static org.jboss.as.naming.deployment.ContextNames.BindInfo;
import static org.wildfly.extension.messaging.activemq.BinderServiceUtil.installAliasBinderService;
import static org.wildfly.extension.messaging.activemq.MessagingServices.getActiveMQServiceName;
import static org.wildfly.extension.messaging.activemq.jms.ConnectionFactoryAttributes.Pooled.REBALANCE_CONNECTIONS_PROP_NAME;
import static org.wildfly.extension.messaging.activemq.jms.JMSQueueService.JMS_QUEUE_PREFIX;
Expand Down Expand Up @@ -54,7 +52,6 @@
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.NamingService;
import org.jboss.as.network.SocketBinding;
import org.jboss.as.server.Services;
Expand Down Expand Up @@ -178,7 +175,6 @@ public class PooledConnectionFactoryService implements Service<Void> {
private InjectedValue<ActiveMQServer> activeMQServer = new InjectedValue<>();
private BindInfo bindInfo;
private final boolean pickAnyConnectors;
private List<String> jndiAliases;
private String txSupport;
private int minPoolSize;
private int maxPoolSize;
Expand All @@ -191,14 +187,14 @@ public class PooledConnectionFactoryService implements Service<Void> {
private InjectedValue<ExceptionSupplier<CredentialSource, Exception>> credentialSourceSupplier = new InjectedValue<>();


public PooledConnectionFactoryService(String name, List<String> connectors, String discoveryGroupName, String serverName, String jgroupsChannelName, List<PooledConnectionFactoryConfigProperties> adapterParams, List<String> jndiNames, String txSupport, int minPoolSize, int maxPoolSize, String managedConnectionPoolClassName, Boolean enlistmentTrace) {
public PooledConnectionFactoryService(String name, List<String> connectors, String discoveryGroupName, String serverName, String jgroupsChannelName, List<PooledConnectionFactoryConfigProperties> adapterParams, BindInfo bindInfo, String txSupport, int minPoolSize, int maxPoolSize, String managedConnectionPoolClassName, Boolean enlistmentTrace) {
this.name = name;
this.connectors = connectors;
this.discoveryGroupName = discoveryGroupName;
this.serverName = serverName;
this.jgroupsChannelName = jgroupsChannelName;
this.adapterParams = adapterParams;
initJNDIBindings(jndiNames);
this.bindInfo = bindInfo;
createBinderService = true;
this.txSupport = txSupport;
this.minPoolSize = minPoolSize;
Expand All @@ -216,7 +212,6 @@ public PooledConnectionFactoryService(String name, List<String> connectors, Stri
this.jgroupsChannelName = jgroupsChannelName;
this.adapterParams = adapterParams;
this.bindInfo = bindInfo;
this.jndiAliases = EMPTY_LIST;
this.createBinderService = false;
this.txSupport = txSupport;
this.minPoolSize = minPoolSize;
Expand All @@ -226,16 +221,6 @@ public PooledConnectionFactoryService(String name, List<String> connectors, Stri
this.pickAnyConnectors = pickAnyConnectors;
}

private void initJNDIBindings(List<String> jndiNames) {
// create the definition with the 1st jndi names and create jndi aliases for the rest
String jndiName = jndiNames.get(0);
this.bindInfo = ContextNames.bindInfoFor(jndiName);
this.jndiAliases = new ArrayList<String>();
if (jndiNames.size() > 1) {
jndiAliases = jndiNames.subList(1, jndiNames.size());
}
}

static ServiceName getResourceAdapterActivatorsServiceName(String name) {
return ConnectorServices.RESOURCE_ADAPTER_ACTIVATOR_SERVICE.append(name);
}
Expand Down Expand Up @@ -277,7 +262,7 @@ public static PooledConnectionFactoryService installService(OperationContext con
String discoveryGroupName,
String jgroupsChannelName,
List<PooledConnectionFactoryConfigProperties> adapterParams,
List<String> jndiNames,
BindInfo bindInfo,
String txSupport,
int minPoolSize,
int maxPoolSize,
Expand All @@ -289,7 +274,7 @@ public static PooledConnectionFactoryService installService(OperationContext con
ServiceName serviceName = JMSServices.getPooledConnectionFactoryBaseServiceName(serverServiceName).append(name);
PooledConnectionFactoryService service = new PooledConnectionFactoryService(name,
connectors, discoveryGroupName, serverName, jgroupsChannelName, adapterParams,
jndiNames, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);
bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);

installService0(context, serverServiceName, serviceName, service, model);
return service;
Expand Down Expand Up @@ -485,9 +470,6 @@ private void createService(ServiceTarget serviceTarget, ServiceContainer contain
.addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER)
.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default"))
.setInitialMode(ServiceController.Mode.PASSIVE).install();

createJNDIAliases(bindInfo, jndiAliases, controller, serviceTarget);

// Mock the deployment service to allow it to start
serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(name), Service.NULL).install();
} finally {
Expand Down Expand Up @@ -520,17 +502,6 @@ private void configureCredential(List<ConfigProperty> properties) {
}
}

private void createJNDIAliases(final BindInfo bindInfo, List<String> aliases, ServiceController<ResourceAdapterDeployment> controller, ServiceTarget serviceTarget) {
for (final String alias : aliases) {
// do not install the alias' binder service if it is already registered
if (controller.getServiceContainer().getService(ContextNames.bindInfoFor(alias).getBinderServiceName()) == null) {
installAliasBinderService(serviceTarget,
bindInfo,
alias);
}
}
}

private static TransactionSupportEnum getTransactionSupport(String txSupport) {
try {
return TransactionSupportEnum.valueOf(txSupport);
Expand Down

0 comments on commit d5ec48b

Please sign in to comment.