coderzc commented on code in PR #21402:
URL: https://github.com/apache/pulsar/pull/21402#discussion_r1366567027


##########
pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarClassLoader.java:
##########
@@ -135,24 +141,41 @@ public class NarClassLoader extends URLClassLoader {
      * The NAR for which this <tt>ClassLoader</tt> is responsible.
      */
     private final File narWorkingDirectory;
+    private final String narPath;
+    private final ClassLoader parentClassLoader;
+    private final AtomicInteger refCnt = new AtomicInteger(0);
 
     private static final String TMP_DIR_PREFIX = "pulsar-nar";
 
     public static final String DEFAULT_NAR_EXTRACTION_DIR = 
System.getProperty("nar.extraction.tmpdir") != null
             ? System.getProperty("nar.extraction.tmpdir") : 
System.getProperty("java.io.tmpdir");
 
-    static NarClassLoader getFromArchive(File narPath, Set<String> 
additionalJars, ClassLoader parent,
-                                                String narExtractionDirectory)
-        throws IOException {
-        File unpacked = NarUnpacker.unpackNar(narPath, 
getNarExtractionDirectory(narExtractionDirectory));
-        return AccessController.doPrivileged(new 
PrivilegedAction<NarClassLoader>() {
-            @SneakyThrows
-            @Override
-            public NarClassLoader run() {
-                return new NarClassLoader(unpacked, additionalJars, parent);
+    static NarClassLoader getFromArchive(File narFile, Set<String> 
additionalJars, ClassLoader parent,
+                                         String narExtractionDirectory) {
+
+        final String cachedKey = classLoaderKey(narFile.getAbsolutePath(), 
parent);
+        return CACHED_CLASS_LOADER.compute(cachedKey, (key, narClassLoader) -> 
{
+            if (narClassLoader != null) {
+                return narClassLoader.retain();
+            }
+            try {
+                File unpacked = NarUnpacker.unpackNar(narFile, 
getNarExtractionDirectory(narExtractionDirectory));

Review Comment:
   Good idea.



##########
pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarClassLoader.java:
##########
@@ -135,24 +141,41 @@ public class NarClassLoader extends URLClassLoader {
      * The NAR for which this <tt>ClassLoader</tt> is responsible.
      */
     private final File narWorkingDirectory;
+    private final String narPath;
+    private final ClassLoader parentClassLoader;
+    private final AtomicInteger refCnt = new AtomicInteger(0);

Review Comment:
   done



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to