org.jboss.modules.Module.loadServiceFromCallerModuleLoader()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.jboss.modules.Module.loadServiceFromCallerModuleLoader()方法的一些代码示例,展示了Module.loadServiceFromCallerModuleLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Module.loadServiceFromCallerModuleLoader()方法的具体详情如下:
包路径:org.jboss.modules.Module
类名称:Module
方法名:loadServiceFromCallerModuleLoader

Module.loadServiceFromCallerModuleLoader介绍

[英]Load a service loader from a module in the caller's module loader. The caller's module loader refers to the loader of the module of the class that calls this method. Note that #loadService(Class) is more efficient since it does not need to crawl the stack.
[中]从调用者模块加载器中的模块加载服务加载器。调用方的模块加载器指调用此方法的类的模块加载器。注意#loadService(Class)更有效,因为它不需要对堆栈进行爬网。

代码示例

代码示例来源:origin: wildfly/wildfly

static <T> T loadService(String moduleName, String className, final Class<T> type) throws ConfigXMLParseException {
    if (className != null) {
      try {
        Module.loadClassFromCallerModuleLoader(moduleName, className).asSubclass(type).newInstance();
      } catch (ModuleLoadException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    } else {
      try {
        final ServiceLoader<T> loader = Module.loadServiceFromCallerModuleLoader(moduleName, type);
        final Iterator<T> iterator = loader.iterator();
        try {
          if (!iterator.hasNext()) {
            throw new InvalidDiscoveryConfigurationException("No provider found in module " + moduleName);
          }
          return iterator.next();
        } catch (ServiceConfigurationError e) {
          throw new InvalidDiscoveryConfigurationException(e);
        }
      } catch (ModuleLoadException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    }
    return null;
  }
}

代码示例来源:origin: org.jboss.modules/jboss-modules

/**
 * Load a service loader from a module in the caller's module loader. The caller's
 * module loader refers to the loader of the module of the class that calls this method.
 * Note that {@link #loadService(Class)} is more efficient since it does not need to crawl
 * the stack.
 *
 * @param <S> the the service type
 * @param identifier the module identifier containing the service loader
 * @param serviceType the service type class
 * @return the loaded service from the caller's module
 * @throws ModuleLoadException if the named module failed to load
 * @deprecated Use {@link #loadServiceFromCallerModuleLoader(String, Class)} instead.
 */
@Deprecated
public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, Class<S> serviceType) throws ModuleLoadException {
  return loadServiceFromCallerModuleLoader(identifier.toString(), serviceType);
}

代码示例来源:origin: org.wildfly.core/wildfly-domain-management

private List<PlugInProvider> loadPlugInProvider(final String name) {
  synchronized (cachedProviders) {
    List<PlugInProvider> response;
    if (cachedProviders.containsKey(name)) {
      response = cachedProviders.get(name);
    } else {
      List<PlugInProvider> providers = new LinkedList<PlugInProvider>();
      try {
        for (PlugInProvider current : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(name),
            PlugInProvider.class)) {
          providers.add(current);
        }
      } catch (ModuleLoadException e) {
        throw DomainManagementLogger.ROOT_LOGGER.unableToLoadPlugInProviders(name, e.getMessage());
      }
      if (providers.size() > 0) {
        cachedProviders.put(name, providers);
        response = providers;
      } else {
        throw DomainManagementLogger.ROOT_LOGGER.noPlugInProvidersLoaded(name);
      }
    }
    return response;
  }
}

代码示例来源:origin: wildfly/wildfly-core

private List<PlugInProvider> loadPlugInProvider(final String name) {
  synchronized (cachedProviders) {
    List<PlugInProvider> response;
    if (cachedProviders.containsKey(name)) {
      response = cachedProviders.get(name);
    } else {
      List<PlugInProvider> providers = new LinkedList<PlugInProvider>();
      try {
        for (PlugInProvider current : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(name),
            PlugInProvider.class)) {
          providers.add(current);
        }
      } catch (ModuleLoadException e) {
        throw DomainManagementLogger.ROOT_LOGGER.unableToLoadPlugInProviders(name, e.getMessage());
      }
      if (providers.size() > 0) {
        cachedProviders.put(name, providers);
        response = providers;
      } else {
        throw DomainManagementLogger.ROOT_LOGGER.noPlugInProvidersLoaded(name);
      }
    }
    return response;
  }
}

