You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "xwm1992 (via GitHub)" <gi...@apache.org> on 2023/02/24 02:15:26 UTC

[GitHub] [incubator-eventmesh] xwm1992 commented on a diff in pull request #3243: [ISSUE #3242]Refactor EventMeshProducer

xwm1992 commented on code in PR #3243:
URL: https://github.com/apache/incubator-eventmesh/pull/3243#discussion_r1116432318


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java:
##########
@@ -83,32 +86,24 @@ public synchronized void init(EventMeshHTTPConfiguration eventMeshHttpConfigurat
         keyValue.put("eventMeshIDC", eventMeshHttpConfiguration.getEventMeshIDC());
         mqProducerWrapper = new MQProducerWrapper(eventMeshHttpConfiguration.getEventMeshConnectorPluginType());
         mqProducerWrapper.init(keyValue);
-        inited.compareAndSet(false, true);
         log.info("EventMeshProducer [{}] inited.............", producerGroupConfig.getGroupName());
     }
 
 
-    public synchronized void start() throws Exception {
-        if (started.get()) {
+    public void start() throws Exception {
+
+        if (!started.compareAndSet(false, true)) {
             return;
         }
-
         mqProducerWrapper.start();
-        started.compareAndSet(false, true);
         log.info("EventMeshProducer [{}] started.............", producerGroupConfig.getGroupName());
     }
 
-    public synchronized void shutdown() throws Exception {
-        if (!inited.get()) {
-            return;
-        }
-
-        if (!started.get()) {
+    public void shutdown() throws Exception {
+        if (!inited.compareAndSet(true, false && !started.compareAndSet(true, false))) {

Review Comment:
   the code logic of this paragraph is easy to make people confused, may be you use `if(!inited.compareAndSet(true, false) {...}`, `if(!started.compareAndSet(true, false) {...}` much better.



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