org.jboss.as.clustering.controller.AbstractModulesServiceConfigurator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wildfly-clustering-common Show documentation
Show all versions of wildfly-clustering-common Show documentation
The code in this module is not explicitly related to clustering, but rather contains resuable code used by clustering modules
and any modules that integrate with clustering.
The newest version!
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.jboss.as.clustering.controller;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.server.Services;
import org.jboss.dmr.ModelNode;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
import org.wildfly.subsystem.resource.ResourceModelResolver;
import org.wildfly.subsystem.service.ResourceServiceConfigurator;
import org.wildfly.subsystem.service.ResourceServiceInstaller;
import org.wildfly.subsystem.service.ServiceDependency;
import org.wildfly.subsystem.service.capability.CapabilityServiceInstaller;
/**
* @author Paul Ferraro
*/
public abstract class AbstractModulesServiceConfigurator implements ResourceServiceConfigurator, Function, T> {
private final RuntimeCapability capability;
private final ResourceModelResolver> resolver;
AbstractModulesServiceConfigurator(RuntimeCapability capability, ResourceModelResolver> resolver) {
this.capability = capability;
this.resolver = resolver;
}
@Override
public ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException {
List moduleIdentifiers = this.resolver.resolve(context, model);
ServiceDependency loader = ServiceDependency.on(Services.JBOSS_SERVICE_MODULE_LOADER);
Supplier> modules = new Supplier<>() {
@Override
public List get() {
return moduleIdentifiers.stream().map(this::load).collect(Collectors.toUnmodifiableList());
}
private Module load(String identifier) {
try {
return loader.get().loadModule(identifier);
} catch (ModuleLoadException e) {
throw new IllegalArgumentException(e);
}
}
};
return CapabilityServiceInstaller.builder(this.capability, this, modules)
.requires(loader)
.asPassive()
.build();
}
}