@Override public BodyProducer create(HttpContentProducer contentProducer, ServiceTaskExecutor taskExecutor) { final ClassLoader programContextClassLoader = new CombineClassLoader( null, contentProducer.getClass().getClassLoader(), getClass().getClassLoader()); // Capture the context since we need to keep it until the end of the content producing. // We don't need to worry about double capturing of the context when HttpContentConsumer is used. // This is because when HttpContentConsumer is used, the responder constructed here will get closed and this // BodyProducerFactory won't be used. return new BodyProducerAdapter(contentProducer, taskExecutor, context.capture(), defaultTxControl); } }, context.getServiceTaskExecutor(), metricsContext);
queue.addAll(((CombineClassLoader) cl).getDelegates());
@Override public BodyProducer create(HttpContentProducer contentProducer, ServiceTaskExecutor taskExecutor) { final ClassLoader programContextClassLoader = new CombineClassLoader( null, contentProducer.getClass().getClassLoader(), getClass().getClassLoader()); // Capture the context since we need to keep it until the end of the content producing. // We don't need to worry about double capturing of the context when HttpContentConsumer is used. // This is because when HttpContentConsumer is used, the responder constructed here will get closed and this // BodyProducerFactory won't be used. return new BodyProducerAdapter(contentProducer, taskExecutor, context.capture(), defaultTxControl); } }, context.getServiceTaskExecutor(), metricsContext);
queue.addAll(((CombineClassLoader) cl).getDelegates());
static ClassLoader createParent(ClassLoader templateClassLoader) { // Find the ProgramClassLoader from the template ClassLoader ClassLoader programClassLoader = templateClassLoader; while (programClassLoader != null && !(programClassLoader instanceof ProgramClassLoader)) { programClassLoader = programClassLoader.getParent(); } // This shouldn't happen Preconditions.checkArgument(programClassLoader != null, "Cannot find ProgramClassLoader"); // Package filtered classloader of the template classloader, which only classes in "Export-Packages" are loadable. Manifest manifest = ((ProgramClassLoader) programClassLoader).getManifest(); Set<String> exportPackages = ManifestFields.getExportPackages(manifest); ClassLoader filteredTemplateClassLoader = new PackageFilterClassLoader(templateClassLoader, Predicates.in(exportPackages)); // The lib Classloader needs to be able to see all cdap api classes as well. // In this way, parent ClassLoader of the plugin ClassLoader will load class from the parent of the // template program class loader (which is a filtered CDAP classloader), // followed by template export-packages, then by a plugin lib jars. return new CombineClassLoader(programClassLoader.getParent(), filteredTemplateClassLoader); }
List<ClassLoader> delegates = ((CombineClassLoader) cl).getDelegates(); ListIterator<ClassLoader> iterator = delegates.listIterator(delegates.size());
/** * Creates a new instance of {@link ClassLoader} that will be used for program method invocation. * By default it is a {@link CombineClassLoader} with program classloader, * plugins export-package classloader and system classloader in that loading order. */ protected ClassLoader createProgramInvocationClassLoader() { // A classloader that can load all export-package classes from all plugins ClassLoader pluginsClassLoader = PluginClassLoaders.createFilteredPluginsClassLoader( program.getApplicationSpecification().getPlugins(), pluginInstantiator); return new CombineClassLoader(null, program.getClassLoader(), pluginsClassLoader, getClass().getClassLoader()); }
List<ClassLoader> delegates = ((CombineClassLoader) cl).getDelegates(); ListIterator<ClassLoader> iterator = delegates.listIterator(delegates.size());
static ClassLoader createParent(ClassLoader templateClassLoader) { // Find the ProgramClassLoader from the template ClassLoader ClassLoader programClassLoader = templateClassLoader; while (programClassLoader != null && !(programClassLoader instanceof ProgramClassLoader)) { programClassLoader = programClassLoader.getParent(); } // This shouldn't happen Preconditions.checkArgument(programClassLoader != null, "Cannot find ProgramClassLoader"); // Package filtered classloader of the template classloader, which only classes in "Export-Packages" are loadable. Manifest manifest = ((ProgramClassLoader) programClassLoader).getManifest(); Set<String> exportPackages = ManifestFields.getExportPackages(manifest); ClassLoader filteredTemplateClassLoader = new PackageFilterClassLoader(templateClassLoader, Predicates.in(exportPackages)); // The lib Classloader needs to be able to see all cdap api classes as well. // In this way, parent ClassLoader of the plugin ClassLoader will load class from the parent of the // template program class loader (which is a filtered CDAP classloader), // followed by template export-packages, then by a plugin lib jars. return new CombineClassLoader(programClassLoader.getParent(), filteredTemplateClassLoader); }
/** * @param filter A {@link FilterClassLoader.Filter} for filtering out classes from the * @param extraClasspath extra list of {@link URL} to be added to the end of the classpath for the * {@link MainClassLoader} to be created * @return a new instance from the current context classloader or the system classloader. The returned * {@link MainClassLoader} will be the defining classloader for classes in the context classloader * that the filter rejected. For classes that pass the filter, the defining classloader will be the original * context classloader. * It will return {@code null} if it is not able to create a new instance due to lack of classpath information. */ @Nullable public static MainClassLoader createFromContext(FilterClassLoader.Filter filter, URL...extraClasspath) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } List<URL> classpath = new ArrayList<>(); if (classLoader instanceof URLClassLoader) { classpath.addAll(Arrays.asList(((URLClassLoader) classLoader).getURLs())); } else if (classLoader == ClassLoader.getSystemClassLoader()) { addClassPath(classpath); } else { // No able to create a new MainClassLoader return null; } classpath.addAll(Arrays.asList(extraClasspath)); ClassLoader filtered = new FilterClassLoader(classLoader, filter); ClassLoader parent = new CombineClassLoader(classLoader.getParent(), filtered); return new MainClassLoader(classpath.toArray(new URL[classpath.size()]), parent); }
/** * @param filter A {@link FilterClassLoader.Filter} for filtering out classes from the * @param extraClasspath extra list of {@link URL} to be added to the end of the classpath for the * {@link MainClassLoader} to be created * @return a new instance from the current context classloader or the system classloader. The returned * {@link MainClassLoader} will be the defining classloader for classes in the context classloader * that the filter rejected. For classes that pass the filter, the defining classloader will be the original * context classloader. * It will return {@code null} if it is not able to create a new instance due to lack of classpath information. */ @Nullable public static MainClassLoader createFromContext(FilterClassLoader.Filter filter, URL...extraClasspath) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } List<URL> classpath = new ArrayList<>(); if (classLoader instanceof URLClassLoader) { classpath.addAll(Arrays.asList(((URLClassLoader) classLoader).getURLs())); } else if (classLoader == ClassLoader.getSystemClassLoader()) { addClassPath(classpath); } else { // No able to create a new MainClassLoader return null; } classpath.addAll(Arrays.asList(extraClasspath)); ClassLoader filtered = new FilterClassLoader(classLoader, filter); ClassLoader parent = new CombineClassLoader(classLoader.getParent(), filtered); return new MainClassLoader(classpath.toArray(new URL[classpath.size()]), parent); }
@Nullable PluginInstantiator pluginInstantiator) { if (plugins.isEmpty() || pluginInstantiator == null) { return new CombineClassLoader(null); return new CombineClassLoader(null, pluginClassLoaders); } catch (IOException e) { throw Throwables.propagate(e);
@Nullable PluginInstantiator pluginInstantiator) { if (plugins.isEmpty() || pluginInstantiator == null) { return new CombineClassLoader(null); return new CombineClassLoader(null, pluginClassLoaders); } catch (IOException e) { throw Throwables.propagate(e);
/** * Creates a new instance of {@link ClassLoader} that will be used for program method invocation. * By default it is a {@link CombineClassLoader} with program classloader, * plugins export-package classloader and system classloader in that loading order. */ protected ClassLoader createProgramInvocationClassLoader() { // A classloader that can load all export-package classes from all plugins ClassLoader pluginsClassLoader = PluginClassLoaders.createFilteredPluginsClassLoader( program.getApplicationSpecification().getPlugins(), pluginInstantiator); return new CombineClassLoader(null, program.getClassLoader(), pluginsClassLoader, getClass().getClassLoader()); }
ClassLoader outputClassLoader = new CombineClassLoader(outputFormatClassLoader, Thread.currentThread().getContextClassLoader());
ClassLoader outputClassLoader = new CombineClassLoader(outputFormatClassLoader, Thread.currentThread().getContextClassLoader());
new CombineClassLoader(parentPluginCL.getParent(), parentPluginCL.getExportPackagesClassLoader()); return new PluginClassLoader(key.artifact, unpackedDir, parentCL);
new CombineClassLoader(parentPluginCL.getParent(), parentPluginCL.getExportPackagesClassLoader()); return new PluginClassLoader(key.artifact, unpackedDir, parentCL);
new CombineClassLoader(null, app.getClass().getClassLoader(), getClass().getClassLoader())); try { app.configure(configurer, new DefaultApplicationContext<>(appConfig));
new CombineClassLoader(null, app.getClass().getClassLoader(), getClass().getClassLoader())); try { app.configure(configurer, new DefaultApplicationContext<>(appConfig));