From b40be4c11eb356a7478f98799feb88b8b5d414b1 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Wed, 20 Dec 2023 15:11:18 -0500 Subject: [PATCH] WFCORE-6347 Add convenience method for generating a composite ResourceServiceConfigurator. --- .../service/ResourceServiceConfigurator.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/subsystem/src/main/java/org/wildfly/subsystem/service/ResourceServiceConfigurator.java b/subsystem/src/main/java/org/wildfly/subsystem/service/ResourceServiceConfigurator.java index 1a8021da5bd..ef01fe9679b 100644 --- a/subsystem/src/main/java/org/wildfly/subsystem/service/ResourceServiceConfigurator.java +++ b/subsystem/src/main/java/org/wildfly/subsystem/service/ResourceServiceConfigurator.java @@ -4,6 +4,10 @@ */ package org.wildfly.subsystem.service; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; @@ -22,4 +26,31 @@ public interface ResourceServiceConfigurator { * @throws OperationFailedException if there was a failure reading the model or resolving expressions/capabilities */ ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException; + + /** + * Returns a composite {@link ResourceServiceConfigurator} that configures the specified service configurators. + * @param configurators a variable number of configurators + * @return a composite service configurator + */ + static ResourceServiceConfigurator combine(ResourceServiceConfigurator... configurators) { + return combine(List.of(configurators)); + } + + /** + * Returns a composite {@link ResourceServiceConfigurator} that configures the specified service configurators. + * @param configurators a collection of configurators + * @return a composite configurator + */ + static ResourceServiceConfigurator combine(Collection configurators) { + return new ResourceServiceConfigurator() { + @Override + public ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException { + List installers = new ArrayList<>(configurators.size()); + for (ResourceServiceConfigurator configurator : configurators) { + installers.add(configurator.configure(context, model)); + } + return ResourceServiceInstaller.combine(installers); + } + }; + } }