Skip to content
Permalink
Browse files

[WFLY-9954] Moving component related JNDI dependencies

from o.j.a.s.d.Attachments.JNDI_DEPENDENCIES
 to  o.j.a.s.d.Attachments.COMPONENT_JNDI_DEPENDENCIES attachment.
Before this fix JNDI_DEPENDENCY_SERVICE had too many dependencies.
With this fix applied JNDI_DEPENDENCY_SERVICE will now depend on
JNDI_AGGREGATION_SERVICES and these aggregation services
will reference COMPONENT_JNDI_DEPENDENCIES that were referenced
by JNDI_DEPENDENCY_SERVICE before. In other words we are decreasing
JNDI_DEPENDENCY_SERVICE dependencies count and reorganizing (simplifying)
its dependency tree.
  • Loading branch information
ropalka authored and bstansberry committed Mar 27, 2019
1 parent 8f2796c commit edb596918f761f19d13e0285486e10fbfb86986f
@@ -22,6 +22,8 @@

package org.jboss.as.ee.component.deployers;

import java.util.HashMap;

import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
@@ -31,6 +33,7 @@

/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class EEModuleInitialProcessor implements DeploymentUnitProcessor {

@@ -60,6 +63,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
appName = null;
}
deploymentUnit.putAttachment(Attachments.EE_MODULE_DESCRIPTION, new EEModuleDescription(appName, moduleName, earApplicationName, appClient));
deploymentUnit.putAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES, new HashMap<>());
}

public void undeploy(final DeploymentUnit context) {
@@ -21,6 +21,10 @@
*/
package org.jboss.as.ee.naming;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
@@ -43,6 +47,7 @@
* Processor responsible for binding java:comp/InAppClientContainer
*
* @author Stuart Douglas
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class InApplicationClientBindingProcessor implements DeploymentUnitProcessor {

@@ -85,7 +90,12 @@ private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTa
serviceTarget.addService(inAppClientServiceName, inAppClientContainerService)
.addDependency(contextServiceName, ServiceBasedNamingStore.class, inAppClientContainerService.getNamingStoreInjector())
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, inAppClientServiceName);
final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(inAppClientServiceName);
}


@@ -21,6 +21,10 @@
*/
package org.jboss.as.ee.naming;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
@@ -47,6 +51,7 @@
* Processor responsible for binding java:comp/InstanceName
*
* @author Stuart Douglas
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class InstanceNameBindingProcessor implements DeploymentUnitProcessor {

@@ -110,11 +115,14 @@ public void uninject() {
}
})
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName);

final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(instanceNameServiceName);
}


@Override
public void undeploy(DeploymentUnit context) {
}
@@ -21,7 +21,10 @@
*/
package org.jboss.as.naming.deployment;

import java.util.List;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.naming.service.NamingService;
@@ -32,6 +35,7 @@
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;

/**
* Adds a service that depends on all JNDI bindings from the deployment to be up.
@@ -40,37 +44,58 @@
* is necessary to ensure the deployment is not considered complete until add bindings are up
*
* @author Stuart Douglas
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class JndiNamingDependencyProcessor implements DeploymentUnitProcessor {

private static final ServiceName JNDI_DEPENDENCY_SERVICE = ServiceName.of("jndiDependencyService");

private static final String JNDI_AGGREGATION_SERVICE_SUFFIX = "componentJndiDependencies";

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
ServiceName namingStoreServiceName = support.getCapabilityServiceName(NamingService.CAPABILITY_NAME);
//this will always be up but we need to make sure the naming service is
//not shut down before the deployment is undeployed when the container is shut down
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, namingStoreServiceName);

List<ServiceName> dependencies = deploymentUnit.getAttachmentList(Attachments.JNDI_DEPENDENCIES);
final ServiceName serviceName = serviceName(deploymentUnit.getServiceName());
final ServiceBuilder<?> serviceBuilder = phaseContext.getServiceTarget().addService(serviceName, new RuntimeBindReleaseService());
for (final ServiceName dependency : dependencies) {
serviceBuilder.requires(dependency);
}
if(deploymentUnit.getParent() != null) {
for (final ServiceName jndiDependency : deploymentUnit.getParent().getAttachment(Attachments.JNDI_DEPENDENCIES)) {
serviceBuilder.requires(jndiDependency);
}
addAllDependencies(serviceBuilder, deploymentUnit.getAttachmentList(Attachments.JNDI_DEPENDENCIES));
Map<ServiceName, Set<ServiceName>> compJndiDeps = deploymentUnit.getAttachment(Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> aggregatingServices = installComponentJndiAggregatingServices(phaseContext.getServiceTarget(), compJndiDeps);
addAllDependencies(serviceBuilder, aggregatingServices);
if (deploymentUnit.getParent() != null) {
addAllDependencies(serviceBuilder, deploymentUnit.getParent().getAttachment(Attachments.JNDI_DEPENDENCIES));
compJndiDeps = deploymentUnit.getParent().getAttachment(Attachments.COMPONENT_JNDI_DEPENDENCIES);
aggregatingServices = installComponentJndiAggregatingServices(phaseContext.getServiceTarget(), compJndiDeps);
addAllDependencies(serviceBuilder, aggregatingServices);
}
serviceBuilder.requires(namingStoreServiceName);
serviceBuilder.install();
}

private static Set<ServiceName> installComponentJndiAggregatingServices(final ServiceTarget target, final Map<ServiceName, Set<ServiceName>> mappings) {
final Set<ServiceName> retVal = new HashSet<>();
ServiceBuilder sb;
ServiceName sn;
for (final Map.Entry<ServiceName, Set<ServiceName>> mapping : mappings.entrySet()) {
sn = mapping.getKey().append(JNDI_AGGREGATION_SERVICE_SUFFIX);
retVal.add(sn);
sb = target.addService(sn);
for (final ServiceName depName : mapping.getValue()) sb.requires(depName);
sb.install();
}
return retVal;
}

private static void addAllDependencies(final ServiceBuilder sb, final Collection<ServiceName> dependencies) {
for (final ServiceName dependency : dependencies) {
sb.requires(dependency);
}
}

public static ServiceName serviceName(final ServiceName deploymentUnitServiceName) {
return deploymentUnitServiceName.append(JNDI_DEPENDENCY_SERVICE);
}
@@ -21,6 +21,10 @@
*/
package org.jboss.as.txn.deployment;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.UserTransaction;

