Skip to content

Commit cd0f508

Browse files
committed
[WFCORE-3720] Update ServiceModuleLoader to use non-deprecated JBoss Modules APIs
1 parent b124810 commit cd0f508

12 files changed

+101
-26
lines changed

server/src/main/java/org/jboss/as/server/deployment/DeploymentListModulesHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void execute(OperationContext context, ModelNode operation) {
7474
moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
7575
}
7676

77-
final ServiceController<?> moduleLoadServiceController = sr.getService(ServiceModuleLoader.moduleServiceName(moduleIdentifier));
77+
final ServiceController<?> moduleLoadServiceController = sr.getService(ServiceModuleLoader.moduleServiceName(moduleIdentifier.toString()));
7878
final ModuleLoadService moduleLoadService = (ModuleLoadService) moduleLoadServiceController.getService();
7979

8080
final ModelNode result = new ModelNode();

server/src/main/java/org/jboss/as/server/deployment/module/ManifestDependencyProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
100100
deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId);
101101
if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) {
102102
//additional modules will not be created till much later, a dep on them would fail
103-
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
103+
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId.toString()));
104104
}
105105
}
106106

server/src/main/java/org/jboss/as/server/deployment/module/ModuleExtensionListProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
8888
dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
8989
dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
9090
moduleSpecification.addLocalDependency(dependency);
91-
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension));
91+
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension.toString()));
9292
}
9393

9494

@@ -107,7 +107,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
107107
if (extension != null) {
108108
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, extension, false, false,
109109
true, false));
110-
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension));
110+
nextPhaseDeps.add(ServiceModuleLoader.moduleSpecServiceName(extension.toString()));
111111
} else {
112112
ServerLogger.DEPLOYMENT_LOGGER.cannotFindExtensionListEntry(entry, resourceRoot);
113113
}

server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void deployModuleSpec(final DeploymentPhaseContext phaseContext) throws
123123
for (final DeploymentUnit subDeployment : deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) {
124124
ModuleIdentifier moduleId = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
125125
if (moduleId != null) {
126-
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleSpecServiceName(moduleId));
126+
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleSpecServiceName(moduleId.toString()));
127127
}
128128
}
129129

@@ -260,7 +260,7 @@ private ServiceName createModuleService(final DeploymentPhaseContext phaseContex
260260
specBuilder.setClassFileTransformer(delegatingClassTransformer);
261261
deploymentUnit.putAttachment(DelegatingClassTransformer.ATTACHMENT_KEY, delegatingClassTransformer);
262262
final ModuleSpec moduleSpec = specBuilder.create();
263-
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);
263+
final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier.toString());
264264

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

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

288288
HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies());

server/src/main/java/org/jboss/as/server/deployment/module/descriptor/DeploymentStructureDescriptorParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private void handleDeployment(final DeploymentPhaseContext phaseContext, final D
288288
// additional modules will not be created till much later, a dep on them would fail
289289
if (identifier.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX) &&
290290
!(additionalModules.containsKey(identifier) || isSubdeployment(identifier, deploymentUnit))) {
291-
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier));
291+
phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(identifier.toString()));
292292
}
293293
}
294294
moduleSpec.setLocalLast(rootDeploymentSpecification.isLocalLast());

server/src/main/java/org/jboss/as/server/logging/ServerLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public interface ServerLogger extends BasicLogger {
733733
IllegalStateException serviceModuleLoaderAlreadyStopped();
734734

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

738738
@Message(id = 100, value = "Failed to read '%s'")
739739
DeploymentUnitProcessingException failedToReadVirtualFile(VirtualFile file, @Cause IOException cause);

server/src/main/java/org/jboss/as/server/moduleservice/ExtensionIndexService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public boolean accept(final File file) {
9595
// now register a module spec service for this extension
9696
// this makes it available for loading
9797
ExternalModuleSpecService service = new ExternalModuleSpecService(moduleIdentifier, jar);
98-
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);
98+
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier.toString());
9999
ServiceBuilder sb = context.getChildTarget().addService(serviceName, service);
100100
sb.requires(org.jboss.as.server.deployment.Services.JBOSS_DEPLOYMENT_EXTENSION_INDEX);
101101
sb.setInitialMode(Mode.ON_DEMAND);

server/src/main/java/org/jboss/as/server/moduleservice/ExternalModuleService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ModuleIdentifier addExternalModule(String moduleName, ServiceRegistry ser
5656
@Override
5757
public ModuleIdentifier addExternalModule(String moduleName, String path, ServiceRegistry serviceRegistry, ServiceTarget serviceTarget) {
5858
ModuleIdentifier identifier = ModuleIdentifier.fromString(EXTERNAL_MODULE_PREFIX + moduleName);
59-
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier);
59+
ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier.toString());
6060
ServiceController<?> controller = serviceRegistry.getService(serviceName);
6161
if (controller == null) {
6262
ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(path));

