/** * Loads the details for the specified NAR. The details will be extracted * from the manifest file. * * @param narDirectory the nar directory * @return details about the NAR * @throws IOException ioe */ private static BundleDetails getNarDetails(final File narDirectory) throws IOException { return NarBundleUtil.fromNarDirectory(narDirectory); }
/** * @return The singleton instance of the NarClassLoaders */ public static NarClassLoaders getInstance() { if (INSTANCE == null) { synchronized (NarClassLoadersHolder.class) { if (INSTANCE == null) { INSTANCE = new NarClassLoaders(); } } } return INSTANCE; }
Class<?>[] getExecutionStack() { return getClassContext(); } }
private static ExtensionMapping determineDocumentedNiFiComponents(final BundleCoordinate coordinate, final File jar) throws IOException { final ExtensionMapping mapping = new ExtensionMapping(); try (final JarFile jarFile = new JarFile(jar)) { final JarEntry processorEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.processor.Processor"); final JarEntry reportingTaskEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.reporting.ReportingTask"); final JarEntry controllerServiceEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.controller.ControllerService"); if (processorEntry==null && reportingTaskEntry==null && controllerServiceEntry==null) { return mapping; } mapping.addAllProcessors(coordinate, determineDocumentedNiFiComponents(jarFile, processorEntry)); mapping.addAllReportingTasks(coordinate, determineDocumentedNiFiComponents(jarFile, reportingTaskEntry)); mapping.addAllControllerServices(coordinate, determineDocumentedNiFiComponents(jarFile, controllerServiceEntry)); return mapping; } }
public static NarCloseable withNarLoader() { final ClassLoader current = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(NarThreadContextClassLoader.getInstance()); return new NarCloseable(current); }
@Override public void initialize(StateProviderInitializationContext context) throws IOException { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.initialize(context); } }
@Override public void cleanUpResources() { extensionManager.removeInstanceClassLoader(configurableComponent.getIdentifier()); } }
/** * Construct a nar class loader with the specific parent. * * @param narWorkingDirectory directory to explode nar contents to * @param parentClassLoader parent class loader of this nar * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory, final ClassLoader parentClassLoader) throws ClassNotFoundException, IOException { super(new URL[0], parentClassLoader); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
@Override public ExtensionManager getObject() { return ExtensionManagerHolder.getExtensionManager(); }
public NarAutoLoaderTask build() { return new NarAutoLoaderTask(this); }
@Override public void shutdown() { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.shutdown(); } }
@Override public void cleanUpResources() { extensionManager.removeInstanceClassLoader(processorNode.getIdentifier()); } }
/** * Construct a nar class loader. * * @param narWorkingDirectory directory to explode nar contents to * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory) throws ClassNotFoundException, IOException { super(new URL[0]); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
@Override public Scope[] getSupportedScopes() { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { return stateProvider.getSupportedScopes(); } }
@Override public Collection<ValidationResult> validate(ValidationContext context) { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { return stateProvider.validate(context); } }
@Override public AuthenticationResponse authenticate(LoginCredentials credentials) { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { return baseProvider.authenticate(credentials); } }
@Override public void onComponentRemoved(String componentId) throws IOException { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.onComponentRemoved(componentId); } }
@Override public void enable() { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.enable(); } }
@Override public void disable() { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.disable(); } }
@Override public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) { stateProvider.onPropertyModified(descriptor, oldValue, newValue); } }