You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/07/27 10:24:31 UTC

[GitHub] [incubator-eventmesh] li-xiao-shuang commented on a diff in pull request #1044: [ISSUE #1043] Fix the problem of shared registry singleton.

li-xiao-shuang commented on code in PR #1044:
URL: https://github.com/apache/incubator-eventmesh/pull/1044#discussion_r930890398


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/registry/Registry.java:
##########
@@ -31,23 +31,37 @@
 
 public class Registry {
     private static final Logger logger = LoggerFactory.getLogger(Registry.class);
-    private static RegistryService registryService;
 
-    public void init(String registryPluginType) throws Exception {
-        registryService = EventMeshExtensionFactory.getExtension(RegistryService.class, registryPluginType);
-        if (registryService == null) {
-            logger.error("can't load the registryService plugin, please check.");
-            throw new RuntimeException("doesn't load the registryService plugin, please check.");
+    private volatile boolean inited = false;
+
+    private volatile boolean started = false;
+
+    private RegistryService registryService;
+
+    public synchronized void init(String registryPluginType) throws Exception {
+        if (!inited) {
+            registryService = EventMeshExtensionFactory.getExtension(RegistryService.class, registryPluginType);
+            if (registryService == null) {
+                logger.error("can't load the registryService plugin, please check.");
+                throw new RuntimeException("doesn't load the registryService plugin, please check.");
+            }
+            registryService.init();
+            inited = true;
         }
-        registryService.init();
     }
 
-    public void start() throws Exception {
-        registryService.start();
+    public synchronized void start() throws Exception {
+        if (!started) {
+            registryService.start();
+            started = true;
+        }
     }
 
-    public void shutdown() throws Exception {
-        registryService.shutdown();
+    public synchronized void shutdown() throws Exception {
+        if (started) {
+            registryService.shutdown();
+            started = false;

Review Comment:
   inited = false;



-- 
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: dev-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org