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

Fix telnet list unordered #14250

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.apache.dubbo.rpc.model.ServiceRepository;

import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
* ListTelnetHandler handler list services and its methods details.
Expand Down Expand Up @@ -86,6 +88,9 @@ private void printAllProvidedServices(StringBuilder buf, boolean detail) {
List<ProviderModel> providerModels = serviceRepository.getExportedServices();
if (!providerModels.isEmpty()) {
buf.append("PROVIDER:\r\n");

// fix: Fix: Originally, providers were stored in ConcurrentHashMap, Disordered display of servicekey list
providerModels = providerModels.stream().sorted(Comparator.comparing(ProviderModel::getServiceKey)).collect(Collectors.toList());
}

for (ProviderModel provider : providerModels) {
Expand All @@ -103,6 +108,9 @@ private void printAllReferredServices(StringBuilder buf, boolean detail) {
List<ConsumerModel> consumerModels = serviceRepository.getReferredServices();
if (!consumerModels.isEmpty()) {
buf.append("CONSUMER:\r\n");

// fix: Fix: Originally, consumers were stored in ConcurrentHashMap, Disordered display of servicekey list
consumerModels = consumerModels.stream().sorted(Comparator.comparing(ConsumerModel::getServiceKey)).collect(Collectors.toList());
}

for (ConsumerModel consumer : consumerModels) {
Expand All @@ -123,7 +131,7 @@ private void printSpecifiedService(String service, StringBuilder buf, boolean de

private void printSpecifiedProvidedService(String service, StringBuilder buf, boolean detail) {
for (ProviderModel provider : ApplicationModel.allProviderModels()) {
if (isProviderMatched(service,provider)) {
if (isProviderMatched(service, provider)) {
buf.append(provider.getServiceKey()).append(" (as provider):\r\n");
for (MethodDescriptor method : provider.getAllMethods()) {
printMethod(method.getMethod(), buf, detail);
Expand All @@ -134,7 +142,7 @@ private void printSpecifiedProvidedService(String service, StringBuilder buf, bo

private void printSpecifiedReferredService(String service, StringBuilder buf, boolean detail) {
for (ConsumerModel consumer : ApplicationModel.allConsumerModels()) {
if (isConsumerMatcher(service,consumer)) {
if (isConsumerMatcher(service, consumer)) {
buf.append(consumer.getServiceKey()).append(" (as consumer):\r\n");
for (MethodDescriptor method : consumer.getAllMethods()) {
printMethod(method.getMethod(), buf, detail);
Expand All @@ -158,7 +166,7 @@ private boolean isProviderMatched(String service, ProviderModel provider) {
|| service.equalsIgnoreCase(provider.getServiceInterfaceClass().getSimpleName());
}

private boolean isConsumerMatcher(String service,ConsumerModel consumer) {
private boolean isConsumerMatcher(String service, ConsumerModel consumer) {
return service.equalsIgnoreCase(consumer.getServiceKey())
|| service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getName())
|| service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getSimpleName());
Expand Down
Loading