|
20 | 20 | import org.apache.dubbo.common.URL; |
21 | 21 | import org.apache.dubbo.common.logger.Logger; |
22 | 22 | import org.apache.dubbo.common.logger.LoggerFactory; |
| 23 | +import org.apache.dubbo.common.utils.CollectionUtils; |
23 | 24 | import org.apache.dubbo.common.utils.ConcurrentHashSet; |
24 | 25 | import org.apache.dubbo.common.utils.ExecutorUtil; |
25 | 26 | import org.apache.dubbo.common.utils.NamedThreadFactory; |
26 | 27 | import org.apache.dubbo.common.utils.NetUtils; |
27 | 28 | import org.apache.dubbo.common.utils.UrlUtils; |
28 | | -import org.apache.dubbo.common.utils.CollectionUtils; |
29 | 29 | import org.apache.dubbo.registry.NotifyListener; |
30 | 30 | import org.apache.dubbo.registry.support.FailbackRegistry; |
31 | 31 |
|
@@ -82,13 +82,11 @@ public MulticastRegistry(URL url) { |
82 | 82 | try { |
83 | 83 | multicastAddress = InetAddress.getByName(url.getHost()); |
84 | 84 | if (!multicastAddress.isMulticastAddress()) { |
85 | | - throw new IllegalArgumentException("Invalid multicast address " + url.getHost() + |
86 | | - ", ipv4 multicast address scope: 224.0.0.0 - 239.255.255.255."); |
| 85 | + throw new IllegalArgumentException("Invalid multicast address " + url.getHost() + ", ipv4 multicast address scope: 224.0.0.0 - 239.255.255.255."); |
87 | 86 | } |
88 | 87 | multicastPort = url.getPort() <= 0 ? DEFAULT_MULTICAST_PORT : url.getPort(); |
89 | 88 | multicastSocket = new MulticastSocket(multicastPort); |
90 | | - multicastSocket.setLoopbackMode(false); |
91 | | - multicastSocket.joinGroup(multicastAddress); |
| 89 | + NetUtils.joinMulticastGroup(multicastSocket, multicastAddress); |
92 | 90 | Thread thread = new Thread(new Runnable() { |
93 | 91 | @Override |
94 | 92 | public void run() { |
@@ -153,11 +151,7 @@ private void clean() { |
153 | 151 | } |
154 | 152 |
|
155 | 153 | private boolean isExpired(URL url) { |
156 | | - if (!url.getParameter(Constants.DYNAMIC_KEY, true) |
157 | | - || url.getPort() <= 0 |
158 | | - || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()) |
159 | | - || Constants.ROUTE_PROTOCOL.equals(url.getProtocol()) |
160 | | - || Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) { |
| 154 | + if (!url.getParameter(Constants.DYNAMIC_KEY, true) || url.getPort() <= 0 || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()) || Constants.ROUTE_PROTOCOL.equals(url.getProtocol()) || Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) { |
161 | 155 | return false; |
162 | 156 | } |
163 | 157 | Socket socket = null; |
@@ -208,8 +202,7 @@ private void receive(String msg, InetSocketAddress remoteAddress) { |
208 | 202 | if (CollectionUtils.isNotEmpty(urls)) { |
209 | 203 | for (URL u : urls) { |
210 | 204 | if (UrlUtils.isMatch(url, u)) { |
211 | | - String host = remoteAddress != null && remoteAddress.getAddress() != null |
212 | | - ? remoteAddress.getAddress().getHostAddress() : url.getIp(); |
| 205 | + String host = remoteAddress != null && remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : url.getIp(); |
213 | 206 | if (url.getParameter("unicast", true) // Whether the consumer's machine has only one process |
214 | 207 | && !NetUtils.getLocalHost().equals(host)) { // Multiple processes in the same machine cannot be unicast with unicast or there will be only one process receiving information |
215 | 208 | unicast(Constants.REGISTER + " " + u.toFullString(), host); |
@@ -275,8 +268,7 @@ public void doSubscribe(URL url, NotifyListener listener) { |
275 | 268 |
|
276 | 269 | @Override |
277 | 270 | public void doUnsubscribe(URL url, NotifyListener listener) { |
278 | | - if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) |
279 | | - && url.getParameter(Constants.REGISTER_KEY, true)) { |
| 271 | + if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { |
280 | 272 | unregister(url); |
281 | 273 | } |
282 | 274 | multicast(Constants.UNSUBSCRIBE + " " + url.toFullString()); |
|
0 commit comments