markap14 commented on a change in pull request #3894: NIFI-6884 - Native
library loading fixed/improved
URL: https://github.com/apache/nifi/pull/3894#discussion_r349305230
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-utils/src/main/java/org/apache/nifi/nar/InstanceClassLoader.java
##########
@@ -41,20 +51,60 @@
private final Set<URL> instanceUrls;
private final Set<URL> additionalResourceUrls;
+ private final List<File> nativeLibDirs;
+ private final Map<String, Path> nativeLibNameToPath = new HashMap<>();
+
/**
* @param identifier the id of the component this ClassLoader was created
for
* @param instanceUrls the urls for the instance, will either be empty or
a copy of the NARs urls
* @param additionalResourceUrls the urls that came from runtime
properties of the component
* @param parent the parent ClassLoader
*/
public InstanceClassLoader(final String identifier, final String type,
final Set<URL> instanceUrls, final Set<URL> additionalResourceUrls, final
ClassLoader parent) {
+ this(identifier, type, instanceUrls, additionalResourceUrls,
Collections.emptySet(), parent);
+ }
+
+ public InstanceClassLoader(
+ final String identifier,
+ final String type,
+ final Set<URL> instanceUrls,
+ final Set<URL> additionalResourceUrls,
+ final Set<File> nativeLibDirs,
+ final ClassLoader parent
+ ) {
super(combineURLs(instanceUrls, additionalResourceUrls), parent);
this.identifier = identifier;
this.instanceType = type;
this.instanceUrls = Collections.unmodifiableSet(
instanceUrls == null ? Collections.emptySet() : new
LinkedHashSet<>(instanceUrls));
this.additionalResourceUrls = Collections.unmodifiableSet(
additionalResourceUrls == null ? Collections.emptySet() : new
LinkedHashSet<>(additionalResourceUrls));
+
+ List<File> allNativeLibDirs = new ArrayList<>(nativeLibDirs);
+ Set<File> additionalNativeLibDirs =
this.additionalResourceUrls.stream()
Review comment:
This code gets a bit confusing. I think it would be much clearer if written
in the Imperative style rather than the Functional style. In general, we should
avoid functional style programming any time the function exceeds around 3-5
lines. The Guava JavaDocs do a good job of explaining the rational here:
https://github.com/google/guava/wiki/FunctionalExplained as well as Joshua
Bloch's Effective Java.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services