Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compatible] Registry compatibility #3882 #4015

Merged
merged 12 commits into from
May 17, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class StringUtils {
private static final Pattern INT_PATTERN = Pattern.compile("^\\d+$");
private static final int PAD_LIMIT = 8192;

private StringUtils() {
protected StringUtils() {
cvictory marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.common.utils;

import com.alibaba.dubbo.common.URL;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author cvictory ON 2019-04-17
cvictory marked this conversation as resolved.
Show resolved Hide resolved
*/
@Deprecated
public class UrlUtils {

public static URL parseURL(String address, Map<String, String> defaults) {
return new URL(UrlUtils.parseURL(address, defaults));
chickenlj marked this conversation as resolved.
Show resolved Hide resolved
}

public static List<URL> parseURLs(String address, Map<String, String> defaults) {
return UrlUtils.parseURLs(address, defaults).stream().map(e -> new URL(e)).collect(Collectors.toList());
cvictory marked this conversation as resolved.
Show resolved Hide resolved
}

public static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register) {
return org.apache.dubbo.common.utils.UrlUtils.convertRegister(register);
}

public static Map<String, String> convertSubscribe(Map<String, String> subscribe) {
return org.apache.dubbo.common.utils.UrlUtils.convertSubscribe(subscribe);
}

public static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register) {
return org.apache.dubbo.common.utils.UrlUtils.revertRegister(register);
}

public static Map<String, String> revertSubscribe(Map<String, String> subscribe) {
return org.apache.dubbo.common.utils.UrlUtils.revertSubscribe(subscribe);
}

public static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify) {
return org.apache.dubbo.common.utils.UrlUtils.revertNotify(notify);
}

//compatible for dubbo-2.0.0
public static List<String> revertForbid(List<String> forbid, Set<URL> subscribed) {
Set<org.apache.dubbo.common.URL> urls = subscribed.stream().map(e -> e.getOriginalURL()).collect(Collectors.toSet());
return org.apache.dubbo.common.utils.UrlUtils.revertForbid(forbid, urls);
}

public static URL getEmptyUrl(String service, String category) {
return new URL(org.apache.dubbo.common.utils.UrlUtils.getEmptyUrl(service, category));
}

public static boolean isMatchCategory(String category, String categories) {
return org.apache.dubbo.common.utils.UrlUtils.isMatchCategory(category, categories);
}

public static boolean isMatch(URL consumerUrl, URL providerUrl) {
return org.apache.dubbo.common.utils.UrlUtils.isMatch(consumerUrl.getOriginalURL(), providerUrl.getOriginalURL());
}

public static boolean isMatchGlobPattern(String pattern, String value, URL param) {
return org.apache.dubbo.common.utils.UrlUtils.isMatchGlobPattern(pattern, value, param.getOriginalURL());
}

public static boolean isMatchGlobPattern(String pattern, String value) {
return org.apache.dubbo.common.utils.UrlUtils.isMatchGlobPattern(pattern, value);
}

public static boolean isServiceKeyMatch(URL pattern, URL value) {
return org.apache.dubbo.common.utils.UrlUtils.isServiceKeyMatch(pattern.getOriginalURL(), value.getOriginalURL());
}


public static boolean isConfigurator(URL url) {
return org.apache.dubbo.common.utils.UrlUtils.isConfigurator(url.getOriginalURL());
}

public static boolean isRoute(URL url) {
return org.apache.dubbo.common.utils.UrlUtils.isRoute(url.getOriginalURL());
}

public static boolean isProvider(URL url) {
return org.apache.dubbo.common.utils.UrlUtils.isProvider(url.getOriginalURL());
}

public static int getHeartbeat(URL url) {
return org.apache.dubbo.common.utils.UrlUtils.getHeartbeat(url.getOriginalURL());
}

public static int getIdleTimeout(URL url) {
return org.apache.dubbo.common.utils.UrlUtils.getIdleTimeout(url.getOriginalURL());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ public void notify(List<URL> urls) {
}
}
}

