-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
[Dubbo-7367]fix too many instance bean created #7438
Merged
zonghaishang
merged 21 commits into
apache:master
from
70-cloud-lab:210324-fix-7367-step-1
Apr 2, 2021
Merged
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cada543
Update MigrationRule.java
zhangyz-hd 62939a3
Update ReferenceAnnotationBeanPostProcessor.java
zhangyz-hd 94771c9
Update ReferenceAnnotationBeanPostProcessor.java
zhangyz-hd 83eaffc
Update ReferenceAnnotationBeanPostProcessorTest.java
zhangyz-hd 40a341a
Update ReferenceAnnotationBeanPostProcessor.java
zhangyz-hd 1db8fbf
优化generateReferenceBeanName
zhangyz-hd ad4db7b
methods和arguments需要排序
zhangyz-hd 4f285f4
Update ReferenceAnnotationUtils.java
zhangyz-hd 12c658f
update ServiceInstancesChangedListener
zhangyz-hd b54f1b8
Update ServiceInstancesChangedListener.java
zhangyz-hd 78236e0
update generateReferenceBeanName
zhangyz-hd 54908ed
remote println
zhangyz-hd 4c27209
Update ReferenceAnnotationBeanPostProcessor.java
zhangyz-hd 3955586
Update ReferenceAnnotationBeanPostProcessor.java
zhangyz-hd aa95167
Update ReferenceAnnotationBeanPostProcessorTest.java
zhangyz-hd e1ef1e9
update UT
zhangyz-hd b5396e5
revert to use ReferenceAnnotationUtils
zhangyz-hd 8aa2678
使用来自kylixs的convertAttribute方法
zhangyz-hd f14b35e
organize imports & update UT
zhangyz-hd e638eb4
update UT
zhangyz-hd 4eacf5b
update ReferenceAnnotationBeanPostProcessor & UT
zhangyz-hd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
dubbo-common/src/main/java/org/apache/dubbo/config/annotation/ReferenceAnnotationUtils.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,95 @@ | ||
/* | ||
* 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 org.apache.dubbo.config.annotation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ReferenceAnnotationUtils { | ||
public static String generateArrayEntryString(Map.Entry<String, Object> entry) { | ||
String value; | ||
String[] entryValues = (String[]) entry.getValue(); | ||
if ("parameters".equals(entry.getKey())) { | ||
// parameters spec is {key1,value1,key2,value2} | ||
ArrayList<String> kvList = new ArrayList<>(); | ||
for (int i = 0; i < entryValues.length / 2 * 2; i = i + 2) { | ||
kvList.add(entryValues[i] + "=" + entryValues[i + 1]); | ||
} | ||
value = kvList.stream().sorted().collect(Collectors.joining(",", "[", "]")); | ||
} else { | ||
//other spec is {string1,string2,string3} | ||
value = Arrays.stream(entryValues).sorted().collect(Collectors.joining(",", "[", "]")); | ||
} | ||
return value; | ||
} | ||
|
||
public static String generateMethodsString(Method[] methods) { | ||
if (methods.length == 0) { | ||
return null; | ||
} | ||
List<String> methodList = new ArrayList<>(); | ||
for (Method method : methods) { | ||
Map<String, Object> methodMap = new HashMap<>(); | ||
methodMap.put("name", method.name()); | ||
methodMap.put("timeout", method.timeout()); | ||
methodMap.put("retries", method.retries()); | ||
methodMap.put("loadbalance", method.loadbalance()); | ||
methodMap.put("async", method.async()); | ||
methodMap.put("actives", method.actives()); | ||
methodMap.put("executes", method.executes()); | ||
methodMap.put("deprecated", method.deprecated()); | ||
methodMap.put("sticky", method.sticky()); | ||
methodMap.put("isReturn", method.isReturn()); | ||
methodMap.put("oninvoke", method.oninvoke()); | ||
methodMap.put("onreturn", method.onreturn()); | ||
methodMap.put("onthrow", method.onthrow()); | ||
methodMap.put("cache", method.cache()); | ||
methodMap.put("validation", method.validation()); | ||
methodMap.put("merger", method.merger()); | ||
methodMap.put("arguments", generateArgumentsString(method.arguments())); | ||
methodList.add(convertToString(methodMap, "@Method(")); | ||
} | ||
return methodList.stream().sorted().collect(Collectors.joining(",", "[", "]")); | ||
} | ||
|
||
private static String generateArgumentsString(Argument[] arguments) { | ||
if (arguments.length == 0) { | ||
return null; | ||
} | ||
List<String> argumentList = new ArrayList<>(); | ||
for (Argument argument : arguments) { | ||
Map<String, Object> argMap = new HashMap<>(); | ||
argMap.put("index", argument.index()); | ||
argMap.put("type", argument.type()); | ||
argMap.put("callback", argument.callback()); | ||
argumentList.add(convertToString(argMap, "@Argument(")); | ||
} | ||
return argumentList.stream().sorted().collect(Collectors.joining(",", "[", "]")); | ||
} | ||
|
||
private static String convertToString(Map<String, Object> map, String prefix) { | ||
return map.entrySet().stream() | ||
.filter(e -> e.getValue() != null && String.valueOf(e.getValue()).length() > 0) | ||
.map(e -> e.getKey() + "=" + e.getValue()) | ||
.sorted() | ||
.collect(Collectors.joining(",", prefix, ")")); | ||
} | ||
} |
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
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
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
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 |
---|---|---|
|
@@ -61,8 +61,9 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener | |
|
||
private final Set<String> serviceNames; | ||
private final ServiceDiscovery serviceDiscovery; | ||
private final String registryId; | ||
private URL url; | ||
private Map<String, NotifyListener> listeners; | ||
private Map<String, List<NotifyListener>> listeners; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List改成Set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK~ |
||
|
||
private Map<String, List<ServiceInstance>> allInstances; | ||
|
||
|
@@ -73,6 +74,7 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener | |
public ServiceInstancesChangedListener(Set<String> serviceNames, ServiceDiscovery serviceDiscovery) { | ||
this.serviceNames = serviceNames; | ||
this.serviceDiscovery = serviceDiscovery; | ||
this.registryId = serviceDiscovery.getUrl().getParameter("id"); | ||
this.listeners = new HashMap<>(); | ||
this.allInstances = new HashMap<>(); | ||
this.serviceUrls = new HashMap<>(); | ||
|
@@ -188,9 +190,10 @@ private MetadataInfo getMetadataInfo(ServiceInstance instance) { | |
} | ||
|
||
private void notifyAddressChanged() { | ||
listeners.forEach((key, notifyListener) -> { | ||
//FIXME, group wildcard match | ||
notifyListener.notify(toUrlsWithEmpty(serviceUrls.get(key))); | ||
listeners.forEach((key, notifyListeners) -> { | ||
notifyListeners.forEach(notifyListener -> { | ||
notifyListener.notify(toUrlsWithEmpty(serviceUrls.get(key))); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -202,7 +205,7 @@ private List<URL> toUrlsWithEmpty(List<URL> urls) { | |
} | ||
|
||
public void addListener(String serviceKey, NotifyListener listener) { | ||
this.listeners.put(serviceKey, listener); | ||
this.listeners.computeIfAbsent(serviceKey, k -> new ArrayList<>()).add(listener); | ||
} | ||
|
||
public void removeListener(String serviceKey) { | ||
|
@@ -241,6 +244,10 @@ public final boolean accept(ServiceInstancesChangedEvent event) { | |
return serviceNames.contains(event.getServiceName()); | ||
} | ||
|
||
public String getRegistryId() { | ||
return registryId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
@@ -250,11 +257,11 @@ public boolean equals(Object o) { | |
return false; | ||
} | ||
ServiceInstancesChangedListener that = (ServiceInstancesChangedListener) o; | ||
return Objects.equals(getServiceNames(), that.getServiceNames()); | ||
return Objects.equals(getServiceNames(), that.getServiceNames()) && Objects.equals(getRegistryId(), that.getRegistryId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getClass(), getServiceNames()); | ||
return Objects.hash(getClass(), getServiceNames(), getRegistryId()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
release referencedBeanNameIdx resource after app started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK