Skip to content

Commit

Permalink
Polish apache#6261 : Migration the latest Nacos registry implementati…
Browse files Browse the repository at this point in the history
…on to upstream
  • Loading branch information
mercyblitz committed Jul 3, 2020
1 parent 50361e1 commit e4abd39
Showing 1 changed file with 9 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,20 @@
import org.apache.dubbo.registry.client.ServiceInstance;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.utils.NamingUtils;

import java.util.Map;
import java.util.Properties;

import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING;
import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE;
import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_POLLING_THREAD_COUNT;
import static com.alibaba.nacos.api.PropertyKeyConst.RAM_ROLE_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.utils.StringConstantFieldValuePredicate.of;

/**
* The utilities class for {@link NamingService}
Expand Down Expand Up @@ -154,25 +139,13 @@ private static void setServerAddr(URL url, Properties properties) {
}

private static void setProperties(URL url, Properties properties) {
putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
putPropertyIfAbsent(url, properties, IS_USE_CLOUD_NAMESPACE_PARSING);
putPropertyIfAbsent(url, properties, IS_USE_ENDPOINT_PARSING_RULE);
putPropertyIfAbsent(url, properties, ENDPOINT);
putPropertyIfAbsent(url, properties, ENDPOINT_PORT);
putPropertyIfAbsent(url, properties, NAMESPACE);
putPropertyIfAbsent(url, properties, ACCESS_KEY);
putPropertyIfAbsent(url, properties, SECRET_KEY);
putPropertyIfAbsent(url, properties, RAM_ROLE_NAME);
putPropertyIfAbsent(url, properties, CONTEXT_PATH);
putPropertyIfAbsent(url, properties, CLUSTER_NAME);
putPropertyIfAbsent(url, properties, ENCODE);
putPropertyIfAbsent(url, properties, CONFIG_LONG_POLL_TIMEOUT);
putPropertyIfAbsent(url, properties, CONFIG_RETRY_TIME);
putPropertyIfAbsent(url, properties, MAX_RETRY);
putPropertyIfAbsent(url, properties, ENABLE_REMOTE_SYNC_CONFIG);
// @since 2.7.8 : Refactoring
// Get the parameters from constants
Map<String, String> parameters = url.getParameters(of(PropertyKeyConst.class));
// Put all parameters
properties.putAll(parameters);

putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
putPropertyIfAbsent(url, properties, NAMING_CLIENT_BEAT_THREAD_COUNT);
putPropertyIfAbsent(url, properties, NAMING_POLLING_THREAD_COUNT);
}

private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
Expand Down

0 comments on commit e4abd39

Please sign in to comment.