class ReverseCompatibleNotifyListener implements org.apache.dubbo.registry.NotifyListener {

private NotifyListener listener;

public ReverseCompatibleNotifyListener(NotifyListener listener) {
this.listener = listener;
}

@Override
public void notify(List<org.apache.dubbo.common.URL> urls) {
if (listener != null) {
listener.notify(urls.stream().map(url -> new URL(url)).collect(Collectors.toList()));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* 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 org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* 2019-04-16
*/
@Deprecated
public abstract class AbstractRegistry implements Registry {

private CompatibleAbstractRegistry abstractRegistry;

public AbstractRegistry(com.alibaba.dubbo.common.URL url) {
abstractRegistry = new CompatibleAbstractRegistry(url.getOriginalURL());
}

@Override
public com.alibaba.dubbo.common.URL getUrl() {
return new com.alibaba.dubbo.common.URL(abstractRegistry.getUrl());
}

protected void setUrl(com.alibaba.dubbo.common.URL url) {
abstractRegistry.setUrl(url.getOriginalURL());
}

public Set<com.alibaba.dubbo.common.URL> getRegistered() {
return abstractRegistry.getRegistered().stream().map(url -> new com.alibaba.dubbo.common.URL(url)).collect(Collectors.toSet());
}

public Map<com.alibaba.dubbo.common.URL, Set<com.alibaba.dubbo.registry.NotifyListener>> getSubscribed() {
return abstractRegistry.getSubscribed().entrySet()
.stream()
.collect(Collectors.toMap(entry -> new com.alibaba.dubbo.common.URL(entry.getKey()),
entry -> convertToNotifyListeners(entry.getValue())));
}

public Map<com.alibaba.dubbo.common.URL, Map<String, List<com.alibaba.dubbo.common.URL>>> getNotified() {
return abstractRegistry.getNotified().entrySet().stream()
.collect(Collectors.toMap(entry -> new com.alibaba.dubbo.common.URL(entry.getKey()),
entry -> {
return entry.getValue().entrySet()
.stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> {
return e.getValue().stream().map(url -> new com.alibaba.dubbo.common.URL(url)).collect(Collectors.toList());
}));
}));
}


public List<com.alibaba.dubbo.common.URL> getCacheUrls(com.alibaba.dubbo.common.URL url) {
return abstractRegistry.lookup(url.getOriginalURL()).stream().map(tmpUrl -> new com.alibaba.dubbo.common.URL(tmpUrl)).collect(Collectors.toList());
}

public List<com.alibaba.dubbo.common.URL> lookup(com.alibaba.dubbo.common.URL url) {
return abstractRegistry.lookup(url.getOriginalURL()).stream().map(tmpUrl -> new com.alibaba.dubbo.common.URL(tmpUrl)).collect(Collectors.toList());
}

protected void notify(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener, List<com.alibaba.dubbo.common.URL> urls) {
abstractRegistry.notify(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener), urls.stream().map(tmpUrl -> tmpUrl.getOriginalURL()).collect(Collectors.toList()));
}

public void register(com.alibaba.dubbo.common.URL url) {
abstractRegistry.register(url.getOriginalURL());
}

public void unregister(com.alibaba.dubbo.common.URL url) {
abstractRegistry.unregister(url.getOriginalURL());
}

public void subscribe(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener) {
abstractRegistry.subscribe(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener));
}

public void unsubscribe(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener) {
abstractRegistry.unsubscribe(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener));
}


@Override
public void register(URL url) {
this.register(new com.alibaba.dubbo.common.URL(url));
}

@Override
public void unregister(URL url) {
this.unregister(new com.alibaba.dubbo.common.URL(url));
}

@Override
public void subscribe(URL url, NotifyListener listener) {
this.subscribe(new com.alibaba.dubbo.common.URL(url), new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener));
}

@Override
public void unsubscribe(URL url, NotifyListener listener) {
this.unsubscribe(new com.alibaba.dubbo.common.URL(url), new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener));
}

final Set<com.alibaba.dubbo.registry.NotifyListener> convertToNotifyListeners(Set<NotifyListener> notifyListeners) {
return notifyListeners.stream().map(listener -> new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener)).collect(Collectors.toSet());
}


static class CompatibleAbstractRegistry extends org.apache.dubbo.registry.support.AbstractRegistry {
public CompatibleAbstractRegistry(URL url) {
super(url);
}

@Override
public boolean isAvailable() {
return false;
}

public void notify(URL url, NotifyListener listener, List<URL> urls) {
super.notify(url, listener, urls);
}

public void setUrl(URL url) {
super.setUrl(url);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.Registry;

/**
* 2019-04-16
*/
@Deprecated
public abstract class AbstractRegistryFactory extends org.apache.dubbo.registry.support.AbstractRegistryFactory {


protected abstract com.alibaba.dubbo.registry.Registry createRegistry(com.alibaba.dubbo.common.URL url);

protected Registry createRegistry(URL url) {
return createRegistry(new com.alibaba.dubbo.common.URL(url));
}
}
Loading