use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JMSBridgeAdd method createJMSBridge.
private JMSBridge createJMSBridge(OperationContext context, ModelNode model) throws OperationFailedException {
final Properties sourceContextProperties = resolveContextProperties(JMSBridgeDefinition.SOURCE_CONTEXT, context, model);
final String sourceConnectionFactoryName = JMSBridgeDefinition.SOURCE_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
final ConnectionFactoryFactory sourceCff = new JNDIConnectionFactoryFactory(sourceContextProperties, sourceConnectionFactoryName);
final String sourceDestinationName = JMSBridgeDefinition.SOURCE_DESTINATION.resolveModelAttribute(context, model).asString();
final DestinationFactory sourceDestinationFactory = new JNDIDestinationFactory(sourceContextProperties, sourceDestinationName);
final Properties targetContextProperties = resolveContextProperties(JMSBridgeDefinition.TARGET_CONTEXT, context, model);
final String targetConnectionFactoryName = JMSBridgeDefinition.TARGET_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
final ConnectionFactoryFactory targetCff = new JNDIConnectionFactoryFactory(targetContextProperties, targetConnectionFactoryName);
final String targetDestinationName = JMSBridgeDefinition.TARGET_DESTINATION.resolveModelAttribute(context, model).asString();
final DestinationFactory targetDestinationFactory = new JNDIDestinationFactory(targetContextProperties, targetDestinationName);
final String sourceUsername = resolveAttribute(JMSBridgeDefinition.SOURCE_USER, context, model);
final String sourcePassword = resolveAttribute(JMSBridgeDefinition.SOURCE_PASSWORD, context, model);
final String targetUsername = resolveAttribute(JMSBridgeDefinition.TARGET_USER, context, model);
final String targetPassword = resolveAttribute(JMSBridgeDefinition.TARGET_PASSWORD, context, model);
final String selector = resolveAttribute(CommonAttributes.SELECTOR, context, model);
final long failureRetryInterval = JMSBridgeDefinition.FAILURE_RETRY_INTERVAL.resolveModelAttribute(context, model).asLong();
final int maxRetries = JMSBridgeDefinition.MAX_RETRIES.resolveModelAttribute(context, model).asInt();
final QualityOfServiceMode qosMode = QualityOfServiceMode.valueOf(JMSBridgeDefinition.QUALITY_OF_SERVICE.resolveModelAttribute(context, model).asString());
final int maxBatchSize = JMSBridgeDefinition.MAX_BATCH_SIZE.resolveModelAttribute(context, model).asInt();
final long maxBatchTime = JMSBridgeDefinition.MAX_BATCH_TIME.resolveModelAttribute(context, model).asLong();
final String subName = resolveAttribute(JMSBridgeDefinition.SUBSCRIPTION_NAME, context, model);
final String clientID = resolveAttribute(JMSBridgeDefinition.CLIENT_ID, context, model);
final boolean addMessageIDInHeader = JMSBridgeDefinition.ADD_MESSAGE_ID_IN_HEADER.resolveModelAttribute(context, model).asBoolean();
final String moduleName = resolveAttribute(JMSBridgeDefinition.MODULE, context, model);
final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
// will use the correct class loader to execute its threads
if (moduleName != null) {
ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
Module module = Module.getCallerModuleLoader().loadModule(moduleID);
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
}
return new JMSBridgeImpl(sourceCff, targetCff, sourceDestinationFactory, targetDestinationFactory, sourceUsername, sourcePassword, targetUsername, targetPassword, selector, failureRetryInterval, maxRetries, qosMode, maxBatchSize, maxBatchTime, subName, clientID, addMessageIDInHeader);
} catch (ModuleLoadException e) {
throw MessagingLogger.ROOT_LOGGER.unableToLoadModule(moduleName, e);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JMSBridgeService method startBridge.
public void startBridge() throws Exception {
final Module module;
if (moduleName != null) {
ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
module = Module.getContextModuleLoader().loadModule(moduleID);
} else {
module = Module.forClass(JMSBridgeService.class);
}
ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
setJMSBridgePasswordsFromCredentialSource();
bridge.start();
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
MessagingLogger.ROOT_LOGGER.startedService("JMS Bridge", bridgeName);
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class ModuleConfig method visit.
@Override
public void visit(ConfigVisitor visitor) {
if (moduleName != null) {
ModuleIdentifier identifier = ModuleIdentifier.fromString(moduleName);
if (moduleName.startsWith(ServiceModuleLoader.MODULE_PREFIX)) {
ServiceName serviceName = ServiceModuleLoader.moduleServiceName(identifier);
visitor.addDependency(serviceName, getInjectedModule());
} else {
Module dm = visitor.loadModule(identifier);
getInjectedModule().setValue(new ImmediateValue<Module>(dm));
}
} else {
getInjectedModule().setValue(new ImmediateValue<Module>(visitor.getModule()));
}
// no children, no need to visit
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JPADependencyProcessor method addDependency.
private void addDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit, ModuleIdentifier... moduleIdentifiers) {
for (ModuleIdentifier moduleIdentifier : moduleIdentifiers) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, true, false));
ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class NamingBindingAdd method createObjectFactory.
private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException {
final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString());
final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
final Module module;
try {
module = Module.getBootModuleLoader().loadModule(moduleID);
} catch (ModuleLoadException e) {
throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID);
}
final ObjectFactory objectFactoryClassInstance;
final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
final Class<?> clazz = module.getClassLoader().loadClass(className);
objectFactoryClassInstance = (ObjectFactory) clazz.newInstance();
} catch (ClassNotFoundException e) {
throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID);
} catch (InstantiationException e) {
throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
} catch (IllegalAccessException e) {
throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
} catch (ClassCastException e) {
throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}
return objectFactoryClassInstance;
}
Aggregations