本文整理了Java中org.apache.nifi.bundle.Bundle.getClassLoader()
方法的一些代码示例,展示了Bundle.getClassLoader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.getClassLoader()
方法的具体详情如下:
包路径:org.apache.nifi.bundle.Bundle
类名称:Bundle
方法名:getClassLoader
暂无
代码示例来源:origin: apache/nifi
private static StateProvider instantiateStateProvider(final ExtensionManager extensionManager, final String type) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
try {
final List<Bundle> bundles = extensionManager.getBundles(type);
if (bundles.size() == 0) {
throw new IllegalStateException(String.format("The specified class '%s' is not known to this nifi.", type));
}
if (bundles.size() > 1) {
throw new IllegalStateException(String.format("Multiple bundles found for the specified class '%s', only one is allowed.", type));
}
final Bundle bundle = bundles.get(0);
final ClassLoader detectedClassLoaderForType = bundle.getClassLoader();
final Class<?> rawClass = Class.forName(type, true, detectedClassLoaderForType);
Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
final Class<? extends StateProvider> mgrClass = rawClass.asSubclass(StateProvider.class);
return withNarClassLoader(mgrClass.newInstance());
} finally {
if (ctxClassLoader != null) {
Thread.currentThread().setContextClassLoader(ctxClassLoader);
}
}
}
代码示例来源:origin: apache/nifi
@Override
public void discoverExtensions(final Set<Bundle> narBundles) {
// get the current context class loader
ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
// consider each nar class loader
for (final Bundle bundle : narBundles) {
// Must set the context class loader to the nar classloader itself
// so that static initialization techniques that depend on the context class loader will work properly
final ClassLoader ncl = bundle.getClassLoader();
Thread.currentThread().setContextClassLoader(ncl);
loadExtensions(bundle);
// Create a look-up from coordinate to bundle
bundleCoordinateBundleLookup.put(bundle.getBundleDetails().getCoordinate(), bundle);
}
// restore the current context class loader if appropriate
if (currentContextClassLoader != null) {
Thread.currentThread().setContextClassLoader(currentContextClassLoader);
}
}
代码示例来源:origin: apache/nifi
public FlowFilePrioritizer createPrioritizer(final String type) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
FlowFilePrioritizer prioritizer;
final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
try {
final List<Bundle> prioritizerBundles = flowController.getExtensionManager().getBundles(type);
if (prioritizerBundles.size() == 0) {
throw new IllegalStateException(String.format("The specified class '%s' is not known to this nifi.", type));
}
if (prioritizerBundles.size() > 1) {
throw new IllegalStateException(String.format("Multiple bundles found for the specified class '%s', only one is allowed.", type));
}
final Bundle bundle = prioritizerBundles.get(0);
final ClassLoader detectedClassLoaderForType = bundle.getClassLoader();
final Class<?> rawClass = Class.forName(type, true, detectedClassLoaderForType);
Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
final Class<? extends FlowFilePrioritizer> prioritizerClass = rawClass.asSubclass(FlowFilePrioritizer.class);
final Object processorObj = prioritizerClass.newInstance();
prioritizer = prioritizerClass.cast(processorObj);
return prioritizer;
} finally {
if (ctxClassLoader != null) {
Thread.currentThread().setContextClassLoader(ctxClassLoader);
}
}
}
代码示例来源:origin: apache/nifi
final boolean isReportingTask = ReportingTask.class.equals(entry.getKey());
final ServiceLoader<?> serviceLoader = ServiceLoader.load(entry.getKey(), bundle.getClassLoader());
for (final Object o : serviceLoader) {
boolean registerExtension = bundle.getClassLoader().equals(o.getClass().getClassLoader());
if (canReferenceControllerService && !checkControllerServiceReferenceEligibility((ConfigurableComponent) o, bundle.getClassLoader())) {
registerExtension = false;
logger.error(String.format(
classLoaderBundleLookup.put(bundle.getClassLoader(), bundle);
代码示例来源:origin: apache/nifi
/**
* Creates a Closeable object that can be used to to switch to current class
* loader to the framework class loader and will automatically set the
* ClassLoader back to the previous class loader when closed
*
* @return a NarCloseable
*/
public static NarCloseable withFrameworkNar() {
final ClassLoader frameworkClassLoader;
try {
frameworkClassLoader = NarClassLoadersHolder.getInstance().getFrameworkBundle().getClassLoader();
} catch (final Exception e) {
// This should never happen in a running instance, but it will occur in unit tests
logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders.");
if (logger.isDebugEnabled()) {
logger.error("", e);
}
return new NarCloseable(null);
}
final ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(frameworkClassLoader);
return new NarCloseable(current);
}
代码示例来源:origin: apache/nifi
final ClassLoader detectedClassLoaderForType = bundle.getClassLoader();
final Class<?> rawClass = Class.forName(implementationClassName, true, detectedClassLoaderForType);
代码示例来源:origin: apache/nifi
final ClassLoader loginIdentityProviderClassLoader = loginIdentityProviderBundle.getClassLoader();
代码示例来源:origin: apache/nifi
final ClassLoader userGroupProviderClassLoader = userGroupProviderBundle.getClassLoader();
代码示例来源:origin: apache/nifi
final ClassLoader accessPolicyProviderClassLoader = accessPolicyProviderBundle.getClassLoader();
代码示例来源:origin: apache/nifi
if (frameworkBundle != null) {
currentCl = Thread.currentThread().getContextClassLoader();
final ClassLoader cl = frameworkBundle.getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
代码示例来源:origin: apache/nifi
ClassLoader authorizerClassLoader = authorizerBundle.getClassLoader();
代码示例来源:origin: apache/nifi
ClassLoader narClassLoaderForWar = warBundle.getClassLoader();
代码示例来源:origin: apache/nifi
final ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(csBundle.getClassLoader());
serviceClass = Class.forName(serviceType, false, csBundle.getClassLoader());
} catch (final Exception e) {
Thread.currentThread().setContextClassLoader(currentContextClassLoader);
代码示例来源:origin: apache/nifi
final ClassLoader jettyClassLoader = getJettyBundle().getClassLoader();
bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), jettyClassLoader);
} else {
final ClassLoader narDependencyClassLoader = dependencyBundle.get().getClassLoader();
bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), narDependencyClassLoader);
} else {
bundleDetail.getCoordinate().getCoordinate(), dependencyCoordinateStr, coordinate.getCoordinate()));
final ClassLoader narDependencyClassLoader = matchingDependencyIdBundle.get().getClassLoader();
bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), narDependencyClassLoader);
代码示例来源:origin: apache/nifi
final ClassLoader bundleClassLoader = bundle.getClassLoader();
final String key = getClassBundleKey(classType, bundle.getBundleDetails().getCoordinate());
代码示例来源:origin: apache/nifi
final ClassLoader frameworkClassLoader = narClassLoaders.getFrameworkBundle().getClassLoader();
if (frameworkClassLoader == null) {
throw new IllegalStateException("Unable to find the framework NAR ClassLoader.");
代码示例来源:origin: apache/nifi-minifi
/**
* Creates a Closeable object that can be used to to switch to current class
* loader to the framework class loader and will automatically set the
* ClassLoader back to the previous class loader when closed
*
* @return a NarCloseable
*/
public static NarCloseable withFrameworkNar() {
final ClassLoader frameworkClassLoader;
try {
frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader();
} catch (final Exception e) {
// This should never happen in a running instance, but it will occur in unit tests
logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders.");
if (logger.isDebugEnabled()) {
logger.error("", e);
}
return new NarCloseable(null);
}
final ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(frameworkClassLoader);
return new NarCloseable(current);
}
代码示例来源:origin: org.apache.nifi.minifi/minifi-nar-utils
/**
* Creates a Closeable object that can be used to to switch to current class
* loader to the framework class loader and will automatically set the
* ClassLoader back to the previous class loader when closed
*
* @return a NarCloseable
*/
public static NarCloseable withFrameworkNar() {
final ClassLoader frameworkClassLoader;
try {
frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader();
} catch (final Exception e) {
// This should never happen in a running instance, but it will occur in unit tests
logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders.");
if (logger.isDebugEnabled()) {
logger.error("", e);
}
return new NarCloseable(null);
}
final ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(frameworkClassLoader);
return new NarCloseable(current);
}
代码示例来源:origin: org.apache.nifi.minifi/minifi-nar-utils
/**
* Loads all FlowFileProcessor, FlowFileComparator, ReportingTask class types that can be found on the bootstrap classloader and by creating classloaders for all NARs found within the classpath.
*
* @param narBundles the bundles to scan through in search of extensions
*/
public static void discoverExtensions(final Bundle systemBundle, final Set<Bundle> narBundles) {
// get the current context class loader
ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
// load the system bundle first so that any extensions found in JARs directly in lib will be registered as
// being from the system bundle and not from all the other NARs
loadExtensions(systemBundle);
bundleCoordinateBundleLookup.put(systemBundle.getBundleDetails().getCoordinate(), systemBundle);
// consider each nar class loader
for (final Bundle bundle : narBundles) {
// Must set the context class loader to the nar classloader itself
// so that static initialization techniques that depend on the context class loader will work properly
final ClassLoader ncl = bundle.getClassLoader();
Thread.currentThread().setContextClassLoader(ncl);
loadExtensions(bundle);
// Create a look-up from coordinate to bundle
bundleCoordinateBundleLookup.put(bundle.getBundleDetails().getCoordinate(), bundle);
}
// restore the current context class loader if appropriate
if (currentContextClassLoader != null) {
Thread.currentThread().setContextClassLoader(currentContextClassLoader);
}
}
代码示例来源:origin: apache/nifi-minifi
/**
* Loads all FlowFileProcessor, FlowFileComparator, ReportingTask class types that can be found on the bootstrap classloader and by creating classloaders for all NARs found within the classpath.
*
* @param narBundles the bundles to scan through in search of extensions
*/
public static void discoverExtensions(final Bundle systemBundle, final Set<Bundle> narBundles) {
// get the current context class loader
ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
// load the system bundle first so that any extensions found in JARs directly in lib will be registered as
// being from the system bundle and not from all the other NARs
loadExtensions(systemBundle);
bundleCoordinateBundleLookup.put(systemBundle.getBundleDetails().getCoordinate(), systemBundle);
// consider each nar class loader
for (final Bundle bundle : narBundles) {
// Must set the context class loader to the nar classloader itself
// so that static initialization techniques that depend on the context class loader will work properly
final ClassLoader ncl = bundle.getClassLoader();
Thread.currentThread().setContextClassLoader(ncl);
loadExtensions(bundle);
// Create a look-up from coordinate to bundle
bundleCoordinateBundleLookup.put(bundle.getBundleDetails().getCoordinate(), bundle);
}
// restore the current context class loader if appropriate
if (currentContextClassLoader != null) {
Thread.currentThread().setContextClassLoader(currentContextClassLoader);
}
}
内容来源于网络,如有侵权,请联系作者删除!