Skip to content

Commit

Permalink
[WFCORE-3720] Update ServiceModuleLoader to use non-deprecated JBoss …
Browse files Browse the repository at this point in the history
…Modules APIs
  • Loading branch information
lvydra committed Nov 27, 2024
1 parent 2bdbac3 commit f2cbe06
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void execute(OperationContext context, ModelNode operation) {
moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
}

final ServiceController<?> moduleLoadServiceController = sr.getService(ServiceModuleLoader.moduleServiceName(moduleIdentifier));
final ServiceController<?> moduleLoadServiceController = sr.getService(ServiceModuleLoader.moduleServiceName(moduleIdentifier.toString()));
final ModuleLoadService moduleLoadService = (ModuleLoadService) moduleLoadServiceController.getService();

final ModelNode result = new ModelNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId);
if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) {
//additional modules will not be created till much later, a dep on them would fail
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId.toString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
moduleSpecification.addLocalDependency(dependency);
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension));
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension.toString()));
}


Expand All @@ -107,7 +107,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
if (extension != null) {
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, extension, false, false,
true, false));
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension));
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension.toString()));
} else {
ServerLogger.DEPLOYMENT_LOGGER.cannotFindExtensionListEntry(entry, resourceRoot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void deployModuleSpec(final DeploymentPhaseContext phaseContext) throws
for (final DeploymentUnit subDeployment : deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) {
ModuleIdentifier moduleId = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
if (moduleId != null) {
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleSpecServiceName(moduleId));
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleSpecServiceName(moduleId.toString()));
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ private ServiceName createModuleService(final DeploymentPhaseContext phaseContex
specBuilder.setClassFileTransformer(delegatingClassTransformer);
deploymentUnit.putAttachment(DelegatingClassTransformer.ATTACHMENT_KEY, delegatingClassTransformer);
final ModuleSpec moduleSpec = specBuilder.create();
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier.toString());

ModuleDefinition moduleDefinition = new ModuleDefinition(moduleIdentifier, new HashSet<>(moduleSpecification.getAllDependencies()), moduleSpec);

Expand All @@ -282,7 +282,7 @@ private void installAliases(final ModuleSpecification moduleSpecification, final
ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
for (final String aliasName : moduleSpecification.getModuleAliases()) {
final ModuleIdentifier alias = ModuleIdentifier.fromString(aliasName);
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias);
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias.toString());
final ModuleSpec spec = ModuleSpec.buildAlias(aliasName, moduleIdentifier.getName()).create();

HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D
// additional modules will not be created till much later, a dep on them would fail
if (identifier.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX) &&
!(additionalModules.containsKey(identifier) || isSubdeployment(identifier, deploymentUnit))) {
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier));
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier.toString()));
}
}
moduleSpec.setLocalLast(rootDeploymentSpecification.isLocalLast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ public interface ServerLogger extends BasicLogger {
IllegalStateException serviceModuleLoaderAlreadyStopped();

@Message(id = 99, value = "'%s' cannot be loaded from a ServiceModuleLoader as its name does not start with '%s'")
IllegalArgumentException missingModulePrefix(ModuleIdentifier identifier, String prefix);
IllegalArgumentException missingModulePrefix(String name, String prefix);

@Message(id = 100, value = "Failed to read '%s'")
DeploymentUnitProcessingException failedToReadVirtualFile(VirtualFile file, @Cause IOException cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean accept(final File file) {
// now register a module spec service for this extension
// this makes it available for loading
ExternalModuleSpecService service = new ExternalModuleSpecService(moduleIdentifier, jar);
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier.toString());
ServiceBuilder sb = context.getChildTarget().addService(serviceName, service);
sb.requires(org.jboss.as.server.deployment.Services.JBOSS_DEPLOYMENT_EXTENSION_INDEX);
sb.setInitialMode(Mode.ON_DEMAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ModuleIdentifier addExternalModule(String moduleName, ServiceRegistry ser
@Override
public ModuleIdentifier addExternalModule(String moduleName, String path, ServiceRegistry serviceRegistry, ServiceTarget serviceTarget) {
ModuleIdentifier identifier = ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + moduleName);
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier);
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier.toString());
ServiceController<?> controller = serviceRegistry.getService(serviceName);
if (controller == null) {
ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public synchronized void start(StartContext context) throws StartException {
this.moduleDefinition = new ModuleDefinition(moduleIdentifier, Collections.emptySet(), moduleSpec);


ServiceModuleLoader.installModuleResolvedService(context.getChildTarget(), moduleIdentifier);
ServiceModuleLoader.installModuleResolvedService(context.getChildTarget(), moduleIdentifier.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public Module getValue() throws IllegalStateException, IllegalArgumentException
}

private static ServiceName install(final ServiceTarget target, final ModuleIdentifier identifier, ModuleLoadService service) {
final ServiceName serviceName = ServiceModuleLoader.moduleServiceName(identifier);
final ServiceName serviceName = ServiceModuleLoader.moduleServiceName(identifier.toString());
final ServiceBuilder<Module> builder = target.addService(serviceName, service);

builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoader());
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(identifier), ModuleDefinition.class, service.getModuleDefinitionInjectedValue());
builder.requires(ServiceModuleLoader.moduleResolvedServiceName(identifier)); //don't attempt to load until all dependent module specs are up, even transitive ones
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(identifier.toString()), ModuleDefinition.class, service.getModuleDefinitionInjectedValue());
builder.requires(ServiceModuleLoader.moduleResolvedServiceName(identifier.toString())); //don't attempt to load until all dependent module specs are up, even transitive ones
builder.setInitialMode(Mode.ON_DEMAND);

builder.install();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void start(final StartContext startContext) throws StartException {
if (spec != null) { //this can happen for optional dependencies
for (ModuleDependency dep : spec.getDependencies()) {
if (dep.isOptional()) continue; // we don't care about optional dependencies
if (ServiceModuleLoader.isDynamicModule(dep.getIdentifier())) {
if (ServiceModuleLoader.isDynamicModule(dep.getIdentifier().toString())) {
if (!alreadyResolvedModules.contains(dep.getIdentifier())) {
nextAlreadySeen.add(dep.getIdentifier());
nextPhaseIdentifiers.add(dep);
Expand All @@ -75,7 +75,7 @@ public void start(final StartContext startContext) throws StartException {
}
}
if (nextPhaseIdentifiers.isEmpty()) {
ServiceModuleLoader.installModuleResolvedService(startContext.getChildTarget(), moduleIdentifier);
ServiceModuleLoader.installModuleResolvedService(startContext.getChildTarget(), moduleIdentifier.toString());
} else {
installService(startContext.getChildTarget(), moduleIdentifier, phaseNumber + 1, nextPhaseIdentifiers, nextAlreadySeen);
}
Expand All @@ -92,7 +92,7 @@ private static void installService(final ServiceTarget serviceTarget, final Modu
final ModuleResolvePhaseService nextPhaseService = new ModuleResolvePhaseService(moduleIdentifier, nextAlreadySeen, phaseNumber);
ServiceBuilder<ModuleResolvePhaseService> builder = serviceTarget.addService(moduleSpecServiceName(moduleIdentifier, phaseNumber), nextPhaseService);
for (ModuleDependency module : nextPhaseIdentifiers) {
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(module.getIdentifier()), ModuleDefinition.class, new Injector<ModuleDefinition>() {
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(module.getIdentifier().toString()), ModuleDefinition.class, new Injector<ModuleDefinition>() {

ModuleDefinition definition;

Expand Down Expand Up @@ -127,8 +127,8 @@ public Set<ModuleDefinition> getModuleSpecs() {
}

public static ServiceName moduleSpecServiceName(ModuleIdentifier identifier, int phase) {
if (!ServiceModuleLoader.isDynamicModule(identifier)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, ServiceModuleLoader.MODULE_PREFIX);
if (!ServiceModuleLoader.isDynamicModule(identifier.toString())) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier.toString(), ServiceModuleLoader.MODULE_PREFIX);
}
return SERVICE_NAME.append(identifier.getName()).append(identifier.getSlot()).append("" + phase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ protected Module preloadModule(final String name) throws ModuleLoadException {

@SuppressWarnings("unchecked")
@Override
public ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException {
ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(identifier));
public ModuleSpec findModule(String name) throws ModuleLoadException {
ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(name));
if (controller == null) {
ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", identifier, identifier);
ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", name, name);
return null;
}
UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1);
Expand Down Expand Up @@ -191,22 +191,22 @@ public static void addService(final ServiceTarget serviceTarget, final Bootstrap
/**
* Returns the corresponding ModuleSpec service name for the given module.
*
* @param identifier The module identifier
* @param name The module name
* @return The service name of the ModuleSpec service
*/
public static ServiceName moduleSpecServiceName(ModuleIdentifier identifier) {
if (!isDynamicModule(identifier)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
public static ServiceName moduleSpecServiceName(String name) {
if (!isDynamicModule(name)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(name, MODULE_PREFIX);
}
return MODULE_SPEC_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
return MODULE_SPEC_SERVICE_PREFIX.append(name);
}

public static void installModuleResolvedService(ServiceTarget serviceTarget, ModuleIdentifier identifier) {
final ServiceName sn = ServiceModuleLoader.moduleResolvedServiceName(identifier);
public static void installModuleResolvedService(ServiceTarget serviceTarget, String name) {
final ServiceName sn = ServiceModuleLoader.moduleResolvedServiceName(name);
final ServiceBuilder<?> sb = serviceTarget.addService(sn);
final Consumer<ModuleIdentifier> moduleIdConsumer = sb.provides(sn);
sb.requires(moduleSpecServiceName(identifier));
final org.jboss.msc.Service resolvedService = org.jboss.msc.Service.newInstance(moduleIdConsumer, identifier);
final Consumer<String> moduleIdConsumer = sb.provides(sn);
sb.requires(moduleSpecServiceName(name));
final org.jboss.msc.Service resolvedService = org.jboss.msc.Service.newInstance(moduleIdConsumer, name);
sb.setInstance(resolvedService);
sb.install();
}
Expand All @@ -218,33 +218,45 @@ public static void installModuleResolvedService(ServiceTarget serviceTarget, Mod
* until all the transitive dependencies that it depends upon have have their module spec services
* come up.
*
* @param identifier The module identifier
* @param name The module name
* @return The service name of the ModuleSpec service
*/
public static ServiceName moduleResolvedServiceName(ModuleIdentifier identifier) {
if (!isDynamicModule(identifier)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
public static ServiceName moduleResolvedServiceName(String name) {
if (!isDynamicModule(name)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(name, MODULE_PREFIX);
}
return MODULE_RESOLVED_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
return MODULE_RESOLVED_SERVICE_PREFIX.append(name);
}

/**
* Returns true if the module identifier is a dynamic module that will be loaded by this module loader
*/
public static boolean isDynamicModule(ModuleIdentifier identifier) {
return identifier.getName().startsWith(MODULE_PREFIX);
public static boolean isDynamicModule(String name) {
return name.startsWith(MODULE_PREFIX);
}

/**
* Returns the corresponding ModuleLoadService service name for the given module.
*
* @param identifier The module identifier
* @return The service name of the ModuleLoadService service
* @deprecated Use {@link ServiceModuleLoader#moduleServiceName(String)}
*/
@Deprecated(forRemoval = true)
public static ServiceName moduleServiceName(ModuleIdentifier identifier) {
if (!identifier.getName().startsWith(MODULE_PREFIX)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
return moduleServiceName(identifier.toString());
}

/**
* Returns the corresponding ModuleLoadService service name for the given module.
*
* @param name The module name
* @return The service name of the ModuleLoadService service
*/
public static ServiceName moduleServiceName(String name) {
if (!name.startsWith(MODULE_PREFIX)) {
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(name, MODULE_PREFIX);
}
return MODULE_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
return MODULE_SERVICE_PREFIX.append(name);
}
}

0 comments on commit f2cbe06

Please sign in to comment.