blob: c0b3c7c11830b41f729c3256d2cb062c409d8f8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.automatedtests.util;
import java.io.IOException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class StatusServlet extends HttpServlet {
public static DateFormat dfHuman = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
/**
* Version number of this release. For example "5.0.0".
*/
public static final String VERSION;
/**
* Major version number. For example 5 in 5.1.0.
*/
public static final int VERSION_MAJOR;
/**
* Minor version number. For example 1 in 5.1.0.
*/
public static final int VERSION_MINOR;
/**
* Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
*/
public static final String VERSION_BUILD;
/* Initialize version numbers from string replaced by build-script. */
static {
if ("@VERSION@".equals("@" + "VERSION" + "@")) {
VERSION = "5.9.9-INTERNAL-NONVERSIONED-DEBUG-BUILD";
} else {
VERSION = "@VERSION@";
}
final String[] digits = VERSION.split("\\.");
VERSION_MAJOR = Integer.parseInt(digits[0]);
VERSION_MINOR = Integer.parseInt(digits[1]);
VERSION_BUILD = digits[2];
}
@Override
public void init(javax.servlet.ServletConfig servletConfig)
throws javax.servlet.ServletException {
super.init(servletConfig);
}
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Writer w = response.getWriter();
// not cacheable
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("text/html");
String p = "";
p += "<p>StatusServlet " + dfHuman.format(new Date()) + "</p>";
for (int i = 0; i < 30; i++) {
System.gc();
}
long inUse = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory());
p += "<p>Memory:<br />\n<memused>" + inUse
+ "</memused> (Used)<br />\n" + "<memtotal>"
+ Runtime.getRuntime().totalMemory()
+ "<memtotal> (Total)<br />\n" + "<memfree>"
+ Runtime.getRuntime().freeMemory() + "<memfree> (Free)</p>\n";
w.write("<html>\n" + p + "</html>\n");
}
}
|