代码示例来源:origin: org.wildfly.discovery/wildfly-discovery-client

static <T> T loadService(String moduleName, String className, final Class<T> type) throws ConfigXMLParseException {
    if (className != null) {
      try {
        Module.loadClassFromCallerModuleLoader(moduleName, className).asSubclass(type).newInstance();
      } catch (ModuleLoadException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    } else {
      try {
        final ServiceLoader<T> loader = Module.loadServiceFromCallerModuleLoader(moduleName, type);
        final Iterator<T> iterator = loader.iterator();
        try {
          if (!iterator.hasNext()) {
            throw new InvalidDiscoveryConfigurationException("No provider found in module " + moduleName);
          }
          return iterator.next();
        } catch (ServiceConfigurationError e) {
          throw new InvalidDiscoveryConfigurationException(e);
        }
      } catch (ModuleLoadException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    }
    return null;
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

static <T> T loadService(String moduleName, String className, final Class<T> type) throws ConfigXMLParseException {
    if (className != null) {
      try {
        Module.loadClassFromCallerModuleLoader(moduleName, className).asSubclass(type).newInstance();
      } catch (ModuleLoadException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    } else {
      try {
        final ServiceLoader<T> loader = Module.loadServiceFromCallerModuleLoader(moduleName, type);
        final Iterator<T> iterator = loader.iterator();
        try {
          if (!iterator.hasNext()) {
            throw new InvalidDiscoveryConfigurationException("No provider found in module " + moduleName);
          }
          return iterator.next();
        } catch (ServiceConfigurationError e) {
          throw new InvalidDiscoveryConfigurationException(e);
        }
      } catch (ModuleLoadException e) {
        throw new InvalidDiscoveryConfigurationException(e);
      }
    }
    return null;
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-controller

public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersion, String extensionModuleName) {
  try {
    SubsystemTransformerRegistration transformerRegistration = new SubsystemTransformerRegistrationImpl(name, subsystemVersion);
    if (Module.getCallerModule() != null) { //only register when running in modular environment, testsuite does its own loading
      for (ExtensionTransformerRegistration registration : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(extensionModuleName), ExtensionTransformerRegistration.class)) {
        if (registration.getSubsystemName().equals(name)) { //to prevent registering transformers for different subsystems
          registration.registerTransformers(transformerRegistration);
        }
      }
    }
  } catch (ModuleLoadException e) {
    throw ControllerLogger.ROOT_LOGGER.couldNotLoadModuleForTransformers(extensionModuleName, e);
  }
}

代码示例来源:origin: org.jboss.as/jboss-as-controller

void initializeExtension(String module) throws OperationFailedException {
  try {
    boolean unknownModule = false;
    for (Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
      ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
      try {
        if (unknownModule || !extensionRegistry.getExtensionModuleNames().contains(module)) {
          // This extension wasn't handled by the standalone.xml or domain.xml parsing logic, so we
          // need to initialize its parsers so we can display what XML namespaces it supports
          extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
          // AS7-6190 - ensure we initialize parsers for other extensions from this module
          // now that we know the registry was unaware of the module
          unknownModule = true;
        }
        extension.initialize(extensionRegistry.getExtensionContext(module, !standalone && !slaveHC));
      } finally {
        SecurityActions.setThreadContextClassLoader(oldTccl);
      }
    }
  } catch (ModuleLoadException e) {
    throw new OperationFailedException(new ModelNode().set(e.toString()));
  }
}

代码示例来源:origin: wildfly/wildfly-core

public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersion, String extensionModuleName) {
  try {
    SubsystemTransformerRegistration transformerRegistration = new SubsystemTransformerRegistrationImpl(name, subsystemVersion);
    if (Module.getCallerModule() != null) { //only register when running in modular environment, testsuite does its own loading
      for (ExtensionTransformerRegistration registration : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(extensionModuleName), ExtensionTransformerRegistration.class)) {
        if (registration.getSubsystemName().equals(name)) { //to prevent registering transformers for different subsystems
          registration.registerTransformers(transformerRegistration);
        }
      }
    }
  } catch (ModuleLoadException e) {
    throw ControllerLogger.ROOT_LOGGER.couldNotLoadModuleForTransformers(extensionModuleName, e);
  }
}

代码示例来源:origin: wildfly/wildfly-core

protected void initializeExtension(String module, ManagementResourceRegistration rootRegistration) throws OperationFailedException {
    try {
      for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
        ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
        try {
          extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
          extension.initialize(extensionRegistry.getExtensionContext(module, rootRegistration, ExtensionRegistryType.SLAVE));
        } finally {
          SecurityActions.setThreadContextClassLoader(oldTccl);
        }
      }
    } catch (ModuleLoadException e) {
      throw DomainControllerLogger.ROOT_LOGGER.failedToLoadModule(e, module);
    }
  }
}

