Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-6347 Add convenience method for generating a composite ResourceServiceConfigurator. #5809

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<? extends ResourceServiceConfigurator> configurators) {
return new ResourceServiceConfigurator() {
@Override
public ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException {
List<ResourceServiceInstaller> installers = new ArrayList<>(configurators.size());
for (ResourceServiceConfigurator configurator : configurators) {
installers.add(configurator.configure(context, model));
}
return ResourceServiceInstaller.combine(installers);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
public interface ResourceServiceInstaller {

/**
* Installs a service into the target associated with the specified operation context.
* @param context an operation context
* @return a mechanism to remove the installed service
*/
Consumer<OperationContext> install(OperationContext context);

/**
* Returns a composite {@link ResourceServiceInstaller} that installs the specified installers.
* @param installers a variable number of installers
Expand Down Expand Up @@ -50,11 +57,4 @@ public void accept(OperationContext context) {
}
};
}

/**
* Installs a service into the target associated with the specified operation context.
* @param context an operation context
* @return a mechanism to remove the installed service
*/
Consumer<OperationContext> install(OperationContext context);
}