Skip to content

Commit

Permalink
Extract constants in RegistryProtocol (#7727)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoheng1 committed May 11, 2021
1 parent 200f06e commit e845e16
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public class RegistryProtocol implements Protocol {
APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY
};

private final static String REGISTRY_PROTOCOL_LISTENER_KEY = "registry.protocol.listener";
private final static int DEFAULT_PORT = 9090;

private final static Logger LOGGER = LoggerFactory.getLogger(RegistryProtocol.class);
private final Map<URL, NotifyListener> overrideListeners = new ConcurrentHashMap<>();
private final Map<String, ServiceConfigurationListener> serviceConfigurationListeners = new ConcurrentHashMap<>();
Expand All @@ -143,7 +146,9 @@ public class RegistryProtocol implements Protocol {
protected ProxyFactory proxyFactory;

private ConcurrentMap<URL, ReExportTask> reExportFailedTasks = new ConcurrentHashMap<>();
private HashedWheelTimer retryTimer = new HashedWheelTimer(new NamedThreadFactory("DubboReexportTimer", true), DEFAULT_REGISTRY_RETRY_PERIOD, TimeUnit.MILLISECONDS, 128);
private HashedWheelTimer retryTimer =
new HashedWheelTimer(new NamedThreadFactory("DubboReexportTimer", true), DEFAULT_REGISTRY_RETRY_PERIOD, TimeUnit.MILLISECONDS,
128);

// get the parameters which shouldn't been displayed in url string(Starting with .)
private static String[] getHiddenKeys(URL url) {
Expand Down Expand Up @@ -171,7 +176,7 @@ public void setProxyFactory(ProxyFactory proxyFactory) {

@Override
public int getDefaultPort() {
return 9090;
return DEFAULT_PORT;
}

public Map<URL, NotifyListener> getOverrideListeners() {
Expand Down Expand Up @@ -231,7 +236,7 @@ public <T> Exporter<T> export(final Invoker<T> originInvoker) throws RpcExceptio

private <T> void notifyExport(ExporterChangeableWrapper<T> exporter) {
List<RegistryProtocolListener> listeners = ExtensionLoader.getExtensionLoader(RegistryProtocolListener.class)
.getActivateExtension(exporter.getOriginInvoker().getUrl(), "registry.protocol.listener");
.getActivateExtension(exporter.getOriginInvoker().getUrl(), REGISTRY_PROTOCOL_LISTENER_KEY);
if (CollectionUtils.isNotEmpty(listeners)) {
for (RegistryProtocolListener listener : listeners) {
listener.onExport(this, exporter);
Expand Down Expand Up @@ -301,7 +306,8 @@ public <T> void reExport(final Invoker<T> originInvoker, URL newInvokerUrl) {
oldTask = reExportFailedTasks.putIfAbsent(registeredUrl, task);
if (oldTask == null) {
// never has a retry task. then start a new task for retry.
retryTimer.newTimeout(task, registryUrl.getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD), TimeUnit.MILLISECONDS);
retryTimer.newTimeout(task, registryUrl.getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD),
TimeUnit.MILLISECONDS);
}
}
}
Expand Down Expand Up @@ -476,7 +482,8 @@ protected <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> ty
return interceptInvoker(migrationInvoker, url, consumerUrl);
}

protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url, URL consumerUrl) {
protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry,
Class<T> type, URL url, URL consumerUrl) {
return new ServiceDiscoveryMigrationInvoker<T>(registryProtocol, cluster, registry, type, url, consumerUrl);
}

Expand Down Expand Up @@ -535,7 +542,7 @@ public static URL toSubscribeUrl(URL url) {

protected List<RegistryProtocolListener> findRegistryProtocolListeners(URL url) {
return ExtensionLoader.getExtensionLoader(RegistryProtocolListener.class)
.getActivateExtension(url, "registry.protocol.listener");
.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY);
}

// available to test
Expand Down

0 comments on commit e845e16

Please sign in to comment.