代码示例来源:origin: wildfly/wildfly-core

boolean unknownModule = false;
boolean initialized = false;
for (Extension extension : Module.loadServiceFromCallerModuleLoader(module, Extension.class)) {
  ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
  try {

代码示例来源:origin: org.jboss.as/jboss-as-domain-controller

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
  final ModelNode domainModel = operation.get(DOMAIN_MODEL);
  // We get the model as a list of resources descriptions
  if (!appliedExensions) {
    for(final ModelNode resourceDescription : domainModel.asList()) {
      appliedExensions = true;
      final PathAddress resourceAddress = PathAddress.pathAddress(resourceDescription.require("domain-resource-address"));
      final Resource resource = context.createResource(resourceAddress);
      if(resourceAddress.size() == 1 && resourceAddress.getElement(0).getKey().equals(ModelDescriptionConstants.EXTENSION)) {
        final String module = resourceAddress.getElement(0).getValue();
        try {
          for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
            ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
            try {
              extension.initialize(extensionContext);
            } finally {
              SecurityActions.setThreadContextClassLoader(oldTccl);
            }
          }
        } catch (ModuleLoadException e) {
          throw new RuntimeException(e);
        }
      }
      resource.writeModel(resourceDescription.get("domain-resource-model"));
    }
  }
  context.completeStep();
}

代码示例来源:origin: org.wildfly.core/wildfly-host-controller

protected void initializeExtension(String module, ManagementResourceRegistration rootRegistration) throws OperationFailedException {
    try {
      for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
        ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
        try {
          extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
          extension.initialize(extensionRegistry.getExtensionContext(module, rootRegistration, ExtensionRegistryType.SLAVE));
        } finally {
          SecurityActions.setThreadContextClassLoader(oldTccl);
        }
      }
    } catch (ModuleLoadException e) {
      throw DomainControllerLogger.ROOT_LOGGER.failedToLoadModule(e, module);
    }
  }
}

代码示例来源:origin: org.jboss.as/jboss-as-host-controller

protected void initializeExtension(String module) throws OperationFailedException {
    try {
      for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
        ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
        try {
          extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
          extension.initialize(extensionRegistry.getExtensionContext(module, false));
        } finally {
          SecurityActions.setThreadContextClassLoader(oldTccl);
        }
      }
    } catch (ModuleLoadException e) {
      throw DomainControllerMessages.MESSAGES.failedToLoadModule(e, module);
    }
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-controller

boolean unknownModule = false;
boolean initialized = false;
for (Extension extension : Module.loadServiceFromCallerModuleLoader(module, Extension.class)) {
  ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
  try {

代码示例来源:origin: org.wildfly/wildfly-controller

void initializeExtension(String module) throws OperationFailedException {
  try {
    boolean unknownModule = false;
    for (Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
      ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
      try {
        if (unknownModule || !extensionRegistry.getExtensionModuleNames().contains(module)) {
          // This extension wasn't handled by the standalone.xml or domain.xml parsing logic, so we
          // need to initialize its parsers so we can display what XML namespaces it supports
          extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
          // AS7-6190 - ensure we initialize parsers for other extensions from this module
          // now that we know the registry was unaware of the module
          unknownModule = true;
        }
        extension.initialize(extensionRegistry.getExtensionContext(module, !standalone && !slaveHC));
      } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
      }
    }
  } catch (ModuleNotFoundException e) {
    // Treat this as a user mistake, e.g. incorrect module name.
    // Throw OFE so post-boot it only gets logged at DEBUG.
    throw ControllerMessages.MESSAGES.extensionModuleNotFound(e, module);
  } catch (ModuleLoadException e) {
    // The module is there but can't be loaded. Treat this as an internal problem.
    // Throw a runtime exception so it always gets logged at ERROR in the server log with stack trace details.
    throw ControllerMessages.MESSAGES.extensionModuleLoadingFailure(e, module);
  }
}

相关文章