Remove classes related with "dubbo-monitor"

This commit is contained in:
ken.lj 2018-01-11 17:36:24 +08:00
parent da3783e3cd
commit e62d3ff805
22 changed files with 0 additions and 1542 deletions

View File

@ -1,39 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Menu
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Menu {
String name();
String desc() default "";
int order() default 0;
}

View File

@ -1,43 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import java.io.Serializable;
import java.util.Comparator;
/**
* MenuComparator
*/
public class MenuComparator implements Comparator<PageHandler>, Serializable {
private static final long serialVersionUID = -3161526932904414029L;
public int compare(PageHandler o1, PageHandler o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
return o1.equals(o2) ? 0 : (o1.getClass().getAnnotation(Menu.class).order()
> o2.getClass().getAnnotation(Menu.class).order() ? 1 : -1);
}
}

View File

@ -1,82 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Page
*/
public class Page {
private final String navigation;
private final String title;
private final List<String> columns;
private final List<List<String>> rows;
public Page(String navigation) {
this(navigation, (String) null, (String[]) null, (List<List<String>>) null);
}
public Page(String navigation, String title,
String column, String row) {
this(navigation, title, column == null ? null : Arrays.asList(new String[]{column}), row == null ? null : stringToList(row));
}
public Page(String navigation, String title,
String[] columns, List<List<String>> rows) {
this(navigation, title, columns == null ? null : Arrays.asList(columns), rows);
}
public Page(String navigation, String title,
List<String> columns, List<List<String>> rows) {
this.navigation = navigation;
this.title = title;
this.columns = columns;
this.rows = rows;
}
private static List<List<String>> stringToList(String str) {
List<List<String>> rows = new ArrayList<List<String>>();
List<String> row = new ArrayList<String>();
row.add(str);
rows.add(row);
return rows;
}
public String getNavigation() {
return navigation;
}
public String getTitle() {
return title;
}
public List<String> getColumns() {
return columns;
}
public List<List<String>> getRows() {
return rows;
}
}

View File

@ -1,36 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.SPI;
/**
* PageHandler
*/
@SPI
public interface PageHandler {
/**
* Handle the page.
*
* @param url
* @return the page.
*/
Page handle(URL url);
}

View File