@@ -52,6 +56,7 @@
* regardless of the presence of the {@link javax.annotation.Resource} annotation.
*
* @author Stuart Douglas
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class TransactionJndiBindingProcessor implements DeploymentUnitProcessor {
@Override
@@ -96,7 +101,12 @@ private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTa
new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector()))
.addDependency(contextServiceName, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector())
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES,userTransactionServiceName);
final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(userTransactionServiceName);

final ServiceName transactionSynchronizationRegistryName = contextServiceName.append("TransactionSynchronizationRegistry");
BinderService transactionSyncBinderService = new BinderService("TransactionSynchronizationRegistry");
@@ -105,7 +115,7 @@ private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTa
new ManagedReferenceInjector<TransactionSynchronizationRegistry>(transactionSyncBinderService.getManagedObjectInjector()))
.addDependency(contextServiceName, ServiceBasedNamingStore.class, transactionSyncBinderService.getNamingStoreInjector())
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES,transactionSynchronizationRegistryName);
jndiDependencies.add(transactionSynchronizationRegistryName);
}


@@ -21,7 +21,9 @@
*/
package org.jboss.as.weld.deployment.processors;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

@@ -53,7 +55,6 @@
import org.jboss.as.weld.util.Utils;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.value.ImmediateValue;
import org.jboss.msc.value.InjectedValue;
@@ -76,9 +77,6 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
return;
}

final Collection<ServiceName> dependencies = deploymentUnit.getAttachment(Attachments.JNDI_DEPENDENCIES);


BeanDeploymentArchiveImpl rootBda = deploymentUnit
.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
if (rootBda == null) {
@@ -111,30 +109,35 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || deploymentUnit.getName().endsWith(".jar")) {
// bind the bean manager to JNDI
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
bindBeanManager(serviceTarget, beanManagerServiceName, moduleContextServiceName, dependencies, phaseContext.getServiceRegistry());
bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, moduleContextServiceName);
}


//bind the bm into java:comp for all components that require it
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component.getNamingMode() == ComponentNamingMode.CREATE) {
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName());
bindBeanManager(serviceTarget, beanManagerServiceName, compContextServiceName, dependencies, phaseContext.getServiceRegistry());
bindBeanManager(deploymentUnit, serviceTarget, beanManagerServiceName, compContextServiceName);
}
}
deploymentUnit.addToAttachmentList(Attachments.SETUP_ACTIONS, new WeldContextSetup());
}

private void bindBeanManager(ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName, final Collection<ServiceName> dependencies, final ServiceRegistry serviceRegistry) {
private void bindBeanManager(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName) {
final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager");
dependencies.add(beanManagerBindingServiceName);
BinderService beanManagerBindingService = new BinderService("BeanManager");
final BeanManagerManagedReferenceFactory referenceFactory = new BeanManagerManagedReferenceFactory();
beanManagerBindingService.getManagedObjectInjector().inject(referenceFactory);
serviceTarget.addService(beanManagerBindingServiceName, beanManagerBindingService)
.addDependency(contextServiceName, ServiceBasedNamingStore.class, beanManagerBindingService.getNamingStoreInjector())
.addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager)
.install();
final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(beanManagerBindingServiceName);
}

@Override

0 comments on commit edb5969

Please sign in to comment.
You can’t perform that action at this time.