forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compatible with Regigistry. apache#3882
- Loading branch information
Showing
7 changed files
with
463 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
dubbo-compatible/src/main/java/com/alibaba/dubbo/common/utils/UrlUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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 | ||
*/ | ||
public class UrlUtils { | ||
|
||
public static URL parseURL(String address, Map<String, String> defaults) { | ||
return new URL(UrlUtils.parseURL(address, defaults)); | ||
} | ||
|
||
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()); | ||
} | ||
|
||
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
dubbo-compatible/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
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); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-compatible/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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)); | ||
} | ||
} |
Oops, something went wrong.