diff --git a/dubbo-registry/dubbo-registry-api/pom.xml b/dubbo-registry/dubbo-registry-api/pom.xml index acbc9ec740..a805b8f64c 100644 --- a/dubbo-registry/dubbo-registry-api/pom.xml +++ b/dubbo-registry/dubbo-registry-api/pom.xml @@ -1,12 +1,13 @@ exporter private final Map> bounds = new ConcurrentHashMap>(); private Cluster cluster; @@ -72,7 +71,7 @@ public class RegistryProtocol implements Protocol { return INSTANCE; } - //过滤URL中不需要输出的参数(以点号开头的) + //Filter the parameters that do not need to be output in url(Starting with .) private static String[] getFilteredKeys(URL url) { Map params = url.getParameters(); if (params != null && !params.isEmpty()) { @@ -137,13 +136,13 @@ public class RegistryProtocol implements Protocol { ProviderConsumerRegTable.getProviderWrapper(originInvoker).setReg(true); } - // 订阅override数据 - // FIXME 提供者订阅时,会影响同一JVM即暴露服务,又引用同一服务的的场景,因为subscribed以服务名为缓存的key,导致订阅信息覆盖。 + // Subscribe the override data + // FIXME When the provider subscribes, it will affect the scene : a certain JVM exposes the service and call the same service. Because the subscribed is cached key with the name of the service, it causes the subscription information to cover. final URL overrideSubscribeUrl = getSubscribedOverrideUrl(registedProviderUrl); final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl, originInvoker); overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener); registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); - //保证每次export都返回一个新的exporter实例 + //Ensure that a new exporter instance is returned every time export return new Exporter() { public Invoker getInvoker() { return exporter.getInvoker(); @@ -188,7 +187,7 @@ public class RegistryProtocol implements Protocol { } /** - * 对修改了url的invoker重新export + * Reexport the invoker of the modified url * * @param originInvoker * @param newInvokerUrl @@ -206,7 +205,7 @@ public class RegistryProtocol implements Protocol { } /** - * 根据invoker的地址获取registry实例 + * Get an instance of registry based on the address of invoker * * @param originInvoker * @return @@ -227,14 +226,14 @@ public class RegistryProtocol implements Protocol { /** - * 返回注册到注册中心的URL,对URL参数进行一次过滤 + * Return the url that is registered to the registry and filter the url parameter once * * @param originInvoker * @return */ private URL getRegistedProviderUrl(final Invoker originInvoker) { URL providerUrl = getProviderUrl(originInvoker); - //注册中心看到的地址 + //The address you see at the registry final URL registedProviderUrl = providerUrl.removeParameters(getFilteredKeys(providerUrl)) .removeParameter(Constants.MONITOR_KEY) .removeParameter(Constants.BIND_IP_KEY) @@ -249,7 +248,7 @@ public class RegistryProtocol implements Protocol { } /** - * 通过invoker的url 获取 providerUrl的地址 + * Get the address of the providerUrl through the url of the invoker * * @param origininvoker * @return @@ -265,7 +264,7 @@ public class RegistryProtocol implements Protocol { } /** - * 获取invoker在bounds中缓存的key + * Get the key cached in bounds by invoker * * @param originInvoker * @return @@ -304,7 +303,7 @@ public class RegistryProtocol implements Protocol { RegistryDirectory directory = new RegistryDirectory(type, url); directory.setRegistry(registry); directory.setProtocol(protocol); - // REFER_KEY的所有属性 + // all attributes of REFER_KEY Map parameters = new HashMap(directory.getUrl().getParameters()); URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters); if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) @@ -335,7 +334,7 @@ public class RegistryProtocol implements Protocol { /** * @param invoker - * @param url invoker.getUrl返回此值 + * @param url invoker.getUrl return this value */ public InvokerDelegete(Invoker invoker, URL url) { super(invoker, url); @@ -351,10 +350,11 @@ public class RegistryProtocol implements Protocol { } } - /*重新export 1.protocol中的exporter destory问题 - *1.要求registryprotocol返回的exporter可以正常destroy - *2.notify后不需要重新向注册中心注册 - *3.export 方法传入的invoker最好能一直作为exporter的invoker. + /** + * Reexport: the exporter destroy problem in protocol + * 1.Ensure that the exporter returned by registryprotocol can be normal destroyed + * 2.No need to re-register to the registry after notify + * 3.The invoker passed by the export method , would better to be the invoker of exporter */ private class OverrideListener implements NotifyListener { @@ -367,13 +367,13 @@ public class RegistryProtocol implements Protocol { } /** - * @param urls 已注册信息列表,总不为空,含义同{@link com.alibaba.dubbo.registry.RegistryService#lookup(URL)}的返回值。 + * @param urls The list of registered information , is always not empty, The meaning is the same as the return value of {@link com.alibaba.dubbo.registry.RegistryService#lookup(URL)}. */ public synchronized void notify(List urls) { logger.debug("original override urls: " + urls); List matchedUrls = getMatchedUrls(urls, subscribeUrl); logger.debug("subscribe url: " + subscribeUrl + ", override urls: " + matchedUrls); - //没有匹配的 + // No matching results if (matchedUrls.isEmpty()) { return; } @@ -386,7 +386,7 @@ public class RegistryProtocol implements Protocol { } else { invoker = originInvoker; } - //最原始的invoker + //The origin invoker URL originUrl = RegistryProtocol.this.getProviderUrl(invoker); String key = getCacheKey(originInvoker); ExporterChangeableWrapper exporter = bounds.get(key); @@ -394,9 +394,9 @@ public class RegistryProtocol implements Protocol { logger.warn(new IllegalStateException("error state, exporter should not be null")); return; } - //当前的,可能经过了多次merge + //The current, may have been merged many times URL currentUrl = exporter.getInvoker().getUrl(); - //与本次配置merge的 + //Merged with this configuration URL newUrl = getConfigedInvokerUrl(configurators, originUrl); if (!currentUrl.equals(newUrl)) { RegistryProtocol.this.doChangeLocalExport(originInvoker, newUrl); @@ -408,13 +408,13 @@ public class RegistryProtocol implements Protocol { List result = new ArrayList(); for (URL url : configuratorUrls) { URL overrideUrl = url; - // 兼容旧版本 + // Compatible with the old version if (url.getParameter(Constants.CATEGORY_KEY) == null && Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) { overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY); } - //检查是不是要应用到当前服务上 + // Check whether url is to be applied to the current service if (UrlUtils.isMatch(currentSubscribe, overrideUrl)) { result.add(url); } @@ -422,7 +422,7 @@ public class RegistryProtocol implements Protocol { return result; } - //合并配置的url + //Merge the urls of configurators private URL getConfigedInvokerUrl(List configurators, URL url) { for (Configurator configurator : configurators) { url = configurator.configure(url); @@ -432,10 +432,9 @@ public class RegistryProtocol implements Protocol { } /** - * exporter代理,建立返回的exporter与protocol export出的exporter的对应关系,在override时可以进行关系修改. + * exporter proxy, establish the corresponding relationship between the returned exporter and the exporter exported by the protocol, and can modify the relationship at the time of override. * * @param - * @author chao.liuc */ private class ExporterChangeableWrapper implements Exporter { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java index e4a0965f12..19a08c0bf0 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +31,6 @@ import java.util.Set; /** * RegisteredPageHandler * - * @author william.liangf */ public class RegisteredPageHandler implements PageHandler { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java index 8d144f2666..8f1a88d6dd 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,7 +32,6 @@ import java.util.List; /** * RegistriesPageHandler * - * @author william.liangf */ @Menu(name = "Registries", desc = "Show connected registries.", order = 10000) public class RegistriesPageHandler implements PageHandler { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java index a8c47be81d..b048eb90f8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +31,6 @@ import java.util.Set; /** * SubscribedPageHandler * - * @author william.liangf */ public class SubscribedPageHandler implements PageHandler { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/status/RegistryStatusChecker.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/status/RegistryStatusChecker.java index d78b141977..3436d7c711 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/status/RegistryStatusChecker.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/status/RegistryStatusChecker.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,7 +27,6 @@ import java.util.Collection; /** * RegistryStatusChecker * - * @author william.liangf */ @Activate public class RegistryStatusChecker implements StatusChecker { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistry.java index a347c411e7..1ec2da435d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistry.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -52,36 +53,34 @@ import java.util.concurrent.atomic.AtomicReference; /** * AbstractRegistry. (SPI, Prototype, ThreadSafe) * - * @author chao.liuc - * @author william.liangf */ public abstract class AbstractRegistry implements Registry { - // URL地址分隔符,用于文件缓存中,服务提供者URL分隔 + // URL address separator, used in file cache, service provider URL separation private static final char URL_SEPARATOR = ' '; - // URL地址分隔正则表达式,用于解析文件缓存中服务提供者URL列表 + // URL address separated regular expression for parsing the service provider URL list in the file cache private static final String URL_SPLIT = "\\s+"; - // 日志输出 + // Log output protected final Logger logger = LoggerFactory.getLogger(getClass()); - // 本地磁盘缓存,其中特殊的key值.registies记录注册中心列表,其它均为notified服务提供者列表 + // Local disk cache, where the special key value.registies records the list of registry centers, and the others are the list of notified service providers private final Properties properties = new Properties(); - // 文件缓存定时写入 + // File cache timing writing private final ExecutorService registryCacheExecutor = Executors.newFixedThreadPool(1, new NamedThreadFactory("DubboSaveRegistryCache", true)); - //是否是同步保存文件 + // Is it synchronized to save the file private final boolean syncSaveFile; private final AtomicLong lastCacheChanged = new AtomicLong(); private final Set registered = new ConcurrentHashSet(); private final ConcurrentMap> subscribed = new ConcurrentHashMap>(); private final ConcurrentMap>> notified = new ConcurrentHashMap>>(); private URL registryUrl; - // 本地磁盘缓存文件 + // Local disk cache file private File file; private AtomicBoolean destroyed = new AtomicBoolean(false); public AbstractRegistry(URL url) { setUrl(url); - // 启动文件保存定时器 + // Start file save timer syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false); String filename = url.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(Constants.APPLICATION_KEY) + "-" + url.getAddress() + ".cache"); File file = null; @@ -149,7 +148,7 @@ public abstract class AbstractRegistry implements Registry { if (file == null) { return; } - // 保存 + // Save try { File lockfile = new File(file.getAbsolutePath() + ".lock"); if (!lockfile.exists()) { @@ -163,7 +162,7 @@ public abstract class AbstractRegistry implements Registry { if (lock == null) { throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties"); } - // 保存 + // Save try { if (!file.exists()) { file.createNewFile(); @@ -252,7 +251,7 @@ public abstract class AbstractRegistry implements Registry { reference.set(urls); } }; - subscribe(url, listener); // 订阅逻辑保证第一次notify后再返回 + subscribe(url, listener); // Subscribe logic guarantees the first notify to return List urls = reference.get(); if (urls != null && urls.size() > 0) { for (URL u : urls) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java index 8df65fcce7..1fa4429a2d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,38 +33,37 @@ import java.util.concurrent.locks.ReentrantLock; /** * AbstractRegistryFactory. (SPI, Singleton, ThreadSafe) * - * @author william.liangf * @see com.alibaba.dubbo.registry.RegistryFactory */ public abstract class AbstractRegistryFactory implements RegistryFactory { - // 日志输出 + // Log output private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRegistryFactory.class); - // 注册中心获取过程锁 + // The lock for the acquisition process of the registry private static final ReentrantLock LOCK = new ReentrantLock(); - // 注册中心集合 Map + // Registry Collection Map private static final Map REGISTRIES = new ConcurrentHashMap(); /** - * 获取所有注册中心 + * Get all registries * - * @return 所有注册中心 + * @return all registries */ public static Collection getRegistries() { return Collections.unmodifiableCollection(REGISTRIES.values()); } /** - * 关闭所有已创建注册中心 + * Close all created registries */ // TODO: 2017/8/30 to move somewhere else better public static void destroyAll() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Close all registries " + getRegistries()); } - // 锁定注册中心关闭过程 + // Lock up the registry shutdown process LOCK.lock(); try { for (Registry registry : getRegistries()) { @@ -75,7 +75,7 @@ public abstract class AbstractRegistryFactory implements RegistryFactory { } REGISTRIES.clear(); } finally { - // 释放锁 + // Release the lock LOCK.unlock(); } } @@ -85,7 +85,7 @@ public abstract class AbstractRegistryFactory implements RegistryFactory { .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY); String key = url.toServiceString(); - // 锁定注册中心获取过程,保证注册中心单一实例 + // Lock the registry access process to ensure a single instance of the registry LOCK.lock(); try { Registry registry = REGISTRIES.get(key); @@ -99,7 +99,7 @@ public abstract class AbstractRegistryFactory implements RegistryFactory { REGISTRIES.put(key, registry); return registry; } finally { - // 释放锁 + // Release the lock LOCK.unlock(); } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ConsumerInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ConsumerInvokerWrapper.java index 7e962e04e5..e0cb8e1079 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ConsumerInvokerWrapper.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ConsumerInvokerWrapper.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.dubbo.registry.support; import com.alibaba.dubbo.common.URL; @@ -8,7 +24,6 @@ import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcException; /** - * @author qinliujie * @date 2017/11/23 */ public class ConsumerInvokerWrapper implements Invoker { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/FailbackRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/FailbackRegistry.java index 1ae713562d..a0ea25174b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/FailbackRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/FailbackRegistry.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,14 +39,13 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * FailbackRegistry. (SPI, Prototype, ThreadSafe) * - * @author william.liangf */ public abstract class FailbackRegistry extends AbstractRegistry { - // 定时任务执行器 + // Scheduled executor service private final ScheduledExecutorService retryExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DubboRegistryFailedRetryTimer", true)); - // 失败重试定时器,定时检查是否有请求失败,如有,无限次重试 + // Timer for failure retry, regular check if there is a request for failure, and if there is, an unlimited retry private final ScheduledFuture retryFuture; private final Set failedRegistered = new ConcurrentHashSet(); @@ -65,10 +65,10 @@ public abstract class FailbackRegistry extends AbstractRegistry { int retryPeriod = url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD); this.retryFuture = retryExecutor.scheduleWithFixedDelay(new Runnable() { public void run() { - // 检测并连接注册中心 + // Check and connect to the registry try { retry(); - } catch (Throwable t) { // 防御性容错 + } catch (Throwable t) { // Defensive fault tolerance logger.error("Unexpected error occur at failed retry, cause: " + t.getMessage(), t); } } @@ -132,12 +132,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { failedRegistered.remove(url); failedUnregistered.remove(url); try { - // 向服务器端发送注册请求 + // Sending a registration request to the server side doRegister(url); } catch (Exception e) { Throwable t = e; - // 如果开启了启动时检测,则直接抛出异常 + // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true) && !Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()); @@ -151,7 +151,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { logger.error("Failed to register " + url + ", waiting for retry, cause: " + t.getMessage(), t); } - // 将失败的注册请求记录到失败列表,定时重试 + // Record a failed registration request to a failed list, retry regularly failedRegistered.add(url); } } @@ -165,12 +165,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { failedRegistered.remove(url); failedUnregistered.remove(url); try { - // 向服务器端发送取消注册请求 + // Sending a cancellation request to the server side doUnregister(url); } catch (Exception e) { Throwable t = e; - // 如果开启了启动时检测,则直接抛出异常 + // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true) && !Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()); @@ -184,7 +184,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { logger.error("Failed to uregister " + url + ", waiting for retry, cause: " + t.getMessage(), t); } - // 将失败的取消注册请求记录到失败列表,定时重试 + // Record a failed registration request to a failed list, retry regularly failedUnregistered.add(url); } } @@ -197,7 +197,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { super.subscribe(url, listener); removeFailedSubscribed(url, listener); try { - // 向服务器端发送订阅请求 + // Sending a subscription request to the server side doSubscribe(url, listener); } catch (Exception e) { Throwable t = e; @@ -207,7 +207,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { notify(url, listener, urls); logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t); } else { - // 如果开启了启动时检测,则直接抛出异常 + // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true); boolean skipFailback = t instanceof SkipFailbackWrapperException; @@ -221,7 +221,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { } } - // 将失败的订阅请求记录到失败列表,定时重试 + // Record a failed registration request to a failed list, retry regularly addFailedSubscribed(url, listener); } } @@ -234,12 +234,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { super.unsubscribe(url, listener); removeFailedSubscribed(url, listener); try { - // 向服务器端发送取消订阅请求 + // Sending a canceling subscription request to the server side doUnsubscribe(url, listener); } catch (Exception e) { Throwable t = e; - // 如果开启了启动时检测,则直接抛出异常 + // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true); boolean skipFailback = t instanceof SkipFailbackWrapperException; @@ -252,7 +252,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { logger.error("Failed to unsubscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t); } - // 将失败的取消订阅请求记录到失败列表,定时重试 + // Record a failed registration request to a failed list, retry regularly Set listeners = failedUnsubscribed.get(url); if (listeners == null) { failedUnsubscribed.putIfAbsent(url, new ConcurrentHashSet()); @@ -273,7 +273,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { try { doNotify(url, listener, urls); } catch (Exception t) { - // 将失败的通知请求记录到失败列表,定时重试 + // Record a failed registration request to a failed list, retry regularly Map> listeners = failedNotified.get(url); if (listeners == null) { failedNotified.putIfAbsent(url, new ConcurrentHashMap>()); @@ -315,7 +315,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { } } - // 重试失败的动作 + // Retry the failed actions protected void retry() { if (!failedRegistered.isEmpty()) { Set failed = new HashSet(failedRegistered); @@ -328,11 +328,11 @@ public abstract class FailbackRegistry extends AbstractRegistry { try { doRegister(url); failedRegistered.remove(url); - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry register " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry register " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } @@ -348,11 +348,11 @@ public abstract class FailbackRegistry extends AbstractRegistry { try { doUnregister(url); failedUnregistered.remove(url); - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry unregister " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry unregister " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } @@ -376,12 +376,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { try { doSubscribe(url, listener); listeners.remove(listener); - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry subscribe " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } } - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry subscribe " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } @@ -405,12 +405,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { try { doUnsubscribe(url, listener); listeners.remove(listener); - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry unsubscribe " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } } - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry unsubscribe " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } @@ -434,12 +434,12 @@ public abstract class FailbackRegistry extends AbstractRegistry { List urls = entry.getValue(); listener.notify(urls); values.remove(listener); - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry notify " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } } - } catch (Throwable t) { // 忽略所有异常,等待下次重试 + } catch (Throwable t) { // Ignore all the exceptions and wait for the next retry logger.warn("Failed to retry notify " + failed + ", waiting for again, cause: " + t.getMessage(), t); } } @@ -469,7 +469,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { } - // ==== 模板方法 ==== + // ==== Template method ==== protected abstract void doRegister(URL url); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderConsumerRegTable.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderConsumerRegTable.java index de5710007b..cd408ca405 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderConsumerRegTable.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderConsumerRegTable.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.dubbo.registry.support; import com.alibaba.dubbo.common.Constants; @@ -11,7 +27,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** - * @author qinliujie * @date 2017/11/23 */ public class ProviderConsumerRegTable { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderInvokerWrapper.java index d4479dfa22..b60fdf5d65 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderInvokerWrapper.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/ProviderInvokerWrapper.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.dubbo.registry.support; import com.alibaba.dubbo.common.URL; @@ -7,7 +23,6 @@ import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcException; /** - * @author qinliujie * @date 2017/11/23 */ public class ProviderInvokerWrapper implements Invoker { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/SkipFailbackWrapperException.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/SkipFailbackWrapperException.java index 212b3c7f8e..836f599d0b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/SkipFailbackWrapperException.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/SkipFailbackWrapperException.java @@ -1,11 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.dubbo.registry.support; /** - * Wrapper异常,用于指示 {@link FailbackRegistry}跳过Failback。 + * Wrapper Exception, it is used to indicate that {@link FailbackRegistry} skips Failback. *