@ -1,279 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.StringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
/**
* PageServlet
*/
public class PageServlet extends HttpServlet {
protected static final Logger logger = LoggerFactory.getLogger(PageServlet.class);
private static final long serialVersionUID = -8370312705453328501L;
private static PageServlet INSTANCE;
protected final Random random = new Random();
protected final Map<String, PageHandler> pages = new ConcurrentHashMap<String, PageHandler>();
protected final List<PageHandler> menus = new ArrayList<PageHandler>();
public static PageServlet getInstance() {
return INSTANCE;
}
public List<PageHandler> getMenus() {
return Collections.unmodifiableList(menus);
}
@Override
public void init() throws ServletException {
super.init();
INSTANCE = this;
String config = getServletConfig().getInitParameter("pages");
Collection<String> names;
if (config != null && config.length() > 0) {
names = Arrays.asList(Constants.COMMA_SPLIT_PATTERN.split(config));
} else {
names = ExtensionLoader.getExtensionLoader(PageHandler.class).getSupportedExtensions();
}
for (String name : names) {
PageHandler handler = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtension(name);
pages.put(ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler), handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
if (menu != null) {
menus.add(handler);
}
}
Collections.sort(menus, new MenuComparator());
}
@Override
protected final void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected final void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!response.isCommitted()) {
PrintWriter writer = response.getWriter();
String uri = request.getRequestURI();
boolean isHtml = false;
if (uri == null || uri.length() == 0 || "/".equals(uri)) {
uri = "index";
isHtml = true;
} else {
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
if (uri.endsWith(".html")) {
uri = uri.substring(0, uri.length() - ".html".length());
isHtml = true;
}
}
if (uri.endsWith("favicon.ico")) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ExtensionLoader<PageHandler> pageHandlerLoader = ExtensionLoader.getExtensionLoader(PageHandler.class);
PageHandler pageHandler = pageHandlerLoader.hasExtension(uri) ? pageHandlerLoader.getExtension(uri) : null;
if (isHtml) {
writer.println("<html><head><title>Dubbo</title>");
writer.println("<style type=\"text/css\">html, body {margin: 10;padding: 0;background-color: #6D838C;font-family: Arial, Verdana;font-size: 12px;color: #FFFFFF;text-align: center;vertical-align: middle;word-break: break-all; } table {width: 90%; margin: 0px auto;border-collapse: collapse;border: 8px solid #FFFFFF; } thead tr {background-color: #253c46; } tbody tr {background-color: #8da5af; } th {padding-top: 4px;padding-bottom: 4px;font-size: 14px;height: 20px; } td {margin: 3px;padding: 3px;border: 2px solid #FFFFFF;font-size: 14px;height: 25px; } a {color: #FFFFFF;cursor: pointer;text-decoration: underline; } a:hover {text-decoration: none; }</style>");
writer.println("</head><body>");
}
if (pageHandler != null) {
Page page = null;
try {
String query = request.getQueryString();
page = pageHandler.handle(URL.valueOf(request.getRequestURL().toString()
+ (query == null || query.length() == 0 ? "" : "?" + query)));
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
String msg = t.getMessage();
if (msg == null) {
msg = StringUtils.toString(t);
}
if (isHtml) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th>Error</th>");
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td>");
writer.println(" " + msg.replace("<", "&lt;").replace(">", "&lt;").replace("\n", "<br/>"));
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
} else {
writer.println(msg);
}
}
if (page != null) {
if (isHtml) {
String nav = page.getNavigation();
if (nav == null || nav.length() == 0) {
nav = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(pageHandler);
nav = nav.substring(0, 1).toUpperCase() + nav.substring(1);
}
if (!"index".equals(uri)) {
nav = "<a href=\"/\">Home</a> &gt; " + nav;
}
writeMenu(request, writer, nav);
writeTable(writer, page.getTitle(), page.getColumns(),
page.getRows());
} else {
if (page.getRows().size() > 0 && page.getRows().get(0).size() > 0) {
writer.println(page.getRows().get(0).get(0));
}
}
}
} else {
if (isHtml) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th>Error</th>");
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td>");
writer.println(" Not found " + uri + " page. Please goto <a href=\"/\">Home</a> page.");
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
} else {
writer.println("Not found " + uri + " page.");
}
}
if (isHtml) {
writer.println("</body></html>");
}
writer.flush();
}
}
protected final void writeMenu(HttpServletRequest request, PrintWriter writer, String nav) {
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
for (PageHandler handler : menus) {
String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
writer.println(" <th><a href=\"" + uri + ".html\">" + menu.name() + "</a></th>");
}
writer.println(" </tr>");
writer.println("</thead>");
writer.println("<tbody>");
writer.println(" <tr>");
writer.println(" <td style=\"text-align: left\" colspan=\"" + menus.size() + "\">");
writer.println(nav);
writer.println(" </td>");
writer.println(" </tr>");
writer.println("</tbody>");
writer.println("</table>");
writer.println("<br/>");
}
protected final void writeTable(PrintWriter writer, String title, List<String> columns,
List<List<String>> rows) {
int n = random.nextInt();
int c = (columns == null ? (rows == null || rows.size() == 0 ? 0 : rows.get(0).size())
: columns.size());
int r = (rows == null ? 0 : rows.size());
writer.println("<table>");
writer.println("<thead>");
writer.println(" <tr>");
writer.println(" <th colspan=\"" + c + "\">" + title + "</th>");
writer.println(" </tr>");
if (columns != null && columns.size() > 0) {
writer.println(" <tr>");
for (int i = 0; i < columns.size(); i++) {
String col = columns.get(i);
if (col.endsWith(":")) {
col += " <input type=\"text\" id=\"in_"
+ n
+ "_"
+ i
+ "\" onkeyup=\"for (var i = 0; i < "
+ r
+ "; i ++) { var m = true; for (var j = 0; j < "
+ columns.size()
+ "; j ++) { if (document.getElementById('in_"
+ n
+ "_' + j)) { var iv = document.getElementById('in_"
+ n
+ "_' + j).value; var tv = document.getElementById('td_"
+ n
+ "_' + i + '_' + j).innerHTML; if (iv.length > 0 && (tv.length < iv.length || tv.indexOf(iv) == -1)) { m = false; break; } } } document.getElementById('tr_"
+ n
+ "_' + i).style.display = (m ? '' : 'none');}\" sytle=\"width: 100%\" />";
}
writer.println(" <td>" + col + "</td>");
}
writer.println(" </tr>");
}
writer.println("</thead>");
if (rows != null && rows.size() > 0) {
writer.println("<tbody>");
int i = 0;
for (Collection<String> row : rows) {
writer.println(" <tr id=\"tr_" + n + "_" + i + "\">");
int j = 0;
for (String col : row) {
writer.println(" <td id=\"td_" + n + "_" + i + "_" + j
+ "\" style=\"display: ;\">" + col + "</td>");
j++;
}
writer.println(" </tr>");
i++;
}
writer.println("</tbody>");
}
writer.println("</table>");
writer.println("<br/>");
}
}

