Skip to content

Commit

Permalink
HADOOP-7704. Reduce number of object created by JMXJsonServlet.
Browse files Browse the repository at this point in the history
(Devaraj K via Eric Yang)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1179287 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
macroadster committed Oct 5, 2011
1 parent c90d7d6 commit 9b6671d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
3 changes: 3 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,23 @@ 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.
*/
@Override
public void init() throws ServletException {
// Retrieve the MBean server
mBeanServer = ManagementFactory.getPlatformMBeanServer();
jsonFactory = new JsonFactory();
}

/**
Expand All @@ -149,53 +152,45 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
response)) {
return;
}
JsonGenerator jg = null;
try {
response.setContentType("application/json; charset=utf8");

response.setContentType("application/json; charset=utf8");

PrintWriter writer = response.getWriter();
PrintWriter writer = response.getWriter();
jg = jsonFactory.createJsonGenerator(writer);
jg.useDefaultPrettyPrinter();
jg.writeStartObject();

JsonFactory jsonFactory = new JsonFactory();
JsonGenerator 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");
if (getmethod != null) {
String[] splitStrings = getmethod.split("\\:\\:");
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);
// query per mbean attribute
String getmethod = request.getParameter("get");
if (getmethod != null) {
String[] splitStrings = getmethod.split("\\:\\:");
if (splitStrings.length != 2) {
jg.writeStringField("result", "ERROR");
jg.writeStringField("message", "query format is not as expected.");
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1],
response);
return;
}
listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1],
response);
jg.close();
return;
}

// query per mbean
String qry = request.getParameter("qry");
if (qry == null) {
qry = "*:*";
// query per mbean
String qry = request.getParameter("qry");
if (qry == null) {
qry = "*:*";
}
listBeans(jg, new ObjectName(qry), null, response);
} finally {
if (jg != null) {
jg.close();
}
}
listBeans(jg, new ObjectName(qry), null, response);
jg.close();

} catch ( IOException e ) {
} catch (IOException e) {
LOG.error("Caught an exception while processing JMX request", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch ( MalformedObjectNameException e ) {
} catch (MalformedObjectNameException e) {
LOG.error("Caught an exception while processing JMX request", e);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
Expand Down

0 comments on commit 9b6671d

Please sign in to comment.