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); } } }
@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); } }
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); } } }
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);
/** * 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); }
final ClassLoader detectedClassLoaderForType = bundle.getClassLoader(); final Class<?> rawClass = Class.forName(implementationClassName, true, detectedClassLoaderForType);
final ClassLoader loginIdentityProviderClassLoader = loginIdentityProviderBundle.getClassLoader();
final ClassLoader userGroupProviderClassLoader = userGroupProviderBundle.getClassLoader();
final ClassLoader accessPolicyProviderClassLoader = accessPolicyProviderBundle.getClassLoader();
if (frameworkBundle != null) { currentCl = Thread.currentThread().getContextClassLoader(); final ClassLoader cl = frameworkBundle.getClassLoader(); Thread.currentThread().setContextClassLoader(cl);
ClassLoader authorizerClassLoader = authorizerBundle.getClassLoader();
ClassLoader narClassLoaderForWar = warBundle.getClassLoader();
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);
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);
final ClassLoader bundleClassLoader = bundle.getClassLoader(); final String key = getClassBundleKey(classType, bundle.getBundleDetails().getCoordinate());
final ClassLoader frameworkClassLoader = narClassLoaders.getFrameworkBundle().getClassLoader(); if (frameworkClassLoader == null) { throw new IllegalStateException("Unable to find the framework NAR ClassLoader.");
/** * 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); }
/** * 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); }
/** * 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); } }
/** * 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); } }