View File

@ -1,151 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page;
import com.alibaba.dubbo.common.Constants;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* ResourceServlet
*/
public class ResourceFilter implements Filter {
private static final String CLASSPATH_PREFIX = "classpath:";
private final long start = System.currentTimeMillis();
private final List<String> resources = new ArrayList<String>();
public void init(FilterConfig filterConfig) throws ServletException {
String config = filterConfig.getInitParameter("resources");
if (config != null && config.length() > 0) {
String[] configs = Constants.COMMA_SPLIT_PATTERN.split(config);
for (String c : configs) {
if (c != null && c.length() > 0) {
c = c.replace('\\', '/');
if (c.endsWith("/")) {
c = c.substring(0, c.length() - 1);
}
resources.add(c);
}
}
}
}
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
if (response.isCommitted()) {
return;
}
String uri = request.getRequestURI();
String context = request.getContextPath();
if (uri.endsWith("/favicon.ico")) {
uri = "/favicon.ico";
} else if (context != null && !"/".equals(context)) {
uri = uri.substring(context.length());
}
if (!uri.startsWith("/")) {
uri = "/" + uri;
}
long lastModified = getLastModified(uri);
long since = request.getDateHeader("If-Modified-Since");
if (since >= lastModified) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
byte[] data;
InputStream input = getInputStream(uri);
if (input == null) {
chain.doFilter(req, res);
return;
}
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
data = output.toByteArray();
} finally {
input.close();
}
response.setDateHeader("Last-Modified", lastModified);
OutputStream output = response.getOutputStream();
output.write(data);
output.flush();
}
private boolean isFile(String path) {
return path.startsWith("/") || path.indexOf(":") <= 1;
}
private long getLastModified(String uri) {
for (String resource : resources) {
if (resource != null && resource.length() > 0) {
String path = resource + uri;
if (isFile(path)) {
File file = new File(path);
if (file.exists()) {
return file.lastModified();
}
}
}
}
return start;
}
private InputStream getInputStream(String uri) {
for (String resource : resources) {
String path = resource + uri;
try {
if (isFile(path)) {
return new FileInputStream(path);
} else if (path.startsWith(CLASSPATH_PREFIX)) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(path.substring(CLASSPATH_PREFIX.length()));
} else {
return new URL(path).openStream();
}
} catch (IOException e) {
}
}
return null;
}
}

View File

@ -1,48 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.container.page.PageServlet;
import java.util.ArrayList;
import java.util.List;
/**
* HomePageHandler
*/
@Menu(name = "Home", desc = "Home page.", order = Integer.MIN_VALUE)
public class HomePageHandler implements PageHandler {
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
for (PageHandler handler : PageServlet.getInstance().getMenus()) {
String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
Menu menu = handler.getClass().getAnnotation(Menu.class);
List<String> row = new ArrayList<String>();
row.add("<a href=\"" + uri + ".html\">" + menu.name() + "</a>");
row.add(menu.desc());
rows.add(row);
}
return new Page("Home", "Menus", new String[]{"Menu Name", "Menu Desc"}, rows);
}
}

View File

