ruanwenjun commented on code in PR #974:
URL: 
https://github.com/apache/incubator-eventmesh/pull/974#discussion_r910087220


##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/constant/ZookeeperConstant.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.eventmesh.registry.zookeeper.constant;
+
+import java.nio.charset.Charset;
+
+/**
+ * ZookeeperConstant.
+ */
+public class ZookeeperConstant {
+
+    public static final String NAMESPACE = "eventmesh";
+
+    public static final String IP_PORT_SEPARATOR = ":";
+
+    public static final String PATH_SEPARATOR = "/";
+
+    public static final Charset CHARSET_UTF8 = Charset.forName("utf-8");

Review Comment:
   You can directly use `StandardCharsets.UTF_8` rather than define it again in 
this class.



##########
eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * 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.eventmesh.registry.zookeeper.service;
+
+
+import org.apache.eventmesh.api.exception.RegistryException;
+import org.apache.eventmesh.api.registry.RegistryService;
+import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
+import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
+import org.apache.eventmesh.common.config.CommonConfiguration;
+import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
+import org.apache.eventmesh.registry.zookeeper.constant.ZookeeperConstant;
+import org.apache.eventmesh.registry.zookeeper.pojo.Instance;
+import org.apache.eventmesh.registry.zookeeper.util.JsonUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ZookeeperRegistryService implements RegistryService {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(ZookeeperRegistryService.class);
+
+    private static final AtomicBoolean INIT_STATUS = new AtomicBoolean(false);
+
+    private static final AtomicBoolean START_STATUS = new AtomicBoolean(false);
+
+    private String serverAddr;
+
+    public CuratorFramework zkClient = null;
+
+    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+
+    @Override
+    public void init() throws RegistryException {
+        boolean update = INIT_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        eventMeshRegisterInfoMap = new 
HashMap<>(ConfigurationContextUtil.KEYS.size());
+        for (String key : ConfigurationContextUtil.KEYS) {
+            CommonConfiguration commonConfiguration = 
ConfigurationContextUtil.get(key);
+            if (null == commonConfiguration) {
+                continue;
+            }
+            if (StringUtils.isBlank(commonConfiguration.namesrvAddr)) {
+                throw new RegistryException("namesrvAddr cannot be null");
+            }
+            this.serverAddr = commonConfiguration.namesrvAddr;
+            break;
+        }
+    }
+
+    @Override
+    public void start() throws RegistryException {
+        boolean update = START_STATUS.compareAndSet(false, true);
+        if (!update) {
+            return;
+        }
+        try {
+            RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
+            zkClient = CuratorFrameworkFactory.builder()
+                .connectString(serverAddr)
+                .retryPolicy(retryPolicy)
+                .namespace(ZookeeperConstant.NAMESPACE)
+                .build();
+            zkClient.start();
+
+        } catch (Exception e) {
+            logger.error("[ZookeeperRegistryService][start] error", e);
+            throw new RegistryException(e.getMessage());

Review Comment:
   You can directly throw the exception to upper layer, since you don't need to 
log here, this may cause the exception boom.
   ```suggestion
               throw new RegistryException("ZookeeperRegistry starting failed", 
e);
   ```



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