diff --git a/server/src/main/java/org/jboss/as/server/deployment/AbstractDeploymentUnitService.java b/server/src/main/java/org/jboss/as/server/deployment/AbstractDeploymentUnitService.java index 30e7494867c..7212fa94ed3 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/AbstractDeploymentUnitService.java +++ b/server/src/main/java/org/jboss/as/server/deployment/AbstractDeploymentUnitService.java @@ -55,11 +55,13 @@ public abstract class AbstractDeploymentUnitService implements Service deploymentUnitConsumer; private volatile DeploymentUnitPhaseBuilder phaseBuilder = null; private volatile DeploymentUnit deploymentUnit; private volatile StabilityMonitor monitor; - AbstractDeploymentUnitService(final ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, final Resource resource, final CapabilityServiceSupport capabilityServiceSupport) { + AbstractDeploymentUnitService(final Consumer deploymentUnitConsumer, final ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, final Resource resource, final CapabilityServiceSupport capabilityServiceSupport) { + this.deploymentUnitConsumer = deploymentUnitConsumer; this.mutableRegistration = mutableRegistration; this.capabilityServiceSupport = capabilityServiceSupport; this.registration = registration; @@ -106,6 +108,7 @@ public synchronized void start(final StartContext context) throws StartException } else { installer.accept(context); } + deploymentUnitConsumer.accept(deploymentUnit); } /** @@ -119,6 +122,7 @@ public synchronized void start(final StartContext context) throws StartException @Override public synchronized void stop(final StopContext context) { + deploymentUnitConsumer.accept(null); final String deploymentName = context.getController().getName().getSimpleName(); final String managementName = deploymentUnit.getAttachment(Attachments.MANAGEMENT_NAME); if (deploymentUnit.getParent()==null) { @@ -144,7 +148,6 @@ public synchronized void stop(final StopContext context) { private Set> getDeploymentUnitAttachmentKeys() { return ((SimpleAttachable) this.deploymentUnit).attachmentKeys(); } - public synchronized DeploymentUnit getValue() throws IllegalStateException, IllegalArgumentException { return deploymentUnit; } diff --git a/server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtil.java b/server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtil.java index 45c64ceec23..72c771cb601 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtil.java +++ b/server/src/main/java/org/jboss/as/server/deployment/DeploymentHandlerUtil.java @@ -34,6 +34,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Supplier; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; @@ -57,6 +59,7 @@ import org.jboss.dmr.ModelNode; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; +import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; @@ -211,15 +214,17 @@ public static void doDeploy(final OperationContext context, final String deploym // associated with the current OperationContext AnnotationIndexSupport annotationIndexSupport = getAnnotationIndexCache(context); - final RootDeploymentUnitService service = new RootDeploymentUnitService(deploymentUnitName, managementName, null, + final ServiceBuilder sb = serviceTarget.addService(deploymentUnitServiceName); + final Consumer deploymentUnitConsumer = sb.provides(deploymentUnitServiceName); + final Supplier serverDeploymentRepositorySupplier = sb.requires(DeploymentMountProvider.SERVICE_NAME); + final Supplier pathManagerSupplier = sb.requires(context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class)); + final Supplier contentsSupplier = sb.requires(contentsServiceName); + final RootDeploymentUnitService service = new RootDeploymentUnitService(deploymentUnitConsumer, + serverDeploymentRepositorySupplier, pathManagerSupplier, contentsSupplier, + deploymentUnitName, managementName, null, registration, mutableRegistration, deploymentResource, context.getCapabilityServiceSupport(), overlays, annotationIndexSupport, isExplodedContent); - final ServiceController deploymentUnitController = serviceTarget.addService(deploymentUnitServiceName, service) - .addDependency(DeploymentMountProvider.SERVICE_NAME, DeploymentMountProvider.class, service.getServerDeploymentRepositoryInjector()) - .addDependency(context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class), PathManager.class, service.getPathManagerInjector()) - .addDependency(contentsServiceName, VirtualFile.class, service.getContentsInjector()) - .setInitialMode(ServiceController.Mode.ACTIVE) - .install(); + final ServiceController deploymentUnitController = sb.setInstance(service).install(); contentService.addListener(new LifecycleListener() { @Override diff --git a/server/src/main/java/org/jboss/as/server/deployment/RootDeploymentUnitService.java b/server/src/main/java/org/jboss/as/server/deployment/RootDeploymentUnitService.java index 7857e657c40..e166fae69f5 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/RootDeploymentUnitService.java +++ b/server/src/main/java/org/jboss/as/server/deployment/RootDeploymentUnitService.java @@ -23,6 +23,8 @@ package org.jboss.as.server.deployment; import java.lang.ref.WeakReference; +import java.util.function.Consumer; +import java.util.function.Supplier; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; @@ -31,20 +33,19 @@ import org.jboss.as.controller.services.path.PathManager; import org.jboss.as.server.deployment.annotation.AnnotationIndexSupport; import org.jboss.as.server.deploymentoverlay.DeploymentOverlayIndex; -import org.jboss.msc.inject.Injector; import org.jboss.msc.service.ServiceRegistry; -import org.jboss.msc.value.InjectedValue; import org.jboss.vfs.VirtualFile; /** * The top-level service corresponding to a deployment unit. * * @author David M. Lloyd + * @author Richard Opalka */ final class RootDeploymentUnitService extends AbstractDeploymentUnitService { - private final InjectedValue serverDeploymentRepositoryInjector = new InjectedValue(); - private final InjectedValue pathManagerInjector = new InjectedValue(); - private final InjectedValue contentsInjector = new InjectedValue(); + private final Supplier serverDeploymentRepositorySupplier; + private final Supplier pathManagerSupplier; + private final Supplier contentsSupplier; private final String name; private final String managementName; private final DeploymentUnit parent; @@ -65,14 +66,21 @@ final class RootDeploymentUnitService extends AbstractDeploymentUnitService { * @param annotationIndexSupport operation-scoped cache of static module annotation indexes * @param exploded the deployment has been exploded */ - public RootDeploymentUnitService(final String name, final String managementName, final DeploymentUnit parent, + public RootDeploymentUnitService(final Consumer deploymentUnitConsumer, + final Supplier serverDeploymentRepositorySupplier, + final Supplier pathManagerSupplier, + final Supplier contentsSupplier, + final String name, final String managementName, final DeploymentUnit parent, final ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, final Resource resource, final CapabilityServiceSupport capabilityServiceSupport, final DeploymentOverlayIndex deploymentOverlays, final AnnotationIndexSupport annotationIndexSupport, final boolean exploded) { - super(registration, mutableRegistration, resource, capabilityServiceSupport); + super(deploymentUnitConsumer, registration, mutableRegistration, resource, capabilityServiceSupport); assert name != null : "name is null"; + this.serverDeploymentRepositorySupplier = serverDeploymentRepositorySupplier; + this.pathManagerSupplier = pathManagerSupplier; + this.contentsSupplier = contentsSupplier; this.name = name; this.managementName = managementName; this.parent = parent; @@ -88,34 +96,22 @@ public RootDeploymentUnitService(final String name, final String managementName, protected DeploymentUnit createAndInitializeDeploymentUnit(final ServiceRegistry registry) { final DeploymentUnit deploymentUnit = new DeploymentUnitImpl(parent, name, registry); deploymentUnit.putAttachment(Attachments.MANAGEMENT_NAME, managementName); - deploymentUnit.putAttachment(Attachments.DEPLOYMENT_CONTENTS, contentsInjector.getValue()); + deploymentUnit.putAttachment(Attachments.DEPLOYMENT_CONTENTS, contentsSupplier.get()); deploymentUnit.putAttachment(DeploymentResourceSupport.REGISTRATION_ATTACHMENT, registration); deploymentUnit.putAttachment(DeploymentResourceSupport.MUTABLE_REGISTRATION_ATTACHMENT, mutableRegistration); deploymentUnit.putAttachment(DeploymentResourceSupport.DEPLOYMENT_RESOURCE, resource); deploymentUnit.putAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT, new DeploymentResourceSupport(deploymentUnit)); deploymentUnit.putAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT, capabilityServiceSupport); deploymentUnit.putAttachment(Attachments.DEPLOYMENT_OVERLAY_INDEX, deploymentOverlays); - deploymentUnit.putAttachment(Attachments.PATH_MANAGER, pathManagerInjector.getValue()); + deploymentUnit.putAttachment(Attachments.PATH_MANAGER, pathManagerSupplier.get()); deploymentUnit.putAttachment(Attachments.ANNOTATION_INDEX_SUPPORT, annotationIndexSupport); if(this.isExplodedContent) { MountExplodedMarker.setMountExploded(deploymentUnit); } // Attach the deployment repo - deploymentUnit.putAttachment(Attachments.SERVER_DEPLOYMENT_REPOSITORY, serverDeploymentRepositoryInjector.getValue()); + deploymentUnit.putAttachment(Attachments.SERVER_DEPLOYMENT_REPOSITORY, serverDeploymentRepositorySupplier.get()); return deploymentUnit; } - - Injector getServerDeploymentRepositoryInjector() { - return serverDeploymentRepositoryInjector; - } - - InjectedValue getPathManagerInjector() { - return pathManagerInjector; - } - - InjectedValue getContentsInjector() { - return contentsInjector; - } } diff --git a/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentProcessor.java b/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentProcessor.java index 0a63a8fa010..1fdfc18b9b3 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentProcessor.java +++ b/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentProcessor.java @@ -23,6 +23,7 @@ package org.jboss.as.server.deployment; import java.util.List; +import java.util.function.Consumer; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; @@ -30,6 +31,7 @@ import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.services.path.PathManager; import org.jboss.as.server.deployment.module.ResourceRoot; +import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; @@ -39,6 +41,7 @@ * Deployment processor responsible to creating deployment unit services for sub-deployment. * * @author John Bailey + * @author Richard Opalka */ public class SubDeploymentProcessor implements DeploymentUnitProcessor { @@ -64,14 +67,12 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU final ManagementResourceRegistration mutableRegistration = deploymentUnit.getAttachment(DeploymentResourceSupport.MUTABLE_REGISTRATION_ATTACHMENT); final CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final PathManager pathManager = deploymentUnit.getAttachment(Attachments.PATH_MANAGER); - final SubDeploymentUnitService service = new SubDeploymentUnitService(childRoot, deploymentUnit, registration, - mutableRegistration, resource, capabilityServiceSupport, pathManager); - final ServiceName serviceName = Services.deploymentUnitName(deploymentUnit.getName(), childRoot.getRootName()); - - serviceTarget.addService(serviceName, service) - .setInitialMode(ServiceController.Mode.ACTIVE) - .install(); + final ServiceBuilder sb = serviceTarget.addService(serviceName); + final Consumer deploymentUnitConsumer = sb.provides(serviceName); + final SubDeploymentUnitService service = new SubDeploymentUnitService(deploymentUnitConsumer, childRoot, deploymentUnit, registration, mutableRegistration, resource, capabilityServiceSupport, pathManager); + sb.setInstance(service); + sb.install(); phaseContext.addDeploymentDependency(serviceName, Attachments.SUB_DEPLOYMENTS); //we also need a dep on the first phase of the sub deployments phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, serviceName.append(ServiceName.of(Phase.STRUCTURE.name()))); diff --git a/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentUnitService.java b/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentUnitService.java index ec711dc30f1..9bc0596d160 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentUnitService.java +++ b/server/src/main/java/org/jboss/as/server/deployment/SubDeploymentUnitService.java @@ -32,18 +32,21 @@ import org.jboss.as.server.logging.ServerLogger; import org.jboss.msc.service.ServiceRegistry; +import java.util.function.Consumer; + /** * Service responsible for installing the correct services to install a {@link DeploymentUnit}. * * @author John Bailey + * @author Richard Opalka */ final class SubDeploymentUnitService extends AbstractDeploymentUnitService { private final ResourceRoot deploymentRoot; private final DeploymentUnit parent; private final PathManager pathManager; - public SubDeploymentUnitService(ResourceRoot deploymentRoot, DeploymentUnit parent, ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, Resource resource, CapabilityServiceSupport capabilityServiceSupport, PathManager pathManager) { - super(registration, mutableRegistration, resource, capabilityServiceSupport); + public SubDeploymentUnitService(final Consumer deploymentUnitConsumer, ResourceRoot deploymentRoot, DeploymentUnit parent, ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, Resource resource, CapabilityServiceSupport capabilityServiceSupport, PathManager pathManager) { + super(deploymentUnitConsumer, registration, mutableRegistration, resource, capabilityServiceSupport); this.pathManager = pathManager; if (deploymentRoot == null) throw ServerLogger.ROOT_LOGGER.deploymentRootRequired(); this.deploymentRoot = deploymentRoot;