@ -1,106 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
/**
* LogPageHandler
*/
@Menu(name = "Log", desc = "Show system log.", order = Integer.MAX_VALUE - 11000)
public class LogPageHandler implements PageHandler {
private static final int SHOW_LOG_LENGTH = 30000;
private File file;
@SuppressWarnings("unchecked")
public LogPageHandler() {
try {
org.apache.log4j.Logger logger = LogManager.getRootLogger();
if (logger != null) {
Enumeration<Appender> appenders = logger.getAllAppenders();
if (appenders != null) {
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String filename = fileAppender.getFile();
file = new File(filename);
break;
}
}
}
}
} catch (Throwable t) {
}
}
public Page handle(URL url) {
long size = 0;
String content = "";
String modified = "Not exist";
if (file != null && file.exists()) {
try {
FileInputStream fis = new FileInputStream(file);
FileChannel channel = fis.getChannel();
size = channel.size();
ByteBuffer bb;
if (size <= SHOW_LOG_LENGTH) {
bb = ByteBuffer.allocate((int) size);
channel.read(bb, 0);
} else {
int pos = (int) (size - SHOW_LOG_LENGTH);
bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
channel.read(bb, pos);
}
bb.flip();
content = new String(bb.array()).replace("<", "&lt;")
.replace(">", "&gt;").replace("\n", "<br/><br/>");
modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date(file.lastModified()));
} catch (IOException e) {
}
}
Level level = LogManager.getRootLogger().getLevel();
List<List<String>> rows = new ArrayList<List<String>>();
List<String> row = new ArrayList<String>();
row.add(content);
rows.add(row);
return new Page("Log", "Log", new String[]{(file == null ? "" : file.getName()) + ", " + size + " bytes, " + modified + ", " + level}, rows);
}
}

View File

@ -1,84 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.status.Status;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.common.status.support.StatusUtils;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* StatusPageHandler
*/
@Menu(name = "Status", desc = "Show system status.", order = Integer.MAX_VALUE - 12000)
public class StatusPageHandler implements PageHandler {
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
Set<String> names = ExtensionLoader.getExtensionLoader(StatusChecker.class).getSupportedExtensions();
Map<String, Status> statuses = new HashMap<String, Status>();
for (String name : names) {
StatusChecker checker = ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension(name);
List<String> row = new ArrayList<String>();
row.add(name);
Status status = checker.check();
if (status != null && !Status.Level.UNKNOWN.equals(status.getLevel())) {
statuses.put(name, status);
row.add(getLevelHtml(status.getLevel()));
row.add(status.getMessage());
rows.add(row);
}
}
Status status = StatusUtils.getSummaryStatus(statuses);
if ("status".equals(url.getPath())) {
return new Page("", "", "", status.getLevel().toString());
} else {
List<String> row = new ArrayList<String>();
row.add("summary");
row.add(getLevelHtml(status.getLevel()));
row.add("<a href=\"/status\" target=\"_blank\">summary</a>");
rows.add(row);
return new Page("Status (<a href=\"/status\" target=\"_blank\">summary</a>)", "Status", new String[]{"Name", "Status", "Description"}, rows);
}
}
private String getLevelHtml(Status.Level level) {
return "<font color=\"" + getLevelColor(level) + "\">" + level.name() + "</font>";
}
private String getLevelColor(Status.Level level) {
if (level == Status.Level.OK) {
return "green";
} else if (level == Status.Level.ERROR) {
return "red";
} else if (level == Status.Level.WARN) {
return "yellow";
}
return "gray";
}
}

View File

