From dev-return-1870-archive-asf-public=cust-asf.ponee.io@servicecomb.apache.org Sat Feb 3 04:27:17 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 5C015180608 for ; Sat, 3 Feb 2018 04:27:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4B9F2160C57; Sat, 3 Feb 2018 03:27:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6D736160C49 for ; Sat, 3 Feb 2018 04:27:16 +0100 (CET) Received: (qmail 20657 invoked by uid 500); 3 Feb 2018 03:27:15 -0000 Mailing-List: contact dev-help@servicecomb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@servicecomb.apache.org Delivered-To: mailing list dev@servicecomb.apache.org Received: (qmail 20646 invoked by uid 99); 3 Feb 2018 03:27:15 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Feb 2018 03:27:15 +0000 From: GitBox To: dev@servicecomb.apache.org Subject: [GitHub] jeho0815 commented on a change in pull request #546: SCB-315 Config Center module can't get config by DynamicPropertyFacto? Message-ID: <151762843471.18741.14217513502354032107.gitbox@gitbox.apache.org> 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 getStringListProperty(List defaultValue, String... keys) { - String property = null; + private static List getStringListProperty(Configuration configSource, + List 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