This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 33cda2913 [ISSUE #3858]The interface RegistryService can design some 
default methods.  (#3859)
33cda2913 is described below

commit 33cda2913045d1e9a71bcdd17bd5df8439fd73dc
Author: pandaapo <[email protected]>
AuthorDate: Mon May 15 20:20:28 2023 +0800

    [ISSUE #3858]The interface RegistryService can design some default methods. 
 (#3859)
    
    * Fix issue3858:add default method to interface...
    
    * fix checkstyle error.
    
    * Revoke import static.
    
    * Remove the method defined in Interface from EtcdRegistryService.
---
 .../eventmesh/api/registry/RegistryService.java    |  16 +++-
 .../consul/service/ConsulRegistryService.java      |  28 ++----
 .../registry/etcd/service/EtcdCustomService.java   |  14 +--
 .../registry/etcd/service/EtcdRegistryService.java |  34 ++-----
 .../nacos/service/NacosRegistryService.java        | 100 +++++----------------
 .../service/ZookeeperRegistryService.java          |  44 +++------
 6 files changed, 65 insertions(+), 171 deletions(-)

diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java
index 577b692d8..9ef52f8fe 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java
@@ -26,6 +26,7 @@ import 
org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
 import org.apache.eventmesh.spi.EventMeshExtensionType;
 import org.apache.eventmesh.spi.EventMeshSPI;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -45,8 +46,11 @@ public interface RegistryService {
 
     List<EventMeshDataInfo> findAllEventMeshInfo() throws RegistryException;
 
-    Map<String/*eventMeshName*/, Map<String/*purpose*/, Integer/*num*/>> 
findEventMeshClientDistributionData(
-        String clusterName, String group, String purpose) throws 
RegistryException;
+    default Map<String/*eventMeshName*/, Map<String/*purpose*/, 
Integer/*num*/>> findEventMeshClientDistributionData(
+        String clusterName, String group, String purpose) throws 
RegistryException {
+        // todo find metadata
+        return Collections.emptyMap();
+    }
 
     void registerMetadata(Map<String, String> metadataMap);
 
@@ -54,7 +58,11 @@ public interface RegistryService {
 
     boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws 
RegistryException;
 
-    EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String group) 
throws RegistryException;
+    default EventMeshAppSubTopicInfo 
findEventMeshAppSubTopicInfoByGroup(String group) throws RegistryException {
+        return null;
+    }
 
-    List<EventMeshServicePubTopicInfo> findEventMeshServicePubTopicInfos() 
throws RegistryException;
+    default List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
+        return Collections.emptyList();
+    }
 }
diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java
index acf217f7c..48585686e 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-consul/src/main/java/org/apache/eventmesh/registry/consul/service/ConsulRegistryService.java
@@ -19,8 +19,6 @@ package org.apache.eventmesh.registry.consul.service;
 
 import org.apache.eventmesh.api.exception.RegistryException;
 import org.apache.eventmesh.api.registry.RegistryService;
-import org.apache.eventmesh.api.registry.bo.EventMeshAppSubTopicInfo;
-import org.apache.eventmesh.api.registry.bo.EventMeshServicePubTopicInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
@@ -30,7 +28,6 @@ import 
org.apache.eventmesh.common.utils.ConfigurationContextUtil;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -42,6 +39,7 @@ import com.ecwid.consul.v1.agent.model.Service;
 import com.ecwid.consul.v1.health.HealthServicesRequest;
 import com.ecwid.consul.v1.health.model.HealthService;
 
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -57,6 +55,7 @@ public class ConsulRegistryService implements RegistryService 
{
 
     private String consulPort;
 
+    @Getter
     private ConsulClient consulClient;
 
     private String token;
@@ -107,6 +106,9 @@ public class ConsulRegistryService implements 
RegistryService {
     public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) 
throws RegistryException {
         try {
             String[] ipPort = 
eventMeshRegisterInfo.getEndPoint().split(IP_PORT_SEPARATOR);
+            if (ipPort == null || ipPort.length < 2) {
+                return false;
+            }
             NewService service = new NewService();
             service.setPort(Integer.parseInt(ipPort[1]));
             service.setAddress(ipPort[0]);
@@ -132,16 +134,6 @@ public class ConsulRegistryService implements 
RegistryService {
         return true;
     }
 
-    @Override
-    public List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
-        return null;
-    }
-
-    @Override
-    public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String 
group) throws RegistryException {
-        return null;
-    }
-
     @Override
     public List<EventMeshDataInfo> findEventMeshInfoByCluster(String 
clusterName) throws RegistryException {
         HealthServicesRequest request = 
HealthServicesRequest.newBuilder().setPassing(true).setToken(token).build();
@@ -166,18 +158,8 @@ public class ConsulRegistryService implements 
RegistryService {
         return eventMeshDataInfos;
     }
 
-    @Override
-    public Map<String, Map<String, Integer>> 
findEventMeshClientDistributionData(String clusterName, String group, String 
purpose)
-        throws RegistryException {
-        return Collections.emptyMap();
-    }
-
     @Override
     public void registerMetadata(Map<String, String> metadataMap) {
 
     }
-
-    public ConsulClient getConsulClient() {
-        return consulClient;
-    }
 }
diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java
index 06fcfdc18..47ca18e43 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java
@@ -27,24 +27,24 @@ import 
org.apache.eventmesh.registry.etcd.constant.EtcdConstant;
 import org.apache.commons.collections4.CollectionUtils;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.annotation.Nullable;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import io.etcd.jetcd.ByteSequence;
 import io.etcd.jetcd.Client;
 import io.etcd.jetcd.KeyValue;
 import io.etcd.jetcd.options.GetOption;
 
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
 public class EtcdCustomService extends EtcdRegistryService {
 
     private static final String KEY_PREFIX = "eventMesh" + 
EtcdConstant.KEY_SEPARATOR;
     private static final String KEY_APP = "app";
     private static final String KEY_SERVICE = "service";
-    private static final Logger logger = 
LoggerFactory.getLogger(EtcdCustomService.class);
 
     @Nullable
     public List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
@@ -68,11 +68,11 @@ public class EtcdCustomService extends EtcdRegistryService {
                 return eventMeshServicePubTopicInfoList;
             }
         } catch (Exception e) {
-            
logger.error("[EtcdRegistryService][findEventMeshServicePubTopicInfos] error", 
e);
+            
log.error("[EtcdRegistryService][findEventMeshServicePubTopicInfos] error", e);
             throw new RegistryException(e.getMessage());
         }
 
-        return null;
+        return Collections.emptyList();
     }
 
     @Nullable
@@ -93,7 +93,7 @@ public class EtcdCustomService extends EtcdRegistryService {
                 return eventMeshAppSubTopicInfo;
             }
         } catch (Exception e) {
-            
logger.error("[EtcdRegistryService][findEventMeshAppSubTopicInfoByGroup] error, 
group: {}", group, e);
+            
log.error("[EtcdRegistryService][findEventMeshAppSubTopicInfoByGroup] error, 
group: {}", group, e);
             throw new RegistryException(e.getMessage());
         }
         return null;
diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdRegistryService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdRegistryService.java
index ab1aecc61..c3cf5956a 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdRegistryService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdRegistryService.java
@@ -19,8 +19,6 @@ package org.apache.eventmesh.registry.etcd.service;
 
 import org.apache.eventmesh.api.exception.RegistryException;
 import org.apache.eventmesh.api.registry.RegistryService;
-import org.apache.eventmesh.api.registry.bo.EventMeshAppSubTopicInfo;
-import org.apache.eventmesh.api.registry.bo.EventMeshServicePubTopicInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
@@ -36,12 +34,12 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -53,7 +51,7 @@ import io.etcd.jetcd.KeyValue;
 import io.etcd.jetcd.options.GetOption;
 import io.etcd.jetcd.options.PutOption;
 
-
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -72,9 +70,10 @@ public class EtcdRegistryService implements RegistryService {
 
     private String password;
 
+    @Getter
     private Client etcdClient;
 
-    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+    private ConcurrentMap<String, EventMeshRegisterInfo> 
eventMeshRegisterInfoMap;
 
     private ScheduledExecutorService etcdRegistryMonitorExecutorService;
 
@@ -84,7 +83,7 @@ public class EtcdRegistryService implements RegistryService {
         if (!initStatus.compareAndSet(false, true)) {
             return;
         }
-        eventMeshRegisterInfoMap = new 
HashMap<>(ConfigurationContextUtil.KEYS.size());
+        eventMeshRegisterInfoMap = new 
ConcurrentHashMap<>(ConfigurationContextUtil.KEYS.size());
         for (String key : ConfigurationContextUtil.KEYS) {
             CommonConfiguration commonConfiguration = 
ConfigurationContextUtil.get(key);
             if (null == commonConfiguration) {
@@ -180,13 +179,6 @@ public class EtcdRegistryService implements 
RegistryService {
         }
     }
 
-    @Override
-    public Map<String, Map<String, Integer>> 
findEventMeshClientDistributionData(String clusterName, String group, String 
purpose)
-        throws RegistryException {
-        // todo find metadata
-        return Collections.emptyMap();
-    }
-
     @Override
     public void registerMetadata(Map<String, String> metadataMap) {
         for (Map.Entry<String, EventMeshRegisterInfo> eventMeshRegisterInfo : 
eventMeshRegisterInfoMap.entrySet()) {
@@ -240,20 +232,6 @@ public class EtcdRegistryService implements 
RegistryService {
         }
     }
 
-    @Override
-    public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String 
group) throws RegistryException {
-        return null;
-    }
-
-    @Override
-    public List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
-        return Collections.emptyList();
-    }
-
-    public Client getEtcdClient() {
-        return etcdClient;
-    }
-
     public long getLeaseId() {
         return EtcdClientFactory.getLeaseId(serverAddr);
     }
diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-nacos/src/main/java/org/apache/eventmesh/registry/nacos/service/NacosRegistryService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-nacos/src/main/java/org/apache/eventmesh/registry/nacos/service/NacosRegistryService.java
index 79180efdf..fff040bf2 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-nacos/src/main/java/org/apache/eventmesh/registry/nacos/service/NacosRegistryService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-nacos/src/main/java/org/apache/eventmesh/registry/nacos/service/NacosRegistryService.java
@@ -19,8 +19,6 @@ package org.apache.eventmesh.registry.nacos.service;
 
 import org.apache.eventmesh.api.exception.RegistryException;
 import org.apache.eventmesh.api.registry.RegistryService;
-import org.apache.eventmesh.api.registry.bo.EventMeshAppSubTopicInfo;
-import org.apache.eventmesh.api.registry.bo.EventMeshServicePubTopicInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
@@ -32,11 +30,12 @@ import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import com.alibaba.nacos.api.exception.NacosException;
@@ -45,6 +44,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
 import com.alibaba.nacos.client.naming.NacosNamingService;
 import com.alibaba.nacos.common.utils.CollectionUtils;
 
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -54,15 +54,19 @@ public class NacosRegistryService implements 
RegistryService {
 
     private  final AtomicBoolean startStatus = new AtomicBoolean(false);
 
+    @Getter
     private String serverAddr;
 
+    @Getter
     private String username;
 
+    @Getter
     private String password;
 
+    @Getter
     private NamingService namingService;
 
-    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+    private ConcurrentMap<String, EventMeshRegisterInfo> 
eventMeshRegisterInfoMap;
 
     @Override
     public void init() throws RegistryException {
@@ -70,7 +74,7 @@ public class NacosRegistryService implements RegistryService {
         if (!initStatus.compareAndSet(false, true)) {
             return;
         }
-        eventMeshRegisterInfoMap = new 
HashMap<>(ConfigurationContextUtil.KEYS.size());
+        eventMeshRegisterInfoMap = new 
ConcurrentHashMap<>(ConfigurationContextUtil.KEYS.size());
         for (String key : ConfigurationContextUtil.KEYS) {
             CommonConfiguration commonConfiguration = 
ConfigurationContextUtil.get(key);
             if (null == commonConfiguration) {
@@ -124,39 +128,15 @@ public class NacosRegistryService implements 
RegistryService {
 
     @Override
     public List<EventMeshDataInfo> findEventMeshInfoByCluster(String 
clusterName) throws RegistryException {
-        List<EventMeshDataInfo> eventMeshDataInfoList = new ArrayList<>();
-        for (String key : ConfigurationContextUtil.KEYS) {
-            CommonConfiguration configuration = 
ConfigurationContextUtil.get(key);
-            if (Objects.isNull(configuration)) {
-                continue;
-            }
-            String eventMeshName = configuration.getEventMeshName();
-            try {
-                List<Instance> instances =
-                    namingService.selectInstances(eventMeshName + "-" + key,
-                        configuration.getEventMeshCluster(), 
Collections.singletonList(clusterName),
-                        true);
-                if (CollectionUtils.isEmpty(instances)) {
-                    continue;
-                }
-                for (Instance instance : instances) {
-                    EventMeshDataInfo eventMeshDataInfo =
-                        new EventMeshDataInfo(instance.getClusterName(), 
instance.getServiceName(),
-                            instance.getIp() + ":"
-                                + instance.getPort(), 0L, 
instance.getMetadata());
-                    eventMeshDataInfoList.add(eventMeshDataInfo);
-                }
-            } catch (NacosException e) {
-                log.error("[NacosRegistryService][findEventMeshInfoByCluster] 
error", e);
-                throw new RegistryException(e.getMessage());
-            }
-
-        }
-        return eventMeshDataInfoList;
+        return findEventMeshInfos(true, 
Collections.singletonList(clusterName));
     }
 
     @Override
     public List<EventMeshDataInfo> findAllEventMeshInfo() throws 
RegistryException {
+        return findEventMeshInfos(false, null);
+    }
+
+    private List<EventMeshDataInfo> findEventMeshInfos(boolean inCluster, 
List<String> clusters) {
         List<EventMeshDataInfo> eventMeshDataInfoList = new ArrayList<>();
         for (String key : ConfigurationContextUtil.KEYS) {
             CommonConfiguration configuration = 
ConfigurationContextUtil.get(key);
@@ -166,37 +146,28 @@ public class NacosRegistryService implements 
RegistryService {
             String eventMeshName = configuration.getEventMeshName();
             try {
                 List<Instance> instances =
-                    namingService.selectInstances(eventMeshName + "-"
-                            + key, key + "-" + NacosConstant.GROUP, null,
-                        true);
+                        namingService.selectInstances(eventMeshName + "-" + 
key, 
+                                key + "-" + (inCluster ? 
configuration.getEventMeshCluster() : NacosConstant.GROUP),
+                                clusters,
+                                true);
                 if (CollectionUtils.isEmpty(instances)) {
                     continue;
                 }
                 for (Instance instance : instances) {
                     EventMeshDataInfo eventMeshDataInfo =
-                        new EventMeshDataInfo(instance.getClusterName(), 
instance.getServiceName(),
-                            instance.getIp() + ":"
-                                + instance.getPort(), 0L, 
instance.getMetadata());
+                            new EventMeshDataInfo(instance.getClusterName(), 
instance.getServiceName(),
+                                    instance.getIp() + ":"
+                                            + instance.getPort(), 0L, 
instance.getMetadata());
                     eventMeshDataInfoList.add(eventMeshDataInfo);
                 }
             } catch (NacosException e) {
                 log.error("[NacosRegistryService][findEventMeshInfoByCluster] 
error", e);
                 throw new RegistryException(e.getMessage());
             }
-
         }
         return eventMeshDataInfoList;
     }
 
-    @Override
-    public Map<String, Map<String, Integer>> 
findEventMeshClientDistributionData(String clusterName,
-        String group,
-        String purpose)
-        throws RegistryException {
-        // todo find metadata
-        return Collections.emptyMap();
-    }
-
     @Override
     public void registerMetadata(Map<String, String> metadataMap) {
         for (Map.Entry<String, EventMeshRegisterInfo> eventMeshRegisterInfo : 
eventMeshRegisterInfoMap.entrySet()) {
@@ -210,6 +181,9 @@ public class NacosRegistryService implements 
RegistryService {
     public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) 
throws RegistryException {
         try {
             String[] ipPort = 
eventMeshRegisterInfo.getEndPoint().split(NacosConstant.IP_PORT_SEPARATOR);
+            if (ipPort == null || ipPort.length < 2) {
+                return false;
+            }
             String eventMeshClusterName = 
eventMeshRegisterInfo.getEventMeshClusterName();
             Map<String, String> metadata = eventMeshRegisterInfo.getMetadata();
 
@@ -252,30 +226,4 @@ public class NacosRegistryService implements 
RegistryService {
         log.info("EventMesh successfully logout to nacos");
         return true;
     }
-
-    @Override
-    public List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String 
group) throws RegistryException {
-        return null;
-    }
-
-    public String getServerAddr() {
-        return serverAddr;
-    }
-
-    public String getUsername() {
-        return username;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public NamingService getNamingService() {
-        return namingService;
-    }
 }
diff --git 
a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java
 
b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java
index 577a07861..2b7e322d2 100644
--- 
a/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java
+++ 
b/eventmesh-registry-plugin/eventmesh-registry-zookeeper/src/main/java/org/apache/eventmesh/registry/zookeeper/service/ZookeeperRegistryService.java
@@ -20,8 +20,6 @@ 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.bo.EventMeshAppSubTopicInfo;
-import org.apache.eventmesh.api.registry.bo.EventMeshServicePubTopicInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo;
 import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo;
@@ -42,13 +40,14 @@ import org.apache.zookeeper.data.Stat;
 
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -58,11 +57,13 @@ public class ZookeeperRegistryService implements 
RegistryService {
 
     private final AtomicBoolean startStatus = new AtomicBoolean(false);
 
+    @Getter
     private String serverAddr;
 
-    public CuratorFramework zkClient = null;
+    @Getter
+    public CuratorFramework zkClient;
 
-    private Map<String, EventMeshRegisterInfo> eventMeshRegisterInfoMap;
+    private ConcurrentMap<String, EventMeshRegisterInfo> 
eventMeshRegisterInfoMap;
 
     @Override
     public void init() throws RegistryException {
@@ -71,7 +72,7 @@ public class ZookeeperRegistryService implements 
RegistryService {
             log.warn("[ZookeeperRegistryService] has been init");
             return;
         }
-        eventMeshRegisterInfoMap = new 
HashMap<>(ConfigurationContextUtil.KEYS.size());
+        eventMeshRegisterInfoMap = new 
ConcurrentHashMap<>(ConfigurationContextUtil.KEYS.size());
         for (String key : ConfigurationContextUtil.KEYS) {
             CommonConfiguration commonConfiguration = 
ConfigurationContextUtil.get(key);
             if (null == commonConfiguration) {
@@ -219,14 +220,6 @@ public class ZookeeperRegistryService implements 
RegistryService {
         return eventMeshDataInfoList;
     }
 
-
-    @Override
-    public Map<String, Map<String, Integer>> 
findEventMeshClientDistributionData(String clusterName, String group, String 
purpose)
-        throws RegistryException {
-        // todo find metadata
-        return null;
-    }
-
     @Override
     public void registerMetadata(Map<String, String> metadataMap) {
         for (Map.Entry<String, EventMeshRegisterInfo> eventMeshRegisterInfo : 
eventMeshRegisterInfoMap.entrySet()) {
@@ -240,6 +233,9 @@ public class ZookeeperRegistryService implements 
RegistryService {
     public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) 
throws RegistryException {
         try {
             String[] ipPort = 
eventMeshRegisterInfo.getEndPoint().split(ZookeeperConstant.IP_PORT_SEPARATOR);
+            if (null == ipPort || ipPort.length < 2) {
+                return false;
+            }
             String ip = ipPort[0];
             int port = Integer.parseInt(ipPort[1]);
             String eventMeshName = eventMeshRegisterInfo.getEventMeshName();
@@ -288,16 +284,6 @@ public class ZookeeperRegistryService implements 
RegistryService {
         return true;
     }
 
-    @Override
-    public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String 
group) throws RegistryException {
-        return null;
-    }
-
-    @Override
-    public List<EventMeshServicePubTopicInfo> 
findEventMeshServicePubTopicInfos() throws RegistryException {
-        return null;
-    }
-
     private String formatInstancePath(String clusterName, String serviceName, 
String endPoint) {
         return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName)
             .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName)
@@ -308,12 +294,4 @@ public class ZookeeperRegistryService implements 
RegistryService {
         return ZookeeperConstant.PATH_SEPARATOR.concat(clusterName)
             .concat(ZookeeperConstant.PATH_SEPARATOR).concat(serviceName);
     }
-
-    public String getServerAddr() {
-        return serverAddr;
-    }
-
-    public CuratorFramework getZkClient() {
-        return zkClient;
-    }
 }


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

Reply via email to