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/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new d342f556d simplify code
     new 702680fe2 Merge pull request #2636 from weihubeats/CommonConfiguration
d342f556d is described below

commit d342f556dfd01ce86846408aa74d818f573ec54f
Author: weihu <[email protected]>
AuthorDate: Wed Dec 21 16:54:21 2022 +0800

    simplify code
---
 .../apache/eventmesh/common/config/CommonConfiguration.java  | 12 ++++++------
 .../apache/eventmesh/common/config/ConfigurationWrapper.java | 12 +++++++++++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git 
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java
 
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java
index 49dfcfde2..62d2330c3 100644
--- 
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java
+++ 
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java
@@ -17,6 +17,7 @@
 
 package org.apache.eventmesh.common.config;
 
+import org.apache.eventmesh.common.utils.AssertUtils;
 import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
 import org.apache.eventmesh.common.utils.IPUtils;
 
@@ -25,7 +26,6 @@ import org.apache.commons.lang3.StringUtils;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
@@ -96,11 +96,11 @@ public class CommonConfiguration {
 
             namesrvAddr = 
checkNotEmpty(ConfKeys.KEYS_EVENTMESH_REGISTRY_PULGIN_SERVER_ADDR);
 
-            eventMeshRegistryPluginUsername = Optional.ofNullable(
-                    
configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_PULGIN_USERNAME)).orElse("");
+            eventMeshRegistryPluginUsername = 
+                    
configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_PULGIN_USERNAME, 
"");
 
-            eventMeshRegistryPluginPassword = Optional.ofNullable(
-                    
configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_PULGIN_PASSWORD)).orElse("");
+            eventMeshRegistryPluginPassword = 
+                    
configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_PULGIN_PASSWORD, 
"");
 
             String metricsPluginType = 
configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_METRICS_PLUGIN_TYPE);
             if (StringUtils.isNotEmpty(metricsPluginType)) {
@@ -125,7 +125,7 @@ public class CommonConfiguration {
         if (value != null) {
             value = StringUtils.deleteWhitespace(value);
         }
-        Preconditions.checkState(StringUtils.isNotEmpty(value), key + " is 
invalidated");
+        AssertUtils.notBlack(value, key + " is invalidated");
         return value;
     }
 
diff --git 
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java
 
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java
index eddf81c9e..3df946709 100644
--- 
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java
+++ 
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java
@@ -111,7 +111,17 @@ public class ConfigurationWrapper {
     }
 
     public String getProp(String key) {
-        return StringUtils.isEmpty(key) ? null : properties.getProperty(key, 
null);
+        return getProp(key, null);
+    }
+
+    /**
+     * get key value if value is null then return defaultValue
+     * @param key key
+     * @param defaultValue defaultValue
+     * @return string
+     */
+    public String getProp(String key, String defaultValue) {
+        return StringUtils.isEmpty(key) ? defaultValue : 
properties.getProperty(key, defaultValue);
     }
 
     public int getIntProp(String configKey, int defaultValue) {


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

Reply via email to