@ -1,137 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.page.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.Version;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* SystemPageHandler
*/
@Menu(name = "System", desc = "Show system environment information.", order = Integer.MAX_VALUE - 10000)
public class SystemPageHandler implements PageHandler {
private static final long SECOND = 1000;
private static final long MINUTE = 60 * SECOND;
private static final long HOUR = 60 * MINUTE;
private static final long DAY = 24 * HOUR;
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
List<String> row;
row = new ArrayList<String>();
row.add("Version");
row.add(Version.getVersion(SystemPageHandler.class, "2.0.0"));
rows.add(row);
row = new ArrayList<String>();
row.add("Host");
String address = NetUtils.getLocalHost();
row.add(NetUtils.getHostName(address) + "/" + address);
rows.add(row);
row = new ArrayList<String>();
row.add("OS");
row.add(System.getProperty("os.name") + " " + System.getProperty("os.version"));
rows.add(row);
row = new ArrayList<String>();
row.add("JVM");
row.add(System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + ",<br/>" + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + " " + System.getProperty("java.vm.info", ""));
rows.add(row);
row = new ArrayList<String>();
row.add("CPU");
row.add(System.getProperty("os.arch", "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
rows.add(row);
row = new ArrayList<String>();
row.add("Locale");
row.add(Locale.getDefault().toString() + "/" + System.getProperty("file.encoding"));
rows.add(row);
row = new ArrayList<String>();
row.add("Uptime");
row.add(formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()));
rows.add(row);
row = new ArrayList<String>();
row.add("Time");
row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
rows.add(row);
return new Page("System", "System", new String[]{
"Property", "Value"}, rows);
}
private String formatUptime(long uptime) {
StringBuilder buf = new StringBuilder();
if (uptime > DAY) {
long days = (uptime - uptime % DAY) / DAY;
buf.append(days);
buf.append(" Days");
uptime = uptime % DAY;
}
if (uptime > HOUR) {
long hours = (uptime - uptime % HOUR) / HOUR;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(hours);
buf.append(" Hours");
uptime = uptime % HOUR;
}
if (uptime > MINUTE) {
long minutes = (uptime - uptime % MINUTE) / MINUTE;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(minutes);
buf.append(" Minutes");
uptime = uptime % MINUTE;
}
if (uptime > SECOND) {
long seconds = (uptime - uptime % SECOND) / SECOND;
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(seconds);
buf.append(" Seconds");
uptime = uptime % SECOND;
}
if (uptime > 0) {
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(uptime);
buf.append(" Milliseconds");
}
return buf.toString();
}
}

View File

@ -1,4 +0,0 @@
index=com.alibaba.dubbo.container.page.pages.HomePageHandler
status=com.alibaba.dubbo.container.page.pages.StatusPageHandler
log=com.alibaba.dubbo.container.page.pages.LogPageHandler
system=com.alibaba.dubbo.container.page.pages.SystemPageHandler

View File

@ -1,39 +0,0 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-container</artifactId>
<version>2.6.0</version>
</parent>
<artifactId>dubbo-container-jetty</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>The jetty container module of dubbo project</description>
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-container-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,89 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.jetty;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.container.Container;
import com.alibaba.dubbo.container.page.PageServlet;
import com.alibaba.dubbo.container.page.ResourceFilter;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
/**
* JettyContainer. (SPI, Singleton, ThreadSafe)
*/
public class JettyContainer implements Container {
public static final String JETTY_PORT = "dubbo.jetty.port";
public static final String JETTY_DIRECTORY = "dubbo.jetty.directory";
public static final String JETTY_PAGES = "dubbo.jetty.page";
public static final int DEFAULT_JETTY_PORT = 8080;
private static final Logger logger = LoggerFactory.getLogger(JettyContainer.class);
SelectChannelConnector connector;
public void start() {
String serverPort = ConfigUtils.getProperty(JETTY_PORT);
int port;
if (serverPort == null || serverPort.length() == 0) {
port = DEFAULT_JETTY_PORT;
} else {
port = Integer.parseInt(serverPort);
}
connector = new SelectChannelConnector();
connector.setPort(port);
ServletHandler handler = new ServletHandler();
String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
if (resources != null && resources.length() > 0) {
FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
resourceHolder.setInitParameter("resources", resources);
}
ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
pageHolder.setInitOrder(2);
Server server = new Server();
server.addConnector(connector);
server.addHandler(handler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
}
}
public void stop() {
try {
if (connector != null) {
connector.close();
connector = null;
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
}

View File

@ -1 +0,0 @@
jetty=com.alibaba.dubbo.container.jetty.JettyContainer

View File

@ -1,38 +0,0 @@
/*
* 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 com.alibaba.dubbo.container.jetty;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.container.Container;
import org.junit.Assert;
import org.junit.Test;
/**
* StandaloneContainerTest
*/
public class JettyContainerTest {
@Test
public void testContainer() {
JettyContainer container = (JettyContainer) ExtensionLoader.getExtensionLoader(Container.class).getExtension("jetty");
container.start();
Assert.assertTrue(container.connector.isStarted());
container.stop();
}
}

View File

@ -1,79 +0,0 @@
/*
* 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 com.alibaba.dubbo.registry.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* RegisteredPageHandler
*
*/
public class RegisteredPageHandler implements PageHandler {
public Page handle(URL url) {
String registryAddress = url.getParameter("registry", "");
List<List<String>> rows = new ArrayList<List<String>>();
Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
StringBuilder select = new StringBuilder();
Registry registry = null;
if (registries != null && registries.size() > 0) {
if (registries.size() == 1) {
registry = registries.iterator().next();
select.append(" &gt; " + registry.getUrl().getAddress());
} else {
select.append(" &gt; <select onchange=\"window.location.href='registered.html?registry=' + this.value;\">");
for (Registry r : registries) {
String sp = r.getUrl().getAddress();
select.append("<option value=\">");
select.append(sp);
if (((registryAddress == null || registryAddress.length() == 0) && registry == null)
|| registryAddress.equals(sp)) {
registry = r;
select.append("\" selected=\"selected");
}
select.append("\">");
select.append(sp);
select.append("</option>");
}
select.append("</select>");
}
}
if (registry instanceof AbstractRegistry) {
Set<URL> services = ((AbstractRegistry) registry).getRegistered();
if (services != null && services.size() > 0) {
for (URL u : services) {
List<String> row = new ArrayList<String>();
row.add(u.toFullString().replace("<", "&lt;").replace(">", "&gt;"));
rows.add(row);
}
}
}
return new Page("<a href=\"registries.html\">Registries</a>" + select.toString() + " &gt; Registered | <a href=\"subscribed.html?registry=" + registryAddress + "\">Subscribed</a>", "Registered (" + rows.size() + ")",
new String[]{"Provider URL:"}, rows);
}
}

View File

@ -1,71 +0,0 @@
/*
* 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 com.alibaba.dubbo.registry.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* RegistriesPageHandler
*
*/
@Menu(name = "Registries", desc = "Show connected registries.", order = 10000)
public class RegistriesPageHandler implements PageHandler {
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
int registeredCount = 0;
int subscribedCount = 0;
if (registries != null && registries.size() > 0) {
for (Registry registry : registries) {
String server = registry.getUrl().getAddress();
List<String> row = new ArrayList<String>();
row.add(NetUtils.getHostName(server) + "/" + server);
if (registry.isAvailable()) {
row.add("<font color=\"green\">Connected</font>");
} else {
row.add("<font color=\"red\">Disconnected</font>");
}
int registeredSize = 0;
int subscribedSize = 0;
if (registry instanceof AbstractRegistry) {
registeredSize = ((AbstractRegistry) registry).getRegistered().size();
registeredCount += registeredSize;
subscribedSize = ((AbstractRegistry) registry).getSubscribed().size();
subscribedCount += subscribedSize;
}
row.add("<a href=\"registered.html?registry=" + server + "\">Registered(" + registeredSize + ")</a>");
row.add("<a href=\"subscribed.html?registry=" + server + "\">Subscribed(" + subscribedSize + ")</a>");
rows.add(row);
}
}
return new Page("Registries", "Registries (" + rows.size() + ")",
new String[]{"Registry Address:", "Status", "Registered(" + registeredCount + ")", "Subscribed(" + subscribedCount + ")"}, rows);
}
}

View File

@ -1,79 +0,0 @@
/*
* 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 com.alibaba.dubbo.registry.pages;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* SubscribedPageHandler
*
*/
public class SubscribedPageHandler implements PageHandler {
public Page handle(URL url) {
String registryAddress = url.getParameter("registry", "");
List<List<String>> rows = new ArrayList<List<String>>();
Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
StringBuilder select = new StringBuilder();
Registry registry = null;
if (registries != null && registries.size() > 0) {
if (registries.size() == 1) {
registry = registries.iterator().next();
select.append(" &gt; " + registry.getUrl().getAddress());
} else {
select.append(" &gt; <select onchange=\"window.location.href='subscribed.html?registry=' + this.value;\">");
for (Registry r : registries) {
String sp = r.getUrl().getAddress();
select.append("<option value=\">");
select.append(sp);
if (((registryAddress == null || registryAddress.length() == 0) && registry == null)
|| registryAddress.equals(sp)) {
registry = r;
select.append("\" selected=\"selected");
}
select.append("\">");
select.append(sp);
select.append("</option>");
}
select.append("</select>");
}
}
if (registry instanceof AbstractRegistry) {
Set<URL> services = ((AbstractRegistry) registry).getSubscribed().keySet();
if (services != null && services.size() > 0) {
for (URL u : services) {
List<String> row = new ArrayList<String>();
row.add(u.toFullString().replace("<", "&lt;").replace(">", "&gt;"));
rows.add(row);
}
}
}
return new Page("<a href=\"registries.html\">Registries</a>" + select.toString() + " &gt; <a href=\"registered.html?registry=" + registryAddress + "\">Registered</a> | Subscribed", "Subscribed (" + rows.size() + ")",
new String[]{"Consumer URL:"}, rows);
}
}

View File

@ -1,3 +0,0 @@
registries=com.alibaba.dubbo.registry.pages.RegistriesPageHandler
registered=com.alibaba.dubbo.registry.pages.RegisteredPageHandler
subscribed=com.alibaba.dubbo.registry.pages.SubscribedPageHandler

View File

@ -1,77 +0,0 @@
/*
* 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 com.alibaba.dubbo.rpc.protocol.dubbo.page;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.remoting.exchange.ExchangeChannel;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* ClientsPageHandler
*/
public class ClientsPageHandler implements PageHandler {
public Page handle(URL url) {
String port = url.getParameter("port");
int p = port == null || port.length() == 0 ? 0 : Integer.parseInt(port);
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
ExchangeServer server = null;
StringBuilder select = new StringBuilder();
if (servers != null && servers.size() > 0) {
if (servers.size() == 1) {
server = servers.iterator().next();
String address = server.getUrl().getAddress();
select.append(" &gt; " + NetUtils.getHostName(address) + "/" + address);
} else {
select.append(" &gt; <select onchange=\"window.location.href='clients.html?port=' + this.value;\">");
for (ExchangeServer s : servers) {
int sp = s.getUrl().getPort();
select.append("<option value=\">");
select.append(sp);
if (p == 0 && server == null || p == sp) {
server = s;
select.append("\" selected=\"selected");
}
select.append("\">");
select.append(s.getUrl().getAddress());
select.append("</option>");
}
select.append("</select>");
}
}
List<List<String>> rows = new ArrayList<List<String>>();
if (server != null) {
Collection<ExchangeChannel> channels = server.getExchangeChannels();
for (ExchangeChannel c : channels) {
List<String> row = new ArrayList<String>();
String address = NetUtils.toAddressString(c.getRemoteAddress());
row.add(NetUtils.getHostName(address) + "/" + address);
rows.add(row);
}
}
return new Page("<a href=\"servers.html\">Servers</a>" + select.toString() + " &gt; Clients", "Clients (" + rows.size() + ")", new String[]{"Client Address:"}, rows);
}
}

View File

@ -1,55 +0,0 @@
/*
* 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 com.alibaba.dubbo.rpc.protocol.dubbo.page;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* ServersPageHandler
*/
@Menu(name = "Servers", desc = "Show exported service servers.", order = 14000)
public class ServersPageHandler implements PageHandler {
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
int clientCount = 0;
if (servers != null && servers.size() > 0) {
for (ExchangeServer s : servers) {
List<String> row = new ArrayList<String>();
String address = s.getUrl().getAddress();
row.add(NetUtils.getHostName(address) + "/" + address);
int clientSize = s.getExchangeChannels().size();
clientCount += clientSize;
row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>");
rows.add(row);
}
}
return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows);
}
}

View File

@ -1,2 +0,0 @@
servers=com.alibaba.dubbo.rpc.protocol.dubbo.page.ServersPageHandler
clients=com.alibaba.dubbo.rpc.protocol.dubbo.page.ClientsPageHandler