xuefuz commented on a change in pull request #9937: [FLINK-14416][table] Add 
Module interface and ModuleManager
URL: https://github.com/apache/flink/pull/9937#discussion_r338149370
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/module/ModuleManager.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.module;
+
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.module.exceptions.ModuleAlreadyExistException;
+import org.apache.flink.table.module.exceptions.ModuleNotFoundException;
+import org.apache.flink.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Responsible for loading/unloading modules, managing their life cycles, and 
resolving module objects.
+ */
+public class ModuleManager {
+       private LinkedHashMap<String, Module> modules;
+
+       public ModuleManager() {
+               this.modules = new LinkedHashMap<>();
+
+               // TODO: Add Core module to modules
+       }
+
+       /**
+        * Load a module with given name.
+        *
+        * @param name name of the module
+        * @param module the module instance
+        * @throws ModuleAlreadyExistException thrown when there is already a 
module with the same name
+        */
+       public void loadModule(String name, Module module) throws 
ModuleAlreadyExistException {
+               checkArgument(!StringUtils.isNullOrWhitespaceOnly(name), "name 
cannot be null or empty string");
+               checkNotNull(module, "module cannot be null");
+
+               if (!modules.containsKey(name)) {
+                       modules.put(name, module);
+               } else {
+                       throw new ModuleAlreadyExistException(name);
+               }
+       }
+
+       /**
+        * Unload a module with given name.
+        *
+        * @param name name of the module
+        * @throws ModuleNotFoundException thrown when there is no module with 
the given name
+        */
+       public void unloadModule(String name) throws ModuleNotFoundException {
+               if (modules.containsKey(name)) {
+                       modules.remove(name);
+               } else {
+                       throw new ModuleNotFoundException(name);
+               }
+       }
+
+       /**
+        * Get names of all modules registered.
 
 Review comment:
   Nit: registered -> loaded

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to