📄 statustransformer.java
字号:
/*
* $Header: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/StatusTransformer.java,v 1.11 2003/12/23 19:23:10 remm Exp $
* $Revision: 1.11 $
* $Date: 2003/12/23 19:23:10 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.catalina.manager;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.compat.JdkCompat;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
/**
* This is a refactoring of the servlet to externalize
* the output into a simple class. Although we could
* use XSLT, that is unnecessarily complex.
*
* @author Peter Lin
* @version $Revision: 1.11 $ $Date: 2003/12/23 19:23:10 $
*/
public class StatusTransformer {
// --------------------------------------------------------- Public Methods
public static void setContentType(HttpServletResponse response,
int mode) {
if (mode == 0){
response.setContentType("text/html;charset="+Constants.CHARSET);
} else if (mode == 1){
response.setContentType("text/xml;charset="+Constants.CHARSET);
}
}
/**
* Process a GET request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
public static void writeHeader(PrintWriter writer, int mode) {
if (mode == 0){
// HTML Header Section
writer.print(Constants.HTML_HEADER_SECTION);
} else if (mode == 1){
writer.write(Constants.XML_DECLARATION);
writer.write
(Constants.XML_STYLE);
writer.write("<status>");
}
}
/**
* Write the header body. XML output doesn't bother
* to output this stuff, since it's just title.
*
* @param PrintWriter writer
* @param Object[] args
* @param int mode
*/
public static void writeBody(PrintWriter writer, Object[] args, int mode) {
if (mode == 0){
writer.print(MessageFormat.format
(Constants.BODY_HEADER_SECTION, args));
}
}
/**
* Write the manager webapp information.
*
* @param PrintWriter writer
* @param Object[] args
* @param int mode
*/
public static void writeManager(PrintWriter writer, Object[] args,
int mode) {
if (mode == 0){
writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
}
}
public static void writePageHeading(PrintWriter writer, Object[] args,
int mode) {
if (mode == 0){
writer.print(MessageFormat.format
(Constants.SERVER_HEADER_SECTION, args));
}
}
public static void writeServerInfo(PrintWriter writer, Object[] args,
int mode){
if (mode == 0){
writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args));
}
}
/**
*
*/
public static void writeFooter(PrintWriter writer, int mode) {
if (mode == 0){
// HTML Tail Section
writer.print(Constants.HTML_TAIL_SECTION);
} else if (mode == 1){
writer.write("</status>");
}
}
/**
* Write the VM state. Mode 0 will generate HTML.
* Mode 1 will generate XML.
*/
public static void writeVMState(PrintWriter writer, int mode)
throws Exception {
if (mode == 0){
writer.print("<h1>JVM</h1>");
writer.print("<p>");
writer.print(" Free memory: ");
writer.print(formatSize
(new Long(Runtime.getRuntime().freeMemory()), true));
writer.print(" Total memory: ");
writer.print(formatSize
(new Long(Runtime.getRuntime().totalMemory()), true));
writer.print(" Max memory: ");
writer.print(formatSize
(new Long(JdkCompat.getJdkCompat().getMaxMemory()),
true));
writer.print("</p>");
} else if (mode == 1){
writer.write("<jvm>");
writer.write("<memory");
writer.write(" free='" + Runtime.getRuntime().freeMemory() + "'");
writer.write(" total='" + Runtime.getRuntime().totalMemory() + "'");
writer.write(" max='" + JdkCompat.getJdkCompat().getMaxMemory() + "'/>");
writer.write("</jvm>");
}
}
/**
* Write connector state.
*/
public static void writeConnectorState(PrintWriter writer,
ObjectName tpName, String name,
MBeanServer mBeanServer,
Vector globalRequestProcessors,
Vector requestProcessors,
int mode)
throws Exception {
if (mode == 0) {
writer.print("<h1>");
writer.print(name);
writer.print("</h1>");
writer.print("<p>");
writer.print(" Max threads: ");
writer.print(mBeanServer.getAttribute(tpName, "maxThreads"));
writer.print(" Min spare threads: ");
writer.print(mBeanServer.getAttribute(tpName, "minSpareThreads"));
writer.print(" Max spare threads: ");
writer.print(mBeanServer.getAttribute(tpName, "maxSpareThreads"));
writer.print(" Current thread count: ");
writer.print(mBeanServer.getAttribute(tpName, "currentThreadCount"));
writer.print(" Current thread busy: ");
writer.print(mBeanServer.getAttribute(tpName, "currentThreadsBusy"));
writer.print("<br>");
ObjectName grpName = null;
Enumeration enum = globalRequestProcessors.elements();
while (enum.hasMoreElements()) {
ObjectName objectName = (ObjectName) enum.nextElement();
if (name.equals(objectName.getKeyProperty("name"))) {
grpName = objectName;
}
}
if (grpName == null) {
return;
}
writer.print(" Max processing time: ");
writer.print(formatTime(mBeanServer.getAttribute
(grpName, "maxTime"), false));
writer.print(" Processing time: ");
writer.print(formatTime(mBeanServer.getAttribute
(grpName, "processingTime"), true));
writer.print(" Request count: ");
writer.print(mBeanServer.getAttribute(grpName, "requestCount"));
writer.print(" Error count: ");
writer.print(mBeanServer.getAttribute(grpName, "errorCount"));
writer.print(" Bytes received: ");
writer.print(formatSize(mBeanServer.getAttribute
(grpName, "bytesReceived"), true));
writer.print(" Bytes sent: ");
writer.print(formatSize(mBeanServer.getAttribute
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -