Skip to content

Commit

Permalink
Merge pull request wildfly#5225 from ropalka/WFCORE-6066
Browse files Browse the repository at this point in the history
[WFCORE-6066] Rewriting DeploymentUnitServices to use MSC values API
  • Loading branch information
yersan authored Sep 30, 2022
2 parents 38ad68e + 480d86b commit 523b7cd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public abstract class AbstractDeploymentUnitService implements Service<Deploymen
final ManagementResourceRegistration mutableRegistration;
final Resource resource;
final CapabilityServiceSupport capabilityServiceSupport;
private final Consumer<DeploymentUnit> 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<DeploymentUnit> 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;
Expand Down Expand Up @@ -106,6 +108,7 @@ public synchronized void start(final StartContext context) throws StartException
} else {
installer.accept(context);
}
deploymentUnitConsumer.accept(deploymentUnit);
}

/**
Expand All @@ -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) {
Expand All @@ -144,7 +148,6 @@ public synchronized void stop(final StopContext context) {
private Set<AttachmentKey<?>> getDeploymentUnitAttachmentKeys() {
return ((SimpleAttachable) this.deploymentUnit).attachmentKeys();
}

public synchronized DeploymentUnit getValue() throws IllegalStateException, IllegalArgumentException {
return deploymentUnit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<DeploymentUnit> deploymentUnitConsumer = sb.provides(deploymentUnitServiceName);
final Supplier<DeploymentMountProvider> serverDeploymentRepositorySupplier = sb.requires(DeploymentMountProvider.SERVICE_NAME);
final Supplier<PathManager> pathManagerSupplier = sb.requires(context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class));
final Supplier<VirtualFile> 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<DeploymentUnit> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
final class RootDeploymentUnitService extends AbstractDeploymentUnitService {
private final InjectedValue<DeploymentMountProvider> serverDeploymentRepositoryInjector = new InjectedValue<DeploymentMountProvider>();
private final InjectedValue<PathManager> pathManagerInjector = new InjectedValue<PathManager>();
private final InjectedValue<VirtualFile> contentsInjector = new InjectedValue<VirtualFile>();
private final Supplier<DeploymentMountProvider> serverDeploymentRepositorySupplier;
private final Supplier<PathManager> pathManagerSupplier;
private final Supplier<VirtualFile> contentsSupplier;
private final String name;
private final String managementName;
private final DeploymentUnit parent;
Expand All @@ -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<DeploymentUnit> deploymentUnitConsumer,
final Supplier<DeploymentMountProvider> serverDeploymentRepositorySupplier,
final Supplier<PathManager> pathManagerSupplier,
final Supplier<VirtualFile> 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;
Expand All @@ -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<DeploymentMountProvider> getServerDeploymentRepositoryInjector() {
return serverDeploymentRepositoryInjector;
}

InjectedValue<PathManager> getPathManagerInjector() {
return pathManagerInjector;
}

InjectedValue<VirtualFile> getContentsInjector() {
return contentsInjector;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
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;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
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;
Expand All @@ -39,6 +41,7 @@
* Deployment processor responsible to creating deployment unit services for sub-deployment.
*
* @author John Bailey
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class SubDeploymentProcessor implements DeploymentUnitProcessor {

Expand All @@ -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<DeploymentUnit> 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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:[email protected]">Richard Opalka</a>
*/
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<DeploymentUnit> 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;
Expand Down

0 comments on commit 523b7cd

Please sign in to comment.