Skip to content

Commit

Permalink
[WFLY-11298] Refactoring - eliminating ServiceBuilder.addDependency(S…
Browse files Browse the repository at this point in the history
…erviceName) method usages in weld subsystem.
  • Loading branch information
ropalka committed Nov 12, 2018
1 parent a958681 commit 8019224
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.jboss.as.weld.CdiValidatorFactoryService;
import org.jboss.as.weld.ServiceNames;
import org.jboss.msc.inject.CastingInjector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;

Expand All @@ -57,11 +58,11 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName serviceName = deploymentUnit.getServiceName().append(CdiValidatorFactoryService.SERVICE_NAME);
final CdiValidatorFactoryService cdiValidatorFactoryService = new CdiValidatorFactoryService(deploymentUnit);
serviceTarget.addService(serviceName, cdiValidatorFactoryService)
.addDependency(ServiceNames.beanManagerServiceName(deploymentUnit),
new CastingInjector<BeanManager>(cdiValidatorFactoryService.getBeanManagerInjector(), BeanManager.class))
.addDependency(weldStartService)
.install();
final ServiceBuilder sb = serviceTarget.addService(serviceName, cdiValidatorFactoryService);
sb.addDependency(ServiceNames.beanManagerServiceName(deploymentUnit),
new CastingInjector<BeanManager>(cdiValidatorFactoryService.getBeanManagerInjector(), BeanManager.class));
sb.requires(weldStartService);
sb.install();
}

@Override
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.jboss.as.weld.services.BeanManagerService;
import org.jboss.as.weld.util.Utils;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
Expand All @@ -43,10 +44,10 @@ public class WeldClassIntrospector implements EEClassIntrospector, Service<EECla

public static void install(final DeploymentUnit deploymentUnit, final ServiceTarget serviceTarget) {
final WeldClassIntrospector introspector = new WeldClassIntrospector();
serviceTarget.addService(serviceName(deploymentUnit), introspector)
.addDependency(BeanManagerService.serviceName(deploymentUnit), BeanManager.class, introspector.beanManager)
.addDependency(Utils.getRootDeploymentUnit(deploymentUnit).getServiceName().append(WeldStartService.SERVICE_NAME))
.install();
final ServiceBuilder sb = serviceTarget.addService(serviceName(deploymentUnit), introspector);
sb.addDependency(BeanManagerService.serviceName(deploymentUnit), BeanManager.class, introspector.beanManager);
sb.requires(Utils.getRootDeploymentUnit(deploymentUnit).getServiceName().append(WeldStartService.SERVICE_NAME));
sb.install();
}

public static ServiceName serviceName(DeploymentUnit deploymentUnit) {
Expand Down
Expand Up @@ -182,13 +182,14 @@ private void addWeldIntegration(final Iterable<ComponentIntegrator> componentInt
final WeldComponentService weldComponentService = new WeldComponentService(componentClass, beanName, interceptorClasses, classLoader,
beanDeploymentArchiveId, description.isCDIInterceptorEnabled(), description, isComponentWithView(description, componentIntegrators));
final ServiceBuilder<WeldComponentService> builder = target.addService(serviceName, weldComponentService)
.addDependency(weldServiceName, WeldBootstrapService.class, weldComponentService.getWeldContainer()).addDependency(weldStartService);
.addDependency(weldServiceName, WeldBootstrapService.class, weldComponentService.getWeldContainer());
builder.requires(weldStartService);

configuration.setInstanceFactory(WeldManagedReferenceFactory.INSTANCE);
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(serviceName);
serviceBuilder.requires(serviceName);
}
});

