FangYongs commented on code in PR #22938:
URL: https://github.com/apache/flink/pull/22938#discussion_r1353833344


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/resource/ResourceManager.java:
##########
@@ -124,15 +136,79 @@ public String registerFileResource(ResourceUri 
resourceUri) throws IOException {
                         Collections.singletonList(resourceUri),
                         ResourceType.FILE,
                         false,
-                        url -> {});
+                        url -> {},
+                        false);
         registerResources(stagingResources, false);
         return resourceInfos.get(new 
ArrayList<>(stagingResources.keySet()).get(0)).getPath();
     }
 
+    /**
+     * Register a resource for function and add it to the function resource 
infos. If the file is
+     * remote, it will be copied to a local file.
+     *
+     * @param resourceUris the resource uri for function.
+     */
+    public void registerFunctionResources(Set<ResourceUri> resourceUris) 
throws IOException {
+        prepareStagingResources(
+                resourceUris,
+                ResourceType.JAR,
+                true,
+                url -> {
+                    try {
+                        JarUtils.checkJarFile(url);
+                    } catch (IOException e) {
+                        throw new ValidationException(
+                                String.format("Failed to register jar resource 
[%s]", url), e);
+                    }
+                },
+                true);
+    }
+
+    /**
+     * Unregister the resource uri in function resources, when the reference 
count of the resource
+     * is 0, the resource will be removed from the function resources.
+     *
+     * @param resourceUris the uris to unregister in function resources.
+     */
+    public void unregisterFunctionResources(List<ResourceUri> resourceUris) {
+        if (!resourceUris.isEmpty()) {
+            resourceUris.forEach(
+                    uri -> {
+                        ResourceCounter counter = 
functionResourceInfos.get(uri);
+                        if (counter != null && counter.decreaseCounter()) {
+                            functionResourceInfos.remove(uri);
+                        }
+                    });
+        }
+    }
+
     public URLClassLoader getUserClassLoader() {
         return userClassLoader;
     }
 
+    public URLClassLoader createUserClassLoader(List<ResourceUri> 
resourceUris) {
+        if (resourceUris.isEmpty()) {
+            return userClassLoader;
+        }
+        MutableURLClassLoader classLoader = userClassLoader.copy();
+        for (ResourceUri resourceUri : new HashSet<>(resourceUris)) {
+            
classLoader.addURL(checkNotNull(functionResourceInfos.get(resourceUri)).url);
+        }
+        createdClassLoaderList.add(classLoader);
+
+        return classLoader;
+    }
+
+    public void closeUserClassLoader(URLClassLoader classLoader) {
+        if (createdClassLoaderList.remove(classLoader)) {

Review Comment:
   Remove created class loader list in resourcemanager



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to