use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ProtocolMetricsHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
String name = Operations.getAttributeName(operation);
try {
Protocol protocol = this.locator.findProtocol(context);
if (protocol != null) {
Attribute attribute = getAttribute(protocol.getClass(), name);
if (attribute != null) {
FieldType type = FieldType.valueOf(attribute.getType());
try {
ModelNode result = new ModelNode();
Object value = attribute.read(protocol);
if (value != null) {
type.setValue(result, value);
}
context.getResult().set(result);
} catch (Exception e) {
context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.privilegedAccessExceptionForAttribute(name));
}
} else {
context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
}
}
} catch (ClassNotFoundException | ModuleLoadException e) {
context.getFailureDescription().set(e.getLocalizedMessage());
} finally {
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class JdbcDriverAdd method performRuntime.
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) {
throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName);
}
String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null;
try {
moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e);
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
boolean driverLoaded = false;
if (serviceLoader != null) {
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
driverLoaded = true;
// w/ explicit declaration of driver-class attribute
break;
}
}
if (!driverLoaded)
SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
} 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);
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
}
}
}
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 (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);
}
}
}
Aggregations