- * NOTE: 期望找到其它更常规的指示方式。 + * NOTE: Expect to find other more conventional ways of instruction. * - * @author ding.lid * @see FailbackRegistry */ public class SkipFailbackWrapperException extends RuntimeException { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceRegistryTest.java index b37b8445c1..013fe1612a 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceRegistryTest.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,7 +28,6 @@ import org.junit.Test; /** * RegistryPerformanceTest * - * @author william.liangf */ public class PerformanceRegistryTest extends TestCase { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceUtils.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceUtils.java index cb4584f468..634fccfc34 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceUtils.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/PerformanceUtils.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,7 +26,6 @@ import java.util.List; /** * PerformanceUtils * - * @author william.liangf */ public class PerformanceUtils { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/RegistryTestSupport.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/RegistryTestSupport.java deleted file mode 100644 index 85c7b78345..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/RegistryTestSupport.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry; - - -/** - * @author ding.lid - */ -public class RegistryTestSupport { - /*public static void assertEqualsIgnoreOrde(Collection expected, Collection actual) { - Set expectedSet; - if (expected instanceof Set) { - expectedSet = (Set) expected; - } else { - expectedSet = new HashSet(expected); - } - - Set actualSet; - if (actual instanceof Set) { - actualSet = (Set) actual; - } else { - actualSet = new HashSet(actual); - } - - Assert.assertEquals(expectedSet, actualSet); - } - - public static final String member_service_name = "com.alibaba.morgan.MemberService"; - - public static final Map member_urls1; - static { - Map m = new HashMap(); - m.put("remote://10.20.130.230:9090/memberService", "version=1.0.0"); - - member_urls1 = Collections.unmodifiableMap(m); - } - - public static final Map member_urls2; - static { - Map m = new HashMap(); - m.put("remote://11.11.11.11:9090/memberService", "version=1.0.0"); - m.put("remote://22.22.22.22:9090/memberService", "version=1.0.0"); - m.put("remote://33.33.33.33:9090/memberService", "version=1.0.0"); - - member_urls2 = Collections.unmodifiableMap(m); - } - - public static final Map member_urls3; - static { - Map m = new HashMap(); - m.put("remote://44.44.44.44:9090/memberService", "version=1.0.0"); - member_urls3 = Collections.unmodifiableMap(m); - } - - public static final String xxx_service_name = "com.alibaba.xxx.XxxService"; - - public static final Map xxx_urls1; - static { - Map m = new HashMap(); - m.put("remote://11.11.11.11:9090/xxxService", "version=1.0.0"); - m.put("remote://22.22.22.22:9090/xxxService", "version=1.0.0"); - - xxx_urls1 = Collections.unmodifiableMap(m); - } - - public static void registerCheck(AbstractRegistry registry) { - { - List registeredList = registry - .getRegistered("com.alibaba.morgan.MemberService"); - assertEquals(0, registeredList.size()); - - Map> registeredMap = registry.getRegistered(); - assertEquals(0, registeredMap.size()); - } - - { - for (Map.Entry entry : member_urls1.entrySet()) { - registry.register(member_service_name, entry.getKey(), entry.getValue()); - } - - Map registered = registry.getRegistered(member_service_name); - assertEquals(1, registered.size()); - assertNotSame(member_urls1, registered); - assertEquals(member_urls1, registered); - - Map> registeredMap = registry.getRegistered(); - assertEquals(1, registeredMap.size()); - assertTrue(registeredMap.containsKey(member_service_name)); - - registered = registeredMap.get(member_service_name); - assertEquals(1, registered.size()); - assertNotSame(member_urls1, registered); - assertEquals(member_urls1, registered); - } - - { - registry.register(member_service_name, member_urls2); - - Map registered = registry.getRegistered(member_service_name); - - final Map urls = new HashMap(); - urls.putAll(member_urls1); - urls.putAll(member_urls2); - - assertEquals(urls, registered); - - Map> registeredMap = registry.getRegistered(); - assertEquals(1, registeredMap.size()); - assertTrue(registeredMap.containsKey(member_service_name)); - - registered = registeredMap.get(member_service_name); - assertEquals(urls, registered); - } - - { - Map> services = new HashMap>(); - services.put(member_service_name, member_urls3); - services.put(xxx_service_name, xxx_urls1); - - registry.register(services); - - final Map urls = new HashMap(); - urls.putAll(member_urls1); - urls.putAll(member_urls2); - urls.putAll(member_urls3); - { - Map registered = registry.getRegistered(member_service_name); - assertEquals(urls, registered); - - registered = registry.getRegistered(xxx_service_name); - assertEquals(xxx_urls1, registered); - } - - { - Map> registeredMap = registry.getRegistered(); - assertEquals(2, registeredMap.size()); - assertTrue(registeredMap.containsKey(member_service_name)); - assertTrue(registeredMap.containsKey(xxx_service_name)); - - Map registered = registeredMap.get(member_service_name); - assertEquals(urls, registered); - - registered = registeredMap.get(xxx_service_name); - assertEquals(xxx_urls1, registered); - } - } - } - - public static void subscribeCheck(AbstractRegistry registry, NotificationListener mockNotifyListener) { - String subscribed = registry.getSubscribed("com.alibaba.morgan.MemberService"); - assertNull(subscribed); - - Map subscribedMap = registry.getSubscribed(); - assertEquals(0, subscribedMap.size()); - - // query允许为null - registry.subscribe("com.alibaba.xxx.XxxService", (String) null, mockNotifyListener); - - subscribed = registry.getSubscribed("com.alibaba.xxx.XxxService"); - assertEquals("", subscribed); - - subscribedMap = registry.getSubscribed(); - assertEquals(1, subscribedMap.size()); - assertTrue(subscribedMap.containsKey("com.alibaba.xxx.XxxService")); - assertEquals("", subscribedMap.get("com.alibaba.xxx.XxxService")); - - registry.subscribe("com.alibaba.empty.EmptyService", "", mockNotifyListener); - - // query允许为空 - subscribed = registry.getSubscribed("com.alibaba.empty.EmptyService"); - assertEquals("", subscribed); - - subscribedMap = registry.getSubscribed(); - assertEquals(2, subscribedMap.size()); - assertTrue(subscribedMap.containsKey("com.alibaba.empty.EmptyService")); - assertEquals("", subscribedMap.get("com.alibaba.empty.EmptyService")); - - // 多项值的Query - registry.subscribe("com.alibaba.morgan.MemberService", "dog=bad,cat=god", - mockNotifyListener); - - subscribed = registry.getSubscribed("com.alibaba.morgan.MemberService"); - assertEquals("dog=bad,cat=god", subscribed); - - subscribedMap = registry.getSubscribed(); - assertEquals(3, subscribedMap.size()); - String s = subscribedMap.get("com.alibaba.morgan.MemberService"); - assertEquals("dog=bad,cat=god", s); - - registry.subscribe("com.alibaba.complex.ComplexService", - "version=1.0.0&application=kylin&methods=findPerson,findVAccount", - mockNotifyListener); - - subscribedMap = registry.getSubscribed(); - assertEquals(4, subscribedMap.size()); - String q = subscribedMap.get("com.alibaba.complex.ComplexService"); - assertEquals("version=1.0.0&application=kylin&methods=findPerson,findVAccount", q); - }*/ - - public void testDummy() { - } -} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java index 797bf36073..eb7f843801 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,7 +30,6 @@ import java.util.List; /** * AbstractRegistryFactoryTest * - * @author william.liangf */ public class AbstractRegistryFactoryTest { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/FailbackRegistryTest.java index 644bf3b50e..0cd475f3be 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/FailbackRegistryTest.java @@ -1,12 +1,13 @@ /* - * Copyright 1999-2101 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,7 +33,7 @@ import java.util.concurrent.atomic.AtomicReference; import static org.junit.Assert.assertEquals; /** - * @author liuchao + * */ public class FailbackRegistryTest { static String service; @@ -55,7 +56,7 @@ public class FailbackRegistryTest { /** * Test method for - * {@link com.alibaba.dubbo.registry.internal.FailbackRegistry#doRetry()}. + * {@link com.alibaba.dubbo.registry.support.FailbackRegistry#retry()}. * * @throws Exception */ @@ -63,7 +64,7 @@ public class FailbackRegistryTest { public void testDoRetry() throws Exception { final AtomicReference notified = new AtomicReference(false); - final CountDownLatch latch = new CountDownLatch(3);//全部共调用3次。成功才会减1. subscribe register的失败尝试不会在做了 + final CountDownLatch latch = new CountDownLatch(3);//All of them are called 3 times. Successful attempts to reduce the failure of 1. subscribe register will not be done again NotifyListener listner = new NotifyListener() { public void notify(List urls) { @@ -77,7 +78,7 @@ public class FailbackRegistryTest { registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); registry.unsubscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); - //失败的情况不能调用到listener. + //Failure can not be called to listener. assertEquals(false, notified.get()); assertEquals(3, latch.getCount()); @@ -92,14 +93,14 @@ public class FailbackRegistryTest { } // Thread.sleep(100000);//for debug assertEquals(0, latch.getCount()); - //unsubscribe时会清除failedsubcribe对应key + //The failedsubcribe corresponding key will be cleared when unsubscribing assertEquals(false, notified.get()); } @Test public void testDoRetry_subscribe() throws Exception { - final CountDownLatch latch = new CountDownLatch(1);//全部共调用4次。成功才会减1. subscribe的失败尝试不会在做了 + final CountDownLatch latch = new CountDownLatch(1);//All of them are called 4 times. A successful attempt to lose 1. subscribe will not be done registry = new MockRegistry(registryUrl, latch); registry.setBad(true); @@ -120,7 +121,7 @@ public class FailbackRegistryTest { public void testDoRetry_register() throws Exception { final AtomicReference notified = new AtomicReference(false); - final CountDownLatch latch = new CountDownLatch(1);//全部共调用4次。成功才会减1. subscribe的失败尝试不会在做了 + final CountDownLatch latch = new CountDownLatch(1);//All of them are called 4 times. A successful attempt to lose 1. subscribe will not be done NotifyListener listner = new NotifyListener() { public void notify(List urls) { @@ -131,7 +132,7 @@ public class FailbackRegistryTest { registry.setBad(true); registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); - //失败的情况不能调用到listener. + //Failure can not be called to listener. assertEquals(false, notified.get()); assertEquals(1, latch.getCount()); @@ -146,20 +147,20 @@ public class FailbackRegistryTest { } // Thread.sleep(100000); assertEquals(0, latch.getCount()); - //unsubscribe时会清除failedsubcribe对应key + //The failedsubcribe corresponding key will be cleared when unsubscribing assertEquals(true, notified.get()); } @Test public void testDoRetry_nofify() throws Exception { - //初始值0 + //Initial value 0 final AtomicInteger count = new AtomicInteger(0); NotifyListener listner = new NotifyListener() { public void notify(List urls) { count.incrementAndGet(); - //第一次抛出异常,看后面是否会再次调用到incrementAndGet + //The exception is thrown for the first time to see if the back will be called again to incrementAndGet if (count.get() == 1l) { throw new RuntimeException("test exception please ignore"); } @@ -168,8 +169,8 @@ public class FailbackRegistryTest { registry = new MockRegistry(registryUrl, new CountDownLatch(0)); registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); - assertEquals(1, count.get()); //确保subscribe调用完成后刚调用过一次count.incrementAndGet - //等定时器. + assertEquals(1, count.get()); //Make sure that the subscribe call has just been called once count.incrementAndGet after the call is completed + //Wait for the timer. for (int i = 0; i < trytimes; i++) { System.out.println("failback notify retry ,times:" + i); if (count.get() == 2) diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/log4j.xml b/dubbo-registry/dubbo-registry-api/src/test/resources/log4j.xml index 323dfe2bd6..71aaa02ef8 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/resources/log4j.xml +++ b/dubbo-registry/dubbo-registry-api/src/test/resources/log4j.xml @@ -1,13 +1,14 @@ - + diff --git a/dubbo-registry/dubbo-registry-multicast/pom.xml b/dubbo-registry/dubbo-registry-multicast/pom.xml index 85cc78175c..e098d181e0 100644 --- a/dubbo-registry/dubbo-registry-multicast/pom.xml +++ b/dubbo-registry/dubbo-registry-multicast/pom.xml @@ -1,12 +1,13 @@