![JAR search and dependency download from the Maven repository](/logo.png)
com.alibaba.dubbo.monitor.simple.pages.DependenciesPageHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dubbo2-monitor-simple Show documentation
Show all versions of dubbo2-monitor-simple Show documentation
The simple monitor module of dubbo project
The newest version!
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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 com.alibaba.dubbo.monitor.simple.pages;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.monitor.simple.RegistryContainer;
/**
* DependenciesPageHandler
*
* @author william.liangf
*/
public class DependenciesPageHandler implements PageHandler {
public Page handle(URL url) {
String application = url.getParameter("application");
if (application == null || application.length() == 0) {
throw new IllegalArgumentException("Please input application parameter.");
}
boolean reverse = url.getParameter("reverse", false);
List> rows = new ArrayList>();
Set directly = RegistryContainer.getInstance().getDependencies(application, reverse);
Set indirectly = new HashSet();
appendDependency(rows, reverse, application, 0, new HashSet(), indirectly);
indirectly.remove(application);
return new Page("Applications > " + application +
" > Providers | Consumers | " +
(reverse ? "Depends On | Used By"
: "Depends On | Used By"), (reverse ? "Used By" : "Depends On") + " (" + directly.size() + "/" + indirectly.size() + ")", new String[] { "Application Name:"}, rows);
}
private void appendDependency(List> rows, boolean reverse, String application, int level, Set appended, Set indirectly) {
List row = new ArrayList();
StringBuilder buf = new StringBuilder();
if (level > 0) {
for (int i = 0; i < level; i ++) {
buf.append(" |");
}
buf.append(reverse ? "<-- " : "--> ");
}
boolean end = false;
if (level > 5) {
buf.append(" More...");
end = true;
} else {
buf.append(application);
if (appended.contains(application)) {
buf.append(" (Cycle)");
end = true;
}
}
row.add(buf.toString());
rows.add(row);
if (end) {
return;
}
appended.add(application);
indirectly.add(application);
Set dependencies = RegistryContainer.getInstance().getDependencies(application, reverse);
if (dependencies != null && dependencies.size() > 0) {
for (String dependency : dependencies) {
appendDependency(rows, reverse, dependency, level + 1, appended, indirectly);
}
}
appended.remove(application);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy