funky-eyes commented on code in PR #6230:
URL: https://github.com/apache/incubator-seata/pull/6230#discussion_r1501956247


##########
rocketmq/src/main/java/org/apache/seata/integration/rocketmq/SeataMQProducerFactory.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.seata.integration.rocketmq;
+
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.seata.common.exception.NotSupportYetException;
+import org.apache.seata.core.model.BranchType;
+import org.apache.seata.integration.tx.api.util.ProxyUtil;
+
+/**
+ * SeataMQProducer Factory
+ **/
+public class SeataMQProducerFactory {
+
+    public static final String ROCKET_TCC_NAME = "tccRocketMQ";
+    public static final BranchType ROCKET_BRANCH_TYPE = BranchType.TCC;
+
+    /**
+     * Default Producer, it can be replaced to Map after multi-resource is 
supported
+     */
+    private static SeataMQProducer defaultProducer;
+
+
+    public static SeataMQProducer createSingle(String nameServer, String 
producerGroup) throws MQClientException {
+        return createSingle(nameServer, null, producerGroup, null);
+    }
+
+    public static SeataMQProducer createSingle(String nameServer, String 
namespace,
+                                               String groupName, RPCHook 
rpcHook) throws MQClientException {
+        if (defaultProducer == null) {
+            synchronized (SeataMQProducerFactory.class) {
+                if (defaultProducer == null) {
+                    defaultProducer = new SeataMQProducer(namespace, 
groupName, rpcHook);
+                    defaultProducer.setNamesrvAddr(nameServer);
+                    TCCRocketMQ tccRocketMQProxy = ProxyUtil.createProxy(new 
TCCRocketMQImpl());
+                    tccRocketMQProxy.setProducer(defaultProducer);
+                    defaultProducer.setTccRocketMQ(tccRocketMQProxy);
+                    defaultProducer.start();
+                }
+            }
+        }
+        if (!ObjectUtils.equals(nameServer, defaultProducer.getNamesrvAddr())

Review Comment:
   > 
这个校验仅用于:producer已被创建,即将返回单例。作用是producer已存在,但和用户现在希望新创建的producer的配置不相同(也就是用户以为可以创建多个不同的producer),同理如果用户并发进行创建producer时,可能会有一个或多个线程在等待锁,直到第一个线程创建完成,那其他的创建线程也会进入这个校验。所以这个校验放在这里应该是没错的。
   > 
   > This check is only used if the producer has been created and is about to 
return a single instance. The effect is that the producer already exists, but 
it's not the same as the producer the user wants to create now (i.e., the user 
thinks it's possible to create more than one producer), so it's a good place to 
put this check.
   
   If the producer is not empty, why not just throw an exception to represent a 
proxy that currently only supports one producer?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to