servicecomb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] jeho0815 commented on a change in pull request #546: SCB-315 Config Center module can't get config by DynamicPropertyFacto?
Date Thu, 01 Jan 1970 00:00:00 GMT
jeho0815 commented on a change in pull request #546: SCB-315 Config Center module can't get
config by DynamicPropertyFacto?
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/546#discussion_r165803480
 
 

 ##########
 File path: foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/AddressResolverConfig.java
 ##########
 @@ -32,96 +34,113 @@
    * @return AddressResolverOptions
    */
   public static AddressResolverOptions getAddressResover(String tag) {
+    return getAddressResover(tag, null);
+  }
+
+  /**
+   * get the target endpoints with custom address resolve config
+   * @param tag config tag, such as sc.consumer or cc.consumer
+   * @param configSource get config from special config source
+   * @return AddressResolverOptions
+   */
+  public static AddressResolverOptions getAddressResover(String tag, Configuration configSource)
{
     AddressResolverOptions addressResolverOptions = new AddressResolverOptions();
     addressResolverOptions
-        .setServers(getStringListProperty(AddressResolverOptions.DEFAULT_SEACH_DOMAINS,
+        .setServers(getStringListProperty(configSource,
+            AddressResolverOptions.DEFAULT_SEACH_DOMAINS,
             "addressResolver." + tag + ".servers",
             "addressResolver.servers"));
     addressResolverOptions
-        .setOptResourceEnabled(getBooleanProperty(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED,
+        .setOptResourceEnabled(getBooleanProperty(configSource,
+            AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED,
             "addressResolver." + tag + ".optResourceEnabled",
             "addressResolver.optResourceEnabled"));
     addressResolverOptions
-        .setCacheMinTimeToLive(getIntProperty(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE,
+        .setCacheMinTimeToLive(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE,
             "addressResolver." + tag + ".cacheMinTimeToLive",
             "addressResolver.cacheMinTimeToLive"));
     addressResolverOptions
-        .setCacheMaxTimeToLive(getIntProperty(AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE,
+        .setCacheMaxTimeToLive(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE,
             "addressResolver." + tag + ".cacheMaxTimeToLive",
             "addressResolver.cacheMaxTimeToLive"));
     addressResolverOptions
-        .setCacheNegativeTimeToLive(getIntProperty(AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE,
+        .setCacheNegativeTimeToLive(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE,
             "addressResolver." + tag + ".cacheNegativeTimeToLive",
             "addressResolver.cacheNegativeTimeToLive"));
     addressResolverOptions
-        .setQueryTimeout(getIntProperty(AddressResolverOptions.DEFAULT_QUERY_TIMEOUT,
+        .setQueryTimeout(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_QUERY_TIMEOUT,
             "addressResolver." + tag + ".queryTimeout",
             "addressResolver.queryTimeout"));
     addressResolverOptions
-        .setMaxQueries(getIntProperty(AddressResolverOptions.DEFAULT_MAX_QUERIES,
+        .setMaxQueries(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_MAX_QUERIES,
             "addressResolver." + tag + ".maxQueries",
             "addressResolver.maxQueries"));
     addressResolverOptions
-        .setRdFlag(getBooleanProperty(AddressResolverOptions.DEFAULT_RD_FLAG,
+        .setRdFlag(getBooleanProperty(configSource,
+            AddressResolverOptions.DEFAULT_RD_FLAG,
             "addressResolver." + tag + ".rdFlag",
             "addressResolver.rdFlag"));
     addressResolverOptions
-        .setSearchDomains(getStringListProperty(AddressResolverOptions.DEFAULT_SEACH_DOMAINS,
+        .setSearchDomains(getStringListProperty(configSource,
+            AddressResolverOptions.DEFAULT_SEACH_DOMAINS,
             "addressResolver." + tag + ".searchDomains",
             "addressResolver.searchDomains"));
     addressResolverOptions
-        .setNdots(getIntProperty(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE,
+        .setNdots(getIntProperty(configSource,
+            AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE,
             "addressResolver." + tag + ".ndots",
             "addressResolver.ndots"));
     addressResolverOptions
-        .setRotateServers(getBooleanProperty(AddressResolverOptions.DEFAULT_ROTATE_SERVERS,
+        .setRotateServers(getBooleanProperty(configSource,
+            AddressResolverOptions.DEFAULT_ROTATE_SERVERS,
             "addressResolver." + tag + ".rotateServers",
             "addressResolver.rotateServers"));
     return addressResolverOptions;
   }
 
-  private static List<String> getStringListProperty(List<String> defaultValue,
String... keys) {
-    String property = null;
+  private static List<String> getStringListProperty(Configuration configSource,
+      List<String> defaultValue, String... keys) {
+    if (configSource == null) {
+      configSource = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
+    }
     for (String key : keys) {
-      property = DynamicPropertyFactory.getInstance().getStringProperty(key, null).get();
-      if (property != null) {
-        break;
+      String[] vals = configSource.getStringArray(key);
+      if (vals != null && vals.length > 0) {
+        return Arrays.asList(vals);
       }
     }
-    if (property != null) {
-      return Arrays.asList(property.split(","));
-    } else {
-      return defaultValue;
-    }
+    return defaultValue;
   }
 
-  private static int getIntProperty(int defaultValue, String... keys) {
-    int property = -1;
+  private static int getIntProperty(Configuration configSource, int defaultValue, String...
keys) {
+    if (configSource == null) {
+      configSource = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
+    }
     for (String key : keys) {
-      property = DynamicPropertyFactory.getInstance().getIntProperty(key, -1).get();
-      if (property > 0) {
-        break;
+      Integer val = configSource.getInteger(key, null);
+      if (val != null && val > 0) {
 
 Review comment:
   all integer parameters must large than zero

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message