Expand Down Expand Up @@ -248,10 +249,10 @@ protected void run(Object instance) {
private static ServiceName addWeldInterceptorBindingService(final ServiceTarget target, final ComponentConfiguration configuration, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final String beanDeploymentArchiveId, final ComponentInterceptorSupport componentInterceptorSupport) {
final WeldInterceptorBindingsService weldInterceptorBindingsService = new WeldInterceptorBindingsService(beanDeploymentArchiveId, beanName, componentClass, componentInterceptorSupport);
ServiceName bindingServiceName = configuration.getComponentDescription().getServiceName().append(WeldInterceptorBindingsService.SERVICE_NAME);
target.addService(bindingServiceName, weldInterceptorBindingsService)
.addDependency(weldServiceName, WeldBootstrapService.class, weldInterceptorBindingsService.getWeldContainer())
.addDependency(weldStartService)
.install();
final ServiceBuilder sb = target.addService(bindingServiceName, weldInterceptorBindingsService);
sb.addDependency(weldServiceName, WeldBootstrapService.class, weldInterceptorBindingsService.getWeldContainer());
sb.requires(weldStartService);
sb.install();
return bindingServiceName;
}

Expand Down
Expand Up @@ -103,8 +103,8 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
ServiceBuilder<WeldStartCompletionService> weldStartCompletionServiceBuilder = serviceTarget
.addService(weldStartCompletionServiceName, weldStartCompletionService)
.addDependency(weldBootstrapServiceName, WeldBootstrapService.class, weldStartCompletionService.getBootstrap())
.addDependency(Services.JBOSS_SERVER_EXECUTOR, ExecutorService.class, weldStartCompletionService.getServerExecutor())
.addDependency(weldStartServiceName);
.addDependency(Services.JBOSS_SERVER_EXECUTOR, ExecutorService.class, weldStartCompletionService.getServerExecutor());
weldStartCompletionServiceBuilder.requires(weldStartServiceName);
weldStartCompletionServiceBuilder.install();
}

Expand Down
Expand Up @@ -237,7 +237,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
// add the weld service
final ServiceBuilder<WeldBootstrapService> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceName, weldBootstrapService);

weldBootstrapServiceBuilder.addDependency(TCCLSingletonService.SERVICE_NAME);
weldBootstrapServiceBuilder.requires(TCCLSingletonService.SERVICE_NAME);
weldBootstrapServiceBuilder.addDependency(WeldExecutorServices.SERVICE_NAME, ExecutorServices.class, weldBootstrapService.getExecutorServices());
weldBootstrapServiceBuilder.addDependency(Services.JBOSS_SERVER_EXECUTOR, ExecutorService.class, weldBootstrapService.getServerExecutor());

Expand Down Expand Up @@ -267,24 +267,24 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
ServiceBuilder<WeldStartService> startService = serviceTarget.addService(weldStartServiceName, weldStartService)
.addDependency(weldBootstrapServiceName, WeldBootstrapService.class, weldStartService.getBootstrap());
for (final ServiceName dependency : dependencies) {
startService.addDependency(dependency);
startService.requires(dependency);
}

// make sure JNDI bindings are up
startService.addDependency(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
startService.requires(JndiNamingDependencyProcessor.serviceName(deploymentUnit));

final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
boolean tx = capabilities.hasCapability("org.wildfly.transactions");
// [WFLY-5232]
for (final ServiceName jndiSubsystemDependency : getJNDISubsytemDependencies(tx)) {
startService.addDependency(jndiSubsystemDependency);
startService.requires(jndiSubsystemDependency);
}

final EarMetaData earConfig = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earConfig == null || !earConfig.getInitializeInOrder()) {
// in-order install of sub-deployments may result in service dependencies deadlocks if the jndi dependency services of subdeployments are added as dependencies
for (DeploymentUnit sub : subDeployments) {
startService.addDependency(JndiNamingDependencyProcessor.serviceName(sub));
startService.requires(JndiNamingDependencyProcessor.serviceName(sub));
}
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.jboss.as.weld.ServiceNames;
import org.jboss.as.weld.services.bootstrap.WeldTransactionServices;
import org.jboss.as.weld.spi.BootstrapDependencyInstaller;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;

Expand All @@ -40,10 +41,10 @@ public ServiceName install(ServiceTarget serviceTarget, DeploymentUnit deploymen

final ServiceName weldTransactionServiceName = deploymentUnit.getServiceName().append(WeldTransactionServices.SERVICE_NAME);

serviceTarget.addService(weldTransactionServiceName, weldTransactionServices)
// Ensure the local transaction provider is started before we start
.addDependency(ServiceNames.capabilityServiceName(deploymentUnit, "org.wildfly.transactions.global-default-local-provider"))
.install();
final ServiceBuilder sb = serviceTarget.addService(weldTransactionServiceName, weldTransactionServices);
// Ensure the local transaction provider is started before we start
sb.requires(ServiceNames.capabilityServiceName(deploymentUnit, "org.wildfly.transactions.global-default-local-provider"));
sb.install();

return weldTransactionServiceName;
}
Expand Down

0 comments on commit 8019224

Please sign in to comment.