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

xiatian pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/eventmesh-dashboard.git


The following commit(s) were added to refs/heads/main by this push:
     new b43812a  Add SDKManager JavaDoc and some code optimisation (#121)
b43812a is described below

commit b43812a680977c4417c1927e9c17a06103b895b1
Author: Alonexc <[email protected]>
AuthorDate: Wed Apr 17 22:54:40 2024 +0800

    Add SDKManager JavaDoc and some code optimisation (#121)
    
    * SDKManager optimisation and doc
    
    * doc
    
    * doc
    
    * doc
---
 eventmesh-dashboard-core/pom.xml                   | 21 ----------
 .../dashboard/core/function/SDK/SDKManager.java    | 48 ++++++++++++++--------
 .../dashboard/core/function/SDK/SDKOperation.java  |  4 +-
 .../function/SDK/config/CreateNacosConfig.java     |  6 +++
 .../SDK/operation/NacosConfigSDKOperation.java     |  3 +-
 .../SDK/operation/NacosNamingSDKOperation.java     |  3 +-
 .../core/function/SDK/SDKManagerTest.java          |  1 -
 .../service/remoting/ConnectorRemotingService.java |  4 +-
 8 files changed, 46 insertions(+), 44 deletions(-)

diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml
index c5d20d7..135ba00 100644
--- a/eventmesh-dashboard-core/pom.xml
+++ b/eventmesh-dashboard-core/pom.xml
@@ -86,27 +86,6 @@
             <version>0.7.7</version>
         </dependency>
 
-        <!-- health check client -->
-        <!-- EventMesh SDK -->
-        <!--        <dependency>-->
-        <!--            <groupId>org.apache.eventmesh</groupId>-->
-        <!--            <artifactId>eventmesh-sdk-java</artifactId>-->
-        <!--            <version>1.10.0-release</version>-->
-        <!--            <exclusions>-->
-        <!--                <exclusion>-->
-        <!--                    <groupId>junit</groupId>-->
-        <!--                    <artifactId>junit</artifactId>-->
-        <!--                </exclusion>-->
-        <!--                <exclusion>-->
-        <!--                    <groupId>junit</groupId>-->
-        <!--                    <artifactId>junit-dep</artifactId>-->
-        <!--                </exclusion>-->
-        <!--                <exclusion>-->
-        <!--                    <groupId>org.apache.logging.log4j</groupId>-->
-        <!--                    <artifactId>log4j-slf4j-impl</artifactId>-->
-        <!--                </exclusion>-->
-        <!--            </exclusions>-->
-        <!--        </dependency>-->
         <!-- storage redis client -->
         <dependency>
             <groupId>io.lettuce</groupId>
diff --git 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java
 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java
index e8e722e..f4f8a8a 100644
--- 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java
+++ 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java
@@ -48,7 +48,6 @@ public class SDKManager {
 
     private static volatile SDKManager INSTANCE = null;
 
-
     public static synchronized SDKManager getInstance() {
         if (INSTANCE == null) {
             synchronized (SDKManager.class) {
@@ -62,41 +61,57 @@ public class SDKManager {
 
     /**
      * inner key is the unique key of a client, such as (ip + port) they are 
defined in CreateClientConfig
-     *
+     * <p>
+     * key: SDKTypeEnum
+     * value: A map collection is used with key being (ip+port) and value 
being client.
      * @see CreateSDKConfig#getUniqueKey()
      */
+    private static final Map<SDKTypeEnum, Map<String, Object>> clientMap = new 
ConcurrentHashMap<>();
 
-    private final Map<SDKTypeEnum, Map<String, Object>> clientMap = new 
ConcurrentHashMap<>();
-
-    private final Map<SDKTypeEnum, SDKOperation<?>> clientCreateOperationMap = 
new ConcurrentHashMap<>();
+    /**
+     * Initialise the SDKOperation object instance according to SDKTypeEnum.
+     * <p>
+     * key: SDKTypeEnum
+     * value: SDKOperation
+     * @see SDKTypeEnum
+     * @see SDKOperation
+     */
+    private static final Map<SDKTypeEnum, SDKOperation<?>> 
clientCreateOperationMap = new ConcurrentHashMap<>();
 
     // register all client create operation
-    {
+    static {
         for (SDKTypeEnum clientTypeEnum : SDKTypeEnum.values()) {
             clientMap.put(clientTypeEnum, new ConcurrentHashMap<>());
         }
-
+        // redis
         clientCreateOperationMap.put(SDKTypeEnum.STORAGE_REDIS, new 
RedisSDKOperation());
 
+        // rocketmq
         clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, 
new RocketMQRemotingSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_PRODUCER, 
new RocketMQProduceSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_CONSUMER, 
new RocketMQPushConsumerSDKOperation());
 
+        // nacos
         clientCreateOperationMap.put(SDKTypeEnum.META_NACOS, new 
NacosSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.META_NACOS_CONFIG, new 
NacosConfigSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.META_NACOS_NAMING, new 
NacosNamingSDKOperation());
 
+        // etcd
         clientCreateOperationMap.put(SDKTypeEnum.META_ETCD, new 
EtcdSDKOperation());
 
+        // eventmesh_runtime
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_EVENTMESH_CLIENT, new 
RuntimeSDKOperation());
 
+        // eventmesh_runtime_tcp
         
clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_CLOUDEVENT_CLIENT, new 
RuntimeTcpCloudEventSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_EVENTMESH_CLIENT, 
new RuntimeTcpEventMeshSDKOperation());
         
clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_OPENMESSAGE_CLIENT, new 
RuntimeTcpOpenMessageSDKOperation());
 
+        // eventmesh_runtime_http
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_HTTP_PRODUCER, new 
RuntimeHttpProducerSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_HTTP_CONSUMER, new 
RuntimeHttpConsumerSDKOperation());
 
+        // eventmesh_runtime_grpc
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_GRPC_PRODUCER, new 
RuntimeGrpcProducerSDKOperation());
         clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_GRPC_CONSUMER, new 
RuntimeGrpcConsumerSDKOperation());
     }
@@ -104,18 +119,19 @@ public class SDKManager {
     private SDKManager() {
     }
 
+    /**
+     * Create SDK client through (SDKTypeEnum) clientTypeEnum, 
(CreateSDKConfig) config.
+     */
     public <T> SimpleEntry<String, T> createClient(SDKTypeEnum clientTypeEnum, 
CreateSDKConfig config) {
-        return createClient(clientTypeEnum, config.getUniqueKey(), config);
-    }
 
-    public <T> SimpleEntry<String, T> createClient(SDKTypeEnum clientTypeEnum, 
String uniqueKey, CreateSDKConfig config) {
+        final String uniqueKey = config.getUniqueKey();
 
-        Map<String, Object> clients = this.clientMap.get(clientTypeEnum);
+        Map<String, Object> clients = clientMap.get(clientTypeEnum);
 
         Object client = clients.get(uniqueKey);
         SimpleEntry<String, ?> result = new SimpleEntry<>(uniqueKey, client);
         if (Objects.isNull(client)) {
-            SDKOperation<?> clientCreateOperation = 
this.clientCreateOperationMap.get(clientTypeEnum);
+            SDKOperation<?> clientCreateOperation = 
clientCreateOperationMap.get(clientTypeEnum);
             result = clientCreateOperation.createClient(config);
             clients.put(result.getKey(), result.getValue());
         }
@@ -127,8 +143,8 @@ public class SDKManager {
     }
 
     public void deleteClient(SDKTypeEnum clientTypeEnum, String uniqueKey) {
-        Map<String, Object> clients = this.clientMap.get(clientTypeEnum);
-        SDKOperation<?> operation = 
this.clientCreateOperationMap.get(clientTypeEnum);
+        Map<String, Object> clients = clientMap.get(clientTypeEnum);
+        SDKOperation<?> operation = 
clientCreateOperationMap.get(clientTypeEnum);
         try {
             operation.close(clients.get(uniqueKey));
         } catch (Exception e) {
@@ -138,11 +154,11 @@ public class SDKManager {
     }
 
     public Object getClient(SDKTypeEnum clientTypeEnum, String uniqueKey) {
-        return this.clientMap.get(clientTypeEnum).get(uniqueKey);
+        return clientMap.get(clientTypeEnum).get(uniqueKey);
     }
 
     // get all client
     public Map<String, Object> getClients(SDKTypeEnum clientTypeEnum) {
-        return this.clientMap.get(clientTypeEnum);
+        return clientMap.get(clientTypeEnum);
     }
 }
diff --git 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKOperation.java
 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKOperation.java
index 8e9e9ec..fd4f4cf 100644
--- 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKOperation.java
+++ 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKOperation.java
@@ -28,9 +28,9 @@ import java.util.AbstractMap.SimpleEntry;
  */
 public interface SDKOperation<T> {
 
-    public SimpleEntry<String, T> createClient(CreateSDKConfig clientConfig);
+    SimpleEntry<String, T> createClient(CreateSDKConfig clientConfig);
 
 
-    public void close(Object client);
+    void close(Object client);
 
 }
diff --git 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateNacosConfig.java
 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateNacosConfig.java
index 2fd8ef0..71a1c61 100644
--- 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateNacosConfig.java
+++ 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateNacosConfig.java
@@ -17,9 +17,15 @@
 
 package org.apache.eventmesh.dashboard.core.function.SDK.config;
 
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 @Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
 public class CreateNacosConfig implements CreateSDKConfig {
 
     private String serverAddress;
diff --git 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosConfigSDKOperation.java
 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosConfigSDKOperation.java
index cea39d6..982a6ee 100644
--- 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosConfigSDKOperation.java
+++ 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosConfigSDKOperation.java
@@ -25,6 +25,7 @@ import java.util.AbstractMap.SimpleEntry;
 import java.util.Properties;
 
 import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.PropertyKeyConst;
 import com.alibaba.nacos.api.config.ConfigService;
 import com.alibaba.nacos.api.exception.NacosException;
 
@@ -39,7 +40,7 @@ public class NacosConfigSDKOperation extends 
AbstractSDKOperation<ConfigService>
         CreateNacosConfig config = (CreateNacosConfig) clientConfig;
         try {
             Properties properties = new Properties();
-            properties.put("serverAddr", config.getServerAddress());
+            properties.put(PropertyKeyConst.SERVER_ADDR, 
config.getServerAddress());
             configService = NacosFactory.createConfigService(properties);
         } catch (NacosException e) {
             log.error("NacosCheck init failed caused by {}", e.getErrMsg());
diff --git 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosNamingSDKOperation.java
 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosNamingSDKOperation.java
index b6707b3..28431f9 100644
--- 
a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosNamingSDKOperation.java
+++ 
b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosNamingSDKOperation.java
@@ -25,6 +25,7 @@ import java.util.AbstractMap.SimpleEntry;
 import java.util.Properties;
 
 import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.PropertyKeyConst;
 import com.alibaba.nacos.api.config.ConfigService;
 import com.alibaba.nacos.api.exception.NacosException;
 import com.alibaba.nacos.api.naming.NamingService;
@@ -40,7 +41,7 @@ public class NacosNamingSDKOperation extends 
AbstractSDKOperation<NamingService>
         CreateNacosConfig config = (CreateNacosConfig) clientConfig;
         try {
             Properties properties = new Properties();
-            properties.put("serverAddr", config.getServerAddress());
+            properties.put(PropertyKeyConst.SERVER_ADDR, 
config.getServerAddress());
             namingService = NacosFactory.createNamingService(properties);
         } catch (NacosException e) {
             log.error("NacosCheck init failed caused by {}", e.getErrMsg());
diff --git 
a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java
 
b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java
index e936696..fb66c57 100644
--- 
a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java
+++ 
b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java
@@ -40,7 +40,6 @@ class SDKManagerTest {
                 .password("")
                 .timeOut(30)
                 .build();
-            // createRedisConfig.setRedisUrl("redis://localhost:6379");
             redisKey = 
SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, 
createRedisConfig).getKey();
         } catch (Exception e) {
             log.warn("SDK manager test init failed, possible reason: 
redis-server is offline. {}", this.getClass().getSimpleName(), e);
diff --git 
a/eventmesh-dashboard-service/src/main/java/org/apache/eventmesh/dashboard/service/remoting/ConnectorRemotingService.java
 
b/eventmesh-dashboard-service/src/main/java/org/apache/eventmesh/dashboard/service/remoting/ConnectorRemotingService.java
index 40b020c..1164b38 100644
--- 
a/eventmesh-dashboard-service/src/main/java/org/apache/eventmesh/dashboard/service/remoting/ConnectorRemotingService.java
+++ 
b/eventmesh-dashboard-service/src/main/java/org/apache/eventmesh/dashboard/service/remoting/ConnectorRemotingService.java
@@ -27,7 +27,7 @@ import 
org.apache.eventmesh.dashboard.common.model.remoting.connector.GetConnect
  */
 public interface ConnectorRemotingService {
 
-    public GetConnectorResult getConnectors(GetConnectorRequest 
getConnectorRequest);
+    GetConnectorResult getConnectors(GetConnectorRequest getConnectorRequest);
 
-    public CreateConnectorResult createConnector(CreateConnectorRequest 
createConnectorRequest);
+    CreateConnectorResult createConnector(CreateConnectorRequest 
createConnectorRequest);
 }


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

Reply via email to