Skip to content

Commit

Permalink
[WFCORE-1235] : Multiple triggers of each activator service when ther…
Browse files Browse the repository at this point in the history
…e are multiple modules with different service activator files in an ear..

[WFCORE-1234] : DuplicateServiceException if the ServiceActivator is moved from the jar module to the EAR deployment level.
  • Loading branch information
panossot committed Feb 23, 2016
1 parent a464315 commit c9c36ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public final class Attachments {

public static final AttachmentKey<Map<String, MountedDeploymentOverlay>> DEPLOYMENT_OVERLAY_LOCATIONS = AttachmentKey.create(Map.class);

public static final AttachmentKey<Set<String>> DEPLOYMENT_SERVICE_ACTIVATORS = AttachmentKey.create(Set.class);

/**
* Support for getting and creating resource models on a deployment's resource.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package org.jboss.as.server.deployment.service;

import java.util.HashSet;
import java.util.Set;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand Down Expand Up @@ -50,14 +52,19 @@ public class ServiceActivatorProcessor implements DeploymentUnitProcessor {
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parentDeploymentUnit = deploymentUnit.getParent()==null?deploymentUnit:deploymentUnit.getParent();
final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES);
Set<String> serviceActivatorAttachment = parentDeploymentUnit.getAttachment(Attachments.DEPLOYMENT_SERVICE_ACTIVATORS);
if(servicesAttachment == null || servicesAttachment.getServiceImplementations(ServiceActivator.class.getName()).isEmpty())
return; // Skip it if it has not been marked

final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null)
return; // Skip deployments with no module

if (serviceActivatorAttachment == null)
serviceActivatorAttachment = new HashSet<String>();

ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry();
if(WildFlySecurityManager.isChecking()) {
//service registry allows you to modify internal server state across all deployments
Expand All @@ -66,16 +73,20 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
}
final ServiceActivatorContext serviceActivatorContext = new ServiceActivatorContextImpl(phaseContext.getServiceTarget(), serviceRegistry);

final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
for (ServiceActivator serviceActivator : module.loadService(ServiceActivator.class)) {
for(ServiceActivator serviceActivator : module.loadService(ServiceActivator.class)) {
try {
serviceActivator.activate(serviceActivatorContext);
if(!serviceActivatorAttachment.contains(serviceActivator.getClass().toString())) {
serviceActivator.activate(serviceActivatorContext);
serviceActivatorAttachment.add(serviceActivator.getClass().toString());
}
} catch (ServiceRegistryException e) {
throw new DeploymentUnitProcessingException(e);
throw new DeploymentUnitProcessingException(e);
}
}
parentDeploymentUnit.putAttachment(Attachments.DEPLOYMENT_SERVICE_ACTIVATORS, serviceActivatorAttachment);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current);
}
Expand Down

0 comments on commit c9c36ca

Please sign in to comment.