HADOOP-7704. Reduce number of object created by JMXJsonServlet.
(Devaraj K via Eric Yang) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1179287 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c90d7d649b
commit
9b6671dc29
@ -48,6 +48,9 @@ Trunk (unreleased changes)
|
||||
HADOOP-7703. Improved excpetion handling of shutting down web server.
|
||||
(Devaraj K via Eric Yang)
|
||||
|
||||
HADOOP-7704. Reduce number of object created by JMXJsonServlet.
|
||||
(Devaraj K via Eric Yang)
|
||||
|
||||
Release 0.23.0 - Unreleased
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
@ -117,13 +117,15 @@ public class JMXJsonServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
/**
|
||||
* MBean server.
|
||||
*/
|
||||
protected transient MBeanServer mBeanServer = null;
|
||||
protected transient MBeanServer mBeanServer;
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
/**
|
||||
* Json Factory to create Json generators for write objects in json format
|
||||
*/
|
||||
protected transient JsonFactory jsonFactory;
|
||||
/**
|
||||
* Initialize this servlet.
|
||||
*/
|
||||
@ -131,6 +133,7 @@ public class JMXJsonServlet extends HttpServlet {
|
||||
public void init() throws ServletException {
|
||||
// Retrieve the MBean server
|
||||
mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
jsonFactory = new JsonFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,23 +152,14 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
JsonGenerator jg = null;
|
||||
try {
|
||||
response.setContentType("application/json; charset=utf8");
|
||||
|
||||
PrintWriter writer = response.getWriter();
|
||||
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonGenerator jg = jsonFactory.createJsonGenerator(writer);
|
||||
jg = jsonFactory.createJsonGenerator(writer);
|
||||
jg.useDefaultPrettyPrinter();
|
||||
jg.writeStartObject();
|
||||
if (mBeanServer == null) {
|
||||
jg.writeStringField("result", "ERROR");
|
||||
jg.writeStringField("message", "No MBeanServer could be found");
|
||||
jg.close();
|
||||
LOG.error("No MBeanServer could be found.");
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
// query per mbean attribute
|
||||
String getmethod = request.getParameter("get");
|
||||
@ -174,13 +168,11 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (splitStrings.length != 2) {
|
||||
jg.writeStringField("result", "ERROR");
|
||||
jg.writeStringField("message", "query format is not as expected.");
|
||||
jg.close();
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1],
|
||||
response);
|
||||
jg.close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -190,8 +182,11 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
qry = "*:*";
|
||||
}
|
||||
listBeans(jg, new ObjectName(qry), null, response);
|
||||
} finally {
|
||||
if (jg != null) {
|
||||
jg.close();
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Caught an exception while processing JMX request", e);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
|
Loading…
Reference in New Issue
Block a user