List of usage examples for javax.management MBeanInfo getClassName
public String getClassName()
From source file:com.googlecode.jmxtrans.model.Query.java
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { MBeanInfo info = mbeanServer.getMBeanInfo(queryName); ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); }/*from w w w .ja va 2 s. c o m*/ } else { attributes = attr; } try { if (!attributes.isEmpty()) { logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this); AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()])); return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()) .getResults(); } } catch (UnmarshalException ue) { if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) { logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage()); } else { throw ue; } } return ImmutableList.of(); }
From source file:net.zcarioca.jmx.domain.MBeanDescriptor.java
/** * Constructor for an {@link MBeanDescriptor}. * //from w w w . ja v a 2 s.c o m * @param objectInstance The {@link ObjectInstance} as provided by an {@link MBeanServer}. */ public MBeanDescriptor(ObjectName objectName, MBeanInfo mbeanInfo) { this.className = mbeanInfo.getClassName(); this.objectName = objectName; this.description = mbeanInfo.getDescription(); }
From source file:org.apache.catalina.manager.JMXProxyServlet.java
public void listBeans(PrintWriter writer, String qry) { Set names = null;/*ww w . jav a2s . co m*/ try { names = mBeanServer.queryNames(new ObjectName(qry), null); writer.println("OK - Number of results: " + names.size()); writer.println(); } catch (Exception e) { writer.println("Error - " + e.toString()); return; } Iterator it = names.iterator(); while (it.hasNext()) { ObjectName oname = (ObjectName) it.next(); writer.println("Name: " + oname.toString()); try { MBeanInfo minfo = mBeanServer.getMBeanInfo(oname); // can't be null - I thinl String code = minfo.getClassName(); if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { code = (String) mBeanServer.getAttribute(oname, "modelerType"); } writer.println("modelerType: " + code); MBeanAttributeInfo attrs[] = minfo.getAttributes(); Object value = null; for (int i = 0; i < attrs.length; i++) { if (!attrs[i].isReadable()) continue; if (!isSupported(attrs[i].getType())) continue; String attName = attrs[i].getName(); if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { continue; } try { value = mBeanServer.getAttribute(oname, attName); } catch (Throwable t) { log("Error getting attribute " + oname + " " + attName + " " + t.toString()); continue; } if (value == null) continue; if ("modelerType".equals(attName)) continue; String valueString = value.toString(); writer.println(attName + ": " + escape(valueString)); } } catch (Exception e) { // Ignore } writer.println(); } }
From source file:org.apache.catalina.mbeans.MBeanDumper.java
/** * The following code to dump MBeans has been copied from JMXProxyServlet. * *///from w w w . ja va 2s . co m public static String dumpBeans(MBeanServer mbeanServer, Set<ObjectName> names) { StringBuilder buf = new StringBuilder(); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); buf.append("Name: "); buf.append(oname.toString()); buf.append(CRLF); try { MBeanInfo minfo = mbeanServer.getMBeanInfo(oname); // can't be null - I think String code = minfo.getClassName(); if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { code = (String) mbeanServer.getAttribute(oname, "modelerType"); } buf.append("modelerType: "); buf.append(code); buf.append(CRLF); MBeanAttributeInfo attrs[] = minfo.getAttributes(); Object value = null; for (int i = 0; i < attrs.length; i++) { if (!attrs[i].isReadable()) continue; String attName = attrs[i].getName(); if ("modelerType".equals(attName)) continue; if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { continue; } try { value = mbeanServer.getAttribute(oname, attName); } catch (JMRuntimeException rme) { Throwable cause = rme.getCause(); if (cause instanceof UnsupportedOperationException) { if (log.isDebugEnabled()) { log.debug("Error getting attribute " + oname + " " + attName, rme); } } else if (cause instanceof NullPointerException) { if (log.isDebugEnabled()) { log.debug("Error getting attribute " + oname + " " + attName, rme); } } else { log.error("Error getting attribute " + oname + " " + attName, rme); } continue; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error("Error getting attribute " + oname + " " + attName, t); continue; } if (value == null) continue; String valueString; try { Class<?> c = value.getClass(); if (c.isArray()) { int len = Array.getLength(value); StringBuilder sb = new StringBuilder( "Array[" + c.getComponentType().getName() + "] of length " + len); if (len > 0) { sb.append(CRLF); } for (int j = 0; j < len; j++) { sb.append("\t"); Object item = Array.get(value, j); if (item == null) { sb.append("NULL VALUE"); } else { try { sb.append(escape(item.toString())); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); sb.append("NON-STRINGABLE VALUE"); } } if (j < len - 1) { sb.append(CRLF); } } valueString = sb.toString(); } else { valueString = escape(value.toString()); } buf.append(attName); buf.append(": "); buf.append(valueString); buf.append(CRLF); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } buf.append(CRLF); } return buf.toString(); }
From source file:org.apache.hadoop.hbase.util.JSONBean.java
/** * @param mBeanServer/*from w ww .java 2 s . c o m*/ * @param qry * @param attribute * @param description * @return Return non-zero if failed to find bean. 0 * @throws IOException */ private static int write(final JsonGenerator jg, final MBeanServer mBeanServer, ObjectName qry, String attribute, final boolean description) throws IOException { LOG.trace("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo; String code = ""; String descriptionStr = null; Object attributeinfo = null; try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); if (description) descriptionStr = minfo.getDescription(); String prs = ""; try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.getAttribute(oname, prs); } } catch (RuntimeMBeanException e) { // UnsupportedOperationExceptions happen in the normal course of business, // so no need to log them as errors all the time. if (e.getCause() instanceof UnsupportedOperationException) { if (LOG.isTraceEnabled()) { LOG.trace("Getting attribute " + prs + " of " + oname + " threw " + e); } } else { LOG.error("Getting attribute " + prs + " of " + oname + " threw an exception", e); } return 0; } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (MBeanException e) { // The code inside the attribute getter threw an exception so log it, // and fall back on the class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptionscan still find their way through, so treat them // the same as MBeanException LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so log it and fall back on the // class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); if (description && descriptionStr != null && descriptionStr.length() > 0) { jg.writeStringField("description", descriptionStr); } jg.writeStringField("modelerType", code); if (attribute != null && attributeinfo == null) { jg.writeStringField("result", "ERROR"); jg.writeStringField("message", "No attribute with name " + attribute + " was found."); jg.writeEndObject(); jg.writeEndArray(); jg.close(); return -1; } if (attribute != null) { writeAttribute(jg, attribute, descriptionStr, attributeinfo); } else { MBeanAttributeInfo[] attrs = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, mBeanServer, oname, description, attrs[i]); } } jg.writeEndObject(); } jg.writeEndArray(); return 0; }
From source file:org.apache.hadoop.jmx.JMXJsonServlet.java
private void listBeans(JsonGenerator jg, ObjectName qry) throws IOException { LOG.debug("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo; String code;/*from w ww.j a v a 2 s . com*/ try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { code = (String) mBeanServer.getAttribute(oname, "modelerType"); } } catch (AttributeNotFoundException e) { //Ignored the modelerType attribute was not found, so use the class name instead. } catch (MBeanException e) { //The code inside the attribute getter threw an exception so log it, and // fall back on the class name LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } catch (RuntimeException e) { //For some reason even with an MBeanException available to them Runtime exceptions //can still find their way through, so treat them the same as MBeanException LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so log it and fall back on the class name LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { //This is an internal error, something odd happened with reflection so log it and //don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { //This happens when the code inside the JMX bean threw an exception, so log it and //don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); // can't be null - I think jg.writeStringField("modelerType", code); MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, oname, attrs[i]); } // LOG.error("Caught Error writing value ",t); // ExceptionUtils.handleThrowable(t); //} jg.writeEndObject(); } jg.writeEndArray(); }
From source file:org.apache.hive.http.JMXJsonServlet.java
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException { LOG.debug("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo; String code = ""; Object attributeinfo = null; try {//ww w . j av a 2s .c o m minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); String prs = ""; try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.getAttribute(oname, prs); } } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (MBeanException e) { // The code inside the attribute getter threw an exception so log it, // and fall back on the class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptions can still find their way through, so treat them // the same as MBeanException LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so log it and fall back on the // class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); jg.writeStringField("modelerType", code); if ((attribute != null) && (attributeinfo == null)) { jg.writeStringField("result", "ERROR"); jg.writeStringField("message", "No attribute with name " + attribute + " was found."); jg.writeEndObject(); jg.writeEndArray(); jg.close(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } if (attribute != null) { writeAttribute(jg, attribute, attributeinfo); } else { MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, oname, attrs[i]); } } jg.writeEndObject(); } jg.writeEndArray(); }
From source file:org.apache.openejb.server.cli.command.LocalJMXCommand.java
private void listMBeans() { final MBeanServer mBeanServer = LocalMBeanServer.get(); final Set<ObjectName> names; try {// w w w . j av a 2 s. c o m names = mBeanServer.queryNames(null, null); } catch (Exception e) { streamManager.writeErr(e); return; } final Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); streamManager.writeOut("Name: " + oname.toString()); try { final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname); String code = minfo.getClassName(); if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { code = (String) mBeanServer.getAttribute(oname, "modelerType"); } streamManager.writeOut(" + modelerType: " + code); MBeanAttributeInfo attrs[] = minfo.getAttributes(); Object value = null; for (int i = 0; i < attrs.length; i++) { if (!attrs[i].isReadable()) { continue; } final String attName = attrs[i].getName(); if ("modelerType".equals(attName)) { continue; } if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { continue; } try { value = mBeanServer.getAttribute(oname, attName); } catch (RuntimeMBeanException uoe) { // ignored } catch (Throwable t) { streamManager.writeErr(new Exception(t)); continue; } try { String valueString = stringify(value); streamManager.writeOut(" + " + attName + ": " + valueString); } catch (Throwable t) { streamManager.writeErr(new Exception(t)); } } } catch (Throwable t) { streamManager.writeErr(new Exception(t)); } streamManager.writeOut(""); } }
From source file:org.hyperic.hq.plugin.jboss.jmx.ServerQuery.java
private boolean checkClass(MBeanServerConnection mServer, ObjectName name, String mbeanClass) { boolean res = true; if (mbeanClass != null) { try {/*from ww w . jav a2 s . co m*/ MBeanInfo info = mServer.getMBeanInfo(name); res = info.getClassName().matches(mbeanClass); } catch (Exception e) { log.error("mServer.getMBeanInfo(" + name + "): " + e); res = false; } } return res; }
From source file:org.hyperic.hq.product.jmx.MBeanDumper.java
public void dump(Set beans) { Iterator iter = beans.iterator(); while (iter.hasNext()) { ObjectName obj = (ObjectName) iter.next(); try {/*from w ww . j a va2 s . c o m*/ MBeanInfo info = getMBeanInfo(obj); System.out.println("MBean: " + info.getClassName()); System.out.println("Name: " + obj); MBeanAttributeInfo[] attrs = info.getAttributes(); for (int k = 0; k < attrs.length; k++) { String name = attrs[k].getName(); String value = "null"; try { Object o = getAttribute(obj, name); if (o != null) { if (o.getClass().isArray()) { value = Arrays.asList((Object[]) o).toString(); } else { value = o.toString(); } } } catch (Exception e) { value = "ERROR"; if (log.isDebugEnabled()) { e.printStackTrace(); } } String perms = ""; if (attrs[k].isReadable()) { perms += "r"; } if (attrs[k].isWritable()) { perms += "w"; } System.out.println("\t" + k + ". Attribute: " + name + " = " + value + " (" + perms + ")"); } MBeanOperationInfo[] ops = info.getOperations(); for (int i = 0; i < ops.length; i++) { ArrayList sig = new ArrayList(); MBeanParameterInfo[] params = ops[i].getSignature(); for (int j = 0; j < params.length; j++) { sig.add(params[j].getType()); } System.out.println( "\t Operation: " + ops[i].getReturnType() + " " + ops[i].getName() + " " + sig); } } catch (Exception e) { if (log.isDebugEnabled()) { e.printStackTrace(); } } System.out.println(""); } }