|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package com.alibaba.dubbo.registry.support; |
| 18 | + |
| 19 | +import org.apache.dubbo.common.URL; |
| 20 | +import org.apache.dubbo.registry.NotifyListener; |
| 21 | +import org.apache.dubbo.registry.Registry; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | +import java.util.Set; |
| 26 | +import java.util.stream.Collectors; |
| 27 | + |
| 28 | +/** |
| 29 | + * 2019-04-16 |
| 30 | + */ |
| 31 | +@Deprecated |
| 32 | +public abstract class AbstractRegistry implements Registry { |
| 33 | + |
| 34 | + private CompatibleAbstractRegistry abstractRegistry; |
| 35 | + |
| 36 | + public AbstractRegistry(com.alibaba.dubbo.common.URL url) { |
| 37 | + abstractRegistry = new CompatibleAbstractRegistry(url.getOriginalURL()); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public com.alibaba.dubbo.common.URL getUrl() { |
| 42 | + return new com.alibaba.dubbo.common.URL(abstractRegistry.getUrl()); |
| 43 | + } |
| 44 | + |
| 45 | + protected void setUrl(com.alibaba.dubbo.common.URL url) { |
| 46 | + abstractRegistry.setUrl(url.getOriginalURL()); |
| 47 | + } |
| 48 | + |
| 49 | + public Set<com.alibaba.dubbo.common.URL> getRegistered() { |
| 50 | + return abstractRegistry.getRegistered().stream().map(url -> new com.alibaba.dubbo.common.URL(url)).collect(Collectors.toSet()); |
| 51 | + } |
| 52 | + |
| 53 | + public Map<com.alibaba.dubbo.common.URL, Set<com.alibaba.dubbo.registry.NotifyListener>> getSubscribed() { |
| 54 | + return abstractRegistry.getSubscribed().entrySet() |
| 55 | + .stream() |
| 56 | + .collect(Collectors.toMap(entry -> new com.alibaba.dubbo.common.URL(entry.getKey()), |
| 57 | + entry -> convertToNotifyListeners(entry.getValue()))); |
| 58 | + } |
| 59 | + |
| 60 | + public Map<com.alibaba.dubbo.common.URL, Map<String, List<com.alibaba.dubbo.common.URL>>> getNotified() { |
| 61 | + return abstractRegistry.getNotified().entrySet().stream() |
| 62 | + .collect(Collectors.toMap(entry -> new com.alibaba.dubbo.common.URL(entry.getKey()), |
| 63 | + entry -> { |
| 64 | + return entry.getValue().entrySet() |
| 65 | + .stream() |
| 66 | + .collect(Collectors.toMap(e -> e.getKey(), e -> { |
| 67 | + return e.getValue().stream().map(url -> new com.alibaba.dubbo.common.URL(url)).collect(Collectors.toList()); |
| 68 | + })); |
| 69 | + })); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + public List<com.alibaba.dubbo.common.URL> getCacheUrls(com.alibaba.dubbo.common.URL url) { |
| 74 | + return abstractRegistry.lookup(url.getOriginalURL()).stream().map(tmpUrl -> new com.alibaba.dubbo.common.URL(tmpUrl)).collect(Collectors.toList()); |
| 75 | + } |
| 76 | + |
| 77 | + public List<com.alibaba.dubbo.common.URL> lookup(com.alibaba.dubbo.common.URL url) { |
| 78 | + return abstractRegistry.lookup(url.getOriginalURL()).stream().map(tmpUrl -> new com.alibaba.dubbo.common.URL(tmpUrl)).collect(Collectors.toList()); |
| 79 | + } |
| 80 | + |
| 81 | + protected void notify(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener, List<com.alibaba.dubbo.common.URL> urls) { |
| 82 | + abstractRegistry.notify(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener), urls.stream().map(tmpUrl -> tmpUrl.getOriginalURL()).collect(Collectors.toList())); |
| 83 | + } |
| 84 | + |
| 85 | + public void register(com.alibaba.dubbo.common.URL url) { |
| 86 | + abstractRegistry.register(url.getOriginalURL()); |
| 87 | + } |
| 88 | + |
| 89 | + public void unregister(com.alibaba.dubbo.common.URL url) { |
| 90 | + abstractRegistry.unregister(url.getOriginalURL()); |
| 91 | + } |
| 92 | + |
| 93 | + public void subscribe(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener) { |
| 94 | + abstractRegistry.subscribe(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener)); |
| 95 | + } |
| 96 | + |
| 97 | + public void unsubscribe(com.alibaba.dubbo.common.URL url, com.alibaba.dubbo.registry.NotifyListener listener) { |
| 98 | + abstractRegistry.unsubscribe(url.getOriginalURL(), new com.alibaba.dubbo.registry.NotifyListener.ReverseCompatibleNotifyListener(listener)); |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | + @Override |
| 103 | + public void register(URL url) { |
| 104 | + this.register(new com.alibaba.dubbo.common.URL(url)); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public void unregister(URL url) { |
| 109 | + this.unregister(new com.alibaba.dubbo.common.URL(url)); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public void subscribe(URL url, NotifyListener listener) { |
| 114 | + this.subscribe(new com.alibaba.dubbo.common.URL(url), new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener)); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void unsubscribe(URL url, NotifyListener listener) { |
| 119 | + this.unsubscribe(new com.alibaba.dubbo.common.URL(url), new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener)); |
| 120 | + } |
| 121 | + |
| 122 | + final Set<com.alibaba.dubbo.registry.NotifyListener> convertToNotifyListeners(Set<NotifyListener> notifyListeners) { |
| 123 | + return notifyListeners.stream().map(listener -> new com.alibaba.dubbo.registry.NotifyListener.CompatibleNotifyListener(listener)).collect(Collectors.toSet()); |
| 124 | + } |
| 125 | + |
| 126 | + |
| 127 | + static class CompatibleAbstractRegistry extends org.apache.dubbo.registry.support.AbstractRegistry { |
| 128 | + public CompatibleAbstractRegistry(URL url) { |
| 129 | + super(url); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public boolean isAvailable() { |
| 134 | + return false; |
| 135 | + } |
| 136 | + |
| 137 | + public void notify(URL url, NotifyListener listener, List<URL> urls) { |
| 138 | + super.notify(url, listener, urls); |
| 139 | + } |
| 140 | + |
| 141 | + public void setUrl(URL url) { |
| 142 | + super.setUrl(url); |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments