use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class JdbcDriverRemove method recoverServices.
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) {
final String driverName = model.require(DRIVER_NAME.getName()).asString();
final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
try {
moduleId = ModuleIdentifier.fromString(moduleName);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleNotFoundException e) {
context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()));
return;
} catch (ModuleLoadException e) {
context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName));
return;
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
if (serviceLoader != null)
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
}
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
}
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class GetDataSourceClassInfoOperationHandler method findPropsFromCls.
private static ModelNode findPropsFromCls(ServiceModuleLoader serviceModuleLoader, ModuleIdentifier mid, String clsName) throws OperationFailedException {
Class<?> cls = null;
if (mid != null) {
try {
cls = Class.forName(clsName, true, serviceModuleLoader.loadModule(mid.toString()).getClassLoader());
} catch (ModuleLoadException | ClassNotFoundException e) {
throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e);
}
}
if (cls == null) {
try {
cls = Class.forName(clsName);
} catch (ClassNotFoundException e) {
throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e);
}
}
Map<String, Type> methodsMap = new TreeMap<>();
for (Method method : possiblePropsSetters(cls)) {
methodsMap.putIfAbsent(deCapitalize(method.getName().substring(3)), method.getParameterTypes()[0]);
}
final ModelNode result = new ModelNode();
for (Map.Entry<String, Type> prop : methodsMap.entrySet()) {
result.get(prop.getKey()).set(prop.getValue().getTypeName());
}
return result;
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class MicroProfileReactiveMessagingExtension method initialize.
@Override
public void initialize(ExtensionContext extensionContext) {
// Initialize the Netty logger factory or we get horrible stack traces
ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(this.getClass());
if (cl instanceof ModuleClassLoader) {
ModuleLoader loader = ((ModuleClassLoader) cl).getModule().getModuleLoader();
try {
Module module = loader.loadModule("io.netty");
InternalLoggerFactory.setDefaultFactory(JdkLoggerFactory.INSTANCE);
} catch (ModuleLoadException e) {
// The netty module is not there so don't do anything
}
}
final SubsystemRegistration sr = extensionContext.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
sr.registerXMLElementWriter(CURRENT_PARSER);
final ManagementResourceRegistration root = sr.registerSubsystemModel(new MicroProfileReactiveMessagingSubsystemDefinition());
root.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE, false);
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ModClusterSubsystemServiceHandler method addLoadMetrics.
private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException {
for (Property property1 : nodes.asPropertyList()) {
ModelNode node = property1.getValue();
double capacity = LoadMetricResourceDefinition.SharedAttribute.CAPACITY.resolveModelAttribute(context, node).asDouble();
int weight = LoadMetricResourceDefinition.SharedAttribute.WEIGHT.resolveModelAttribute(context, node).asInt();
Class<? extends LoadMetric> loadMetricClass = null;
if (node.hasDefined(LoadMetricResourceDefinition.Attribute.TYPE.getName())) {
String type = LoadMetricResourceDefinition.Attribute.TYPE.resolveModelAttribute(context, node).asString();
// MODCLUSTER-288 Metric "mem" has been dropped, keep it in the model for versions prior to 8.0
if (type.equals("mem")) {
ROOT_LOGGER.unsupportedMetric(type);
continue;
}
LoadMetricEnum metric = LoadMetricEnum.forType(type);
loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null;
} else {
String className = CustomLoadMetricResourceDefinition.Attribute.CLASS.resolveModelAttribute(context, node).asString();
String moduleName = CustomLoadMetricResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, node).asString();
try {
Module module = Module.getContextModuleLoader().loadModule(moduleName);
loadMetricClass = module.getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
} catch (ModuleLoadException e) {
ROOT_LOGGER.errorLoadingModuleForCustomMetric(moduleName, e);
} catch (ClassNotFoundException e) {
ROOT_LOGGER.errorAddingMetrics(e);
}
}
if (loadMetricClass != null) {
try {
LoadMetric metric = loadMetricClass.newInstance();
metric.setCapacity(capacity);
metric.setWeight(weight);
Properties props = new Properties();
for (Property property : LoadMetricResourceDefinition.SharedAttribute.PROPERTY.resolveModelAttribute(context, node).asPropertyListOrEmpty()) {
props.put(property.getName(), property.getValue().asString());
}
// Apply Java Bean properties if any are set
if (!props.isEmpty()) {
try {
BeanUtils.mapJavaBeanProperties(metric, props, true);
} catch (Exception ex) {
ROOT_LOGGER.errorApplyingMetricProperties(ex, loadMetricClass.getCanonicalName());
// Do not add this incomplete metric.
continue;
}
}
metrics.add(metric);
} catch (InstantiationException | IllegalAccessException e) {
ROOT_LOGGER.errorAddingMetrics(e);
}
}
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly-swarm by wildfly-swarm.
the class TranslatorCustomizer method loadTranslators.
@SuppressWarnings("rawtypes")
private void loadTranslators(String moduleName) {
ClassLoader translatorLoader = this.getClass().getClassLoader();
try {
final Module module = Module.getBootModuleLoader().loadModule(moduleName);
if (module != null) {
translatorLoader = module.getClassLoader();
final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
if (serviceLoader != null) {
for (ExecutionFactory ef : serviceLoader) {
Translator t = ef.getClass().getAnnotation(Translator.class);
fraction.translator(t.name(), x -> x.module(moduleName));
}
}
}
} catch (ModuleLoadException e) {
// no-op
}
}
Aggregations