server/src/main/java/org/jboss/as/server/moduleservice/ExternalModuleSpecService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public synchronized void start(StartContext context) throws StartException {
112112
this.moduleDefinition = new ModuleDefinition(moduleIdentifier, Collections.emptySet(), moduleSpec);
113113

114114

115-
ServiceModuleLoader.installModuleResolvedService(context.getChildTarget(), moduleIdentifier);
115+
ServiceModuleLoader.installModuleResolvedService(context.getChildTarget(), moduleIdentifier.toString());
116116
}
117117

118118
@Override

server/src/main/java/org/jboss/as/server/moduleservice/ModuleLoadService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ public Module getValue() throws IllegalStateException, IllegalArgumentException
113113
}
114114

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

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

124124
builder.install();

server/src/main/java/org/jboss/as/server/moduleservice/ModuleResolvePhaseService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void start(final StartContext startContext) throws StartException {
6565
if (spec != null) { //this can happen for optional dependencies
6666
for (ModuleDependency dep : spec.getDependencies()) {
6767
if (dep.isOptional()) continue; // we don't care about optional dependencies
68-
if (ServiceModuleLoader.isDynamicModule(dep.getIdentifier())) {
68+
if (ServiceModuleLoader.isDynamicModule(dep.getIdentifier().toString())) {
6969
if (!alreadyResolvedModules.contains(dep.getIdentifier())) {
7070
nextAlreadySeen.add(dep.getIdentifier());
7171
nextPhaseIdentifiers.add(dep);
@@ -75,7 +75,7 @@ public void start(final StartContext startContext) throws StartException {
7575
}
7676
}
7777
if (nextPhaseIdentifiers.isEmpty()) {
78-
ServiceModuleLoader.installModuleResolvedService(startContext.getChildTarget(), moduleIdentifier);
78+
ServiceModuleLoader.installModuleResolvedService(startContext.getChildTarget(), moduleIdentifier.toString());
7979
} else {
8080
installService(startContext.getChildTarget(), moduleIdentifier, phaseNumber + 1, nextPhaseIdentifiers, nextAlreadySeen);
8181
}
@@ -92,7 +92,7 @@ private static void installService(final ServiceTarget serviceTarget, final Modu
9292
final ModuleResolvePhaseService nextPhaseService = new ModuleResolvePhaseService(moduleIdentifier, nextAlreadySeen, phaseNumber);
9393
ServiceBuilder<ModuleResolvePhaseService> builder = serviceTarget.addService(moduleSpecServiceName(moduleIdentifier, phaseNumber), nextPhaseService);
9494
for (ModuleDependency module : nextPhaseIdentifiers) {
95-
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(module.getIdentifier()), ModuleDefinition.class, new Injector<ModuleDefinition>() {
95+
builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(module.getIdentifier().toString()), ModuleDefinition.class, new Injector<ModuleDefinition>() {
9696

9797
ModuleDefinition definition;
9898

@@ -127,8 +127,8 @@ public Set<ModuleDefinition> getModuleSpecs() {
127127
}
128128

129129
public static ServiceName moduleSpecServiceName(ModuleIdentifier identifier, int phase) {
130-
if (!ServiceModuleLoader.isDynamicModule(identifier)) {
131-
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, ServiceModuleLoader.MODULE_PREFIX);
130+
if (!ServiceModuleLoader.isDynamicModule(identifier.toString())) {
131+
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier.toString(), ServiceModuleLoader.MODULE_PREFIX);
132132
}
133133
return SERVICE_NAME.append(identifier.getName()).append(identifier.getSlot()).append("" + phase);
134134
}

server/src/main/java/org/jboss/as/server/moduleservice/ServiceModuleLoader.java

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,19 @@ protected Module preloadModule(final String name) throws ModuleLoadException {
128128
}
129129
}
130130

131+
/**
132+
* @deprecated Will be made protected in line with this method in the parent class Use {@link ServiceModuleLoader#findModule(String)}
133+
*/
134+
@Deprecated(forRemoval = true, since = "27.0.0")
131135
@SuppressWarnings("unchecked")
132136
@Override
133137
public ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException {
138+
return findModule(identifier.toString());
139+
}
140+
141+
@SuppressWarnings("unchecked")
142+
@Override
143+
protected ModuleSpec findModule(String identifier) throws ModuleLoadException {
134144
ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(identifier));
135145
if (controller == null) {
136146
ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", identifier, identifier);
@@ -193,18 +203,42 @@ public static void addService(final ServiceTarget serviceTarget, final Bootstrap
193203
*
194204
* @param identifier The module identifier
195205
* @return The service name of the ModuleSpec service
206+
* @deprecated Use {@link ServiceModuleLoader#moduleSpecServiceName(String)}
196207
*/
208+
@Deprecated(forRemoval = true, since = "27.0.0")
197209
public static ServiceName moduleSpecServiceName(ModuleIdentifier identifier) {
210+
return moduleSpecServiceName(identifier.toString());
211+
}
212+
213+
/**
214+
* Returns the corresponding ModuleSpec service name for the given module.
215+
*
216+
* @param identifier The module identifier string, method does not support non-canonized identifiers
217+
* @return The service name of the ModuleSpec service
218+
*/
219+
public static ServiceName moduleSpecServiceName(String identifier) {
198220
if (!isDynamicModule(identifier)) {
199221
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
200222
}
201-
return MODULE_SPEC_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
223+
return MODULE_SPEC_SERVICE_PREFIX.append(identifier);
202224
}
203225

226+
/**
227+
* @deprecated Use {@link ServiceModuleLoader#installModuleResolvedService(ServiceTarget, String)}
228+
*/
229+
@Deprecated(forRemoval = true, since = "27.0.0")
204230
public static void installModuleResolvedService(ServiceTarget serviceTarget, ModuleIdentifier identifier) {
231+
installModuleResolvedService(serviceTarget, identifier.toString());
232+
}
233+
234+
/**
235+
* @param serviceTarget service target to use to install the service. Cannot be {@code null}.
236+
* @param identifier The module identifier string, method does not support non-canonized identifiers
237+
*/
238+
public static void installModuleResolvedService(ServiceTarget serviceTarget, String identifier) {
205239
final ServiceName sn = ServiceModuleLoader.moduleResolvedServiceName(identifier);
206240
final ServiceBuilder<?> sb = serviceTarget.addService(sn);
207-
final Consumer<ModuleIdentifier> moduleIdConsumer = sb.provides(sn);
241+
final Consumer<String> moduleIdConsumer = sb.provides(sn);
208242
sb.requires(moduleSpecServiceName(identifier));
209243
final org.jboss.msc.Service resolvedService = org.jboss.msc.Service.newInstance(moduleIdConsumer, identifier);
210244
sb.setInstance(resolvedService);
@@ -220,31 +254,72 @@ public static void installModuleResolvedService(ServiceTarget serviceTarget, Mod
220254
*
221255
* @param identifier The module identifier
222256
* @return The service name of the ModuleSpec service
257+
* @deprecated Use {@link ServiceModuleLoader#moduleResolvedServiceName(String)}
223258
*/
259+
@Deprecated(forRemoval = true, since = "27.0.0")
224260
public static ServiceName moduleResolvedServiceName(ModuleIdentifier identifier) {
261+
return moduleResolvedServiceName(identifier.toString());
262+
}
263+
264+
/**
265+
* Returns the corresponding module resolved service name for the given module.
266+
*
267+
* The module resolved service is basically a latch that prevents the module from being loaded
268+
* until all the transitive dependencies that it depends upon have have their module spec services
269+
* come up.
270+
*
271+
* @param identifier The module identifier string, method does not support non-canonized identifiers
272+
* @return The service name of the ModuleSpec service
273+
*/
274+
public static ServiceName moduleResolvedServiceName(String identifier) {
225275
if (!isDynamicModule(identifier)) {
226276
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
227277
}
228-
return MODULE_RESOLVED_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
278+
return MODULE_RESOLVED_SERVICE_PREFIX.append(identifier);
229279
}
230280

231281
/**
232282
* Returns true if the module identifier is a dynamic module that will be loaded by this module loader
283+
*
284+
* @deprecated Use {@link ServiceModuleLoader#isDynamicModule(String)}
233285
*/
286+
@Deprecated(forRemoval = true, since = "27.0.0")
234287
public static boolean isDynamicModule(ModuleIdentifier identifier) {
235-
return identifier.getName().startsWith(MODULE_PREFIX);
288+
return isDynamicModule(identifier.toString());
289+
}
290+
291+
/**
292+
* Returns true if the module identifier is a dynamic module that will be loaded by this module loader
293+
*
294+
* @param identifier The module identifier string, method does not support non-canonized identifiers
295+
* @return Whether the module identifier is a dynamic module
296+
*/
297+
public static boolean isDynamicModule(String identifier) {
298+
return identifier.startsWith(MODULE_PREFIX);
236299
}
237300

238301
/**
239302
* Returns the corresponding ModuleLoadService service name for the given module.
240303
*
241304
* @param identifier The module identifier
242305
* @return The service name of the ModuleLoadService service
306+
* @deprecated Use {@link ServiceModuleLoader#moduleServiceName(String)}
243307
*/
308+
@Deprecated(forRemoval = true, since = "27.0.0")
244309
public static ServiceName moduleServiceName(ModuleIdentifier identifier) {
245-
if (!identifier.getName().startsWith(MODULE_PREFIX)) {
310+
return moduleServiceName(identifier.toString());
311+
}
312+
313+
/**
314+
* Returns the corresponding ModuleLoadService service name for the given module.
315+
*
316+
* @param identifier The module identifier string, method does not support non-canonized identifiers
317+
* @return The service name of the ModuleLoadService service
318+
*/
319+
public static ServiceName moduleServiceName(String identifier) {
320+
if (!identifier.startsWith(MODULE_PREFIX)) {
246321
throw ServerLogger.ROOT_LOGGER.missingModulePrefix(identifier, MODULE_PREFIX);
247322
}
248-
return MODULE_SERVICE_PREFIX.append(identifier.getName()).append(identifier.getSlot());
323+
return MODULE_SERVICE_PREFIX.append(identifier);
249324
}
250325
}

0 commit comments

Comments
 (0)