List of usage examples for javax.management MBeanAttributeInfo isReadable
public boolean isReadable()
From source file:org.apache.hadoop.hbase.util.JSONBean.java
private static void writeAttribute(final JsonGenerator jg, final MBeanServer mBeanServer, ObjectName oname, final boolean description, final MBeanAttributeInfo attr) throws IOException { if (!attr.isReadable()) { return;//from w ww . ja v a2 s .c o m } String attName = attr.getName(); if ("modelerType".equals(attName)) { return; } if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { return; } String descriptionStr = description ? attr.getDescription() : null; Object value = null; try { value = mBeanServer.getAttribute(oname, attName); } 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 " + attName + " of " + oname + " threw " + e); } } else { LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); } return; } catch (RuntimeErrorException e) { // RuntimeErrorException happens when an unexpected failure occurs in getAttribute // for example https://issues.apache.org/jira/browse/DAEMON-120 LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } catch (AttributeNotFoundException e) { //Ignored the attribute was not found, which should never happen because the bean //just told us that it has this attribute, but if this happens just don't output //the attribute. return; } catch (MBeanException e) { //The code inside the attribute getter threw an exception so log it, and // skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } 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 " + attName + " of " + oname + " threw an exception", e); return; } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so log it and skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } catch (InstanceNotFoundException e) { //Ignored the mbean itself was not found, which should never happen because we //just accessed it (perhaps something unregistered in-between) but if this //happens just don't output the attribute. return; } writeAttribute(jg, attName, descriptionStr, value); }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Dumps the details of a single MBean.//from w ww.ja va 2 s .c o m * * @param connection * the server connection (or server itself) * @param objectName * the object name * @param out * PrintWriter to write the output to * @throws IOException * Signals that an I/O exception has occurred. * @throws JMException * Signals a JMX error */ public static Map<Object, Object> getSimpleMBeanInfo(MBeanServerConnection connection, ObjectName objectName) throws IOException, JMException { Map<Object, Object> attributes = new TreeMap<Object, Object>(); MBeanInfo info = connection.getMBeanInfo(objectName); attributes.put("** Object Name", objectName.toString()); attributes.put("** Object Type", info.getClassName()); for (MBeanAttributeInfo element : info.getAttributes()) { Object value; if (element.isReadable()) { try { value = connection.getAttribute(objectName, element.getName()); } catch (Exception e) { value = JmxDumpUtil.UNREADABLE_VALUE; } } else { value = JmxDumpUtil.UNREADABLE_VALUE; } attributes.put(element.getName(), value); } return attributes; }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Dumps the details of a single MBean.//from www .j a v a2 s. c o m * * @param connection * the server connection (or server itself) * @param objectName * the object name * @param out * PrintWriter to write the output to * @throws IOException * Signals that an I/O exception has occurred. * @throws JMException * Signals a JMX error */ public static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out, String attributeName) throws IOException, JMException { Map<String, Object> attributes = new TreeMap<String, Object>(); MBeanInfo info = connection.getMBeanInfo(objectName); attributes.put("** Object Name", objectName.toString()); attributes.put("** Object Type", info.getClassName()); if (StringUtils.isNotBlank(attributeName)) { Object value; try { value = connection.getAttribute(objectName, attributeName); } catch (Exception e) { value = JmxDumpUtil.UNREADABLE_VALUE; } outputValue(out, value, 10); } else { for (MBeanAttributeInfo element : info.getAttributes()) { Object value; if (element.isReadable()) { try { value = connection.getAttribute(objectName, element.getName()); } catch (Exception e) { value = JmxDumpUtil.UNREADABLE_VALUE; } } else { value = JmxDumpUtil.UNREADABLE_VALUE; } attributes.put(element.getName(), value); } tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0); } }
From source file:org.apache.hadoop.jmx.JMXJsonServlet.java
private void writeAttribute(JsonGenerator jg, ObjectName oname, MBeanAttributeInfo attr) throws IOException { if (!attr.isReadable()) { return;/*w w w.j a v a 2s .c om*/ } String attName = attr.getName(); if ("modelerType".equals(attName)) { return; } if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { return; } Object value = null; try { value = mBeanServer.getAttribute(oname, attName); } 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) { LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e); } else { LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); } return; } catch (AttributeNotFoundException e) { //Ignored the attribute was not found, which should never happen because the bean //just told us that it has this attribute, but if this happens just don't output //the attribute. return; } catch (MBeanException e) { //The code inside the attribute getter threw an exception so log it, and // skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } 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 " + attName + " of " + oname + " threw an exception", e); return; } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so log it and skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } catch (InstanceNotFoundException e) { //Ignored the mbean itself was not found, which should never happen because we //just accessed it (perhaps something unregistered in-between) but if this //happens just don't output the attribute. return; } writeAttribute(jg, attName, value); }
From source file:com.streamsets.datacollector.http.JMXJsonServlet.java
private void writeAttribute(JsonGenerator jg, ObjectName oname, MBeanAttributeInfo attr) throws IOException { if (!attr.isReadable()) { return;/*from ww w .j ava 2 s.co m*/ } String attName = attr.getName(); if ("modelerType".equals(attName)) { return; } if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { return; } Object value = null; try { value = mBeanServer.getAttribute(oname, attName); } catch (RuntimeMBeanException e) { // UnsupportedOperationExceptions happen in the normal course of business, // so no need to if (e.getCause() instanceof UnsupportedOperationException) { } else { } return; } catch (RuntimeErrorException e) { // RuntimeErrorException happens when an unexpected failure occurs in getAttribute // for example https://issues.apache.org/jira/browse/DAEMON-120 return; } catch (AttributeNotFoundException e) { //Ignored the attribute was not found, which should never happen because the bean //just told us that it has this attribute, but if this happens just don't output //the attribute. return; } catch (MBeanException e) { //The code inside the attribute getter threw an exception so // skip outputting the attribute return; } 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 return; } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so return; } catch (InstanceNotFoundException e) { //Ignored the mbean itself was not found, which should never happen because we //just accessed it (perhaps something unregistered in-between) but if this //happens just don't output the attribute. return; } writeAttribute(jg, attName, value); }
From source file:org.jolokia.handler.list.AttributeDataUpdater.java
/** {@inheritDoc} */ @Override//from w w w.ja v a2s .c om protected JSONObject extractData(MBeanInfo pMBeanInfo, String attribute) { JSONObject attrMap = new JSONObject(); for (MBeanAttributeInfo attrInfo : pMBeanInfo.getAttributes()) { if (attribute == null || attrInfo.getName().equals(attribute)) { JSONObject map = new JSONObject(); map.put(TYPE.getKey(), attrInfo.getType()); map.put(DESCRIPTION.getKey(), attrInfo.getDescription()); map.put(READ_WRITE.getKey(), Boolean.valueOf(attrInfo.isWritable() && attrInfo.isReadable())); attrMap.put(attrInfo.getName(), map); } } return attrMap; }
From source file:org.apache.hive.http.JMXJsonServlet.java
private void writeAttribute(JsonGenerator jg, ObjectName oname, MBeanAttributeInfo attr) throws IOException { if (!attr.isReadable()) { return;//from w w w . j a va 2 s . co m } String attName = attr.getName(); if ("modelerType".equals(attName)) { return; } if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) { return; } Object value = null; try { value = mBeanServer.getAttribute(oname, attName); } 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) { LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e); } else { LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); } return; } catch (RuntimeErrorException e) { // RuntimeErrorException happens when an unexpected failure occurs in getAttribute // for example https://issues.apache.org/jira/browse/DAEMON-120 LOG.debug("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } catch (AttributeNotFoundException e) { //Ignored the attribute was not found, which should never happen because the bean //just told us that it has this attribute, but if this happens just don't output //the attribute. return; } catch (MBeanException e) { //The code inside the attribute getter threw an exception so log it, and // skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } 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 " + attName + " of " + oname + " threw an exception", e); return; } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so log it and skip outputting the attribute LOG.error("getting attribute " + attName + " of " + oname + " threw an exception", e); return; } catch (InstanceNotFoundException e) { //Ignored the mbean itself was not found, which should never happen because we //just accessed it (perhaps something unregistered in-between) but if this //happens just don't output the attribute. return; } writeAttribute(jg, attName, value); }
From source file:net.sbbi.upnp.jmx.UPNPMBeanService.java
private String getDeviceSSDP(MBeanInfo info) throws IllegalArgumentException { MBeanOperationInfo[] ops = info.getOperations(); MBeanAttributeInfo[] atts = info.getAttributes(); if ((ops == null || ops.length == 0) && (atts == null || atts.length == 0)) { throw new IllegalArgumentException( "MBean has no operation and no attribute and cannot be exposed as an UPNP device, provide at least one attribute"); }//from w ww .ja va2 s . c o m Set deployedActionNames = new HashSet(); operationsStateVariables = new HashMap(); StringBuffer rtrVal = new StringBuffer(); rtrVal.append("<?xml version=\"1.0\" ?>\r\n"); rtrVal.append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">\r\n"); rtrVal.append("<specVersion><major>1</major><minor>0</minor></specVersion>\r\n"); if (ops != null && ops.length > 0) { rtrVal.append("<actionList>\r\n"); for (int i = 0; i < ops.length; i++) { MBeanOperationInfo op = ops[i]; StringBuffer action = new StringBuffer(); if (deployedActionNames.contains(op.getName())) { log.debug("The " + op.getName() + " is allready deplyoed and cannot be reused, skipping operation deployment"); continue; } action.append("<action>\r\n"); action.append("<name>"); action.append(op.getName()); action.append("</name>\r\n"); action.append("<argumentList>\r\n"); // output argument action.append("<argument>\r\n"); action.append("<name>"); // TODO handle specific output vars String outVarName = op.getName() + "_out"; String actionOutDataType = ServiceStateVariable.getUPNPDataTypeMapping(op.getReturnType()); if (actionOutDataType == null) actionOutDataType = ServiceStateVariableTypes.STRING; action.append(outVarName); action.append("</name>\r\n"); action.append("<direction>out</direction>\r\n"); action.append("<relatedStateVariable>"); action.append(outVarName); action.append("</relatedStateVariable>\r\n"); action.append("</argument>\r\n"); // handle now for all input argument boolean nonPrimitiveInputType = false; boolean duplicatedInputVarname = false; Map operationsInputStateVariables = new HashMap(); if (op.getSignature() != null) { for (int z = 0; z < op.getSignature().length; z++) { MBeanParameterInfo param = op.getSignature()[z]; // do some sanity checks String actionInDataType = ServiceStateVariable.getUPNPDataTypeMapping(param.getType()); if (actionInDataType == null) { nonPrimitiveInputType = true; log.debug("The " + param.getType() + " type is not an UPNP compatible data type, use only primitives"); break; } String inVarName = param.getName(); // check that if the name does allready exists it // has the same type String existing = (String) operationsStateVariables.get(inVarName); if (existing != null && !existing.equals(actionInDataType)) { String msg = "The operation " + op.getName() + " " + inVarName + " parameter already exists for another method with another data type (" + existing + ") either match the data type or change the parameter name" + " in you MBeanParameterInfo object for this operation"; duplicatedInputVarname = true; log.debug(msg); break; } action.append("<argument>\r\n"); action.append("<name>"); operationsInputStateVariables.put(inVarName, actionInDataType); action.append(inVarName); action.append("</name>\r\n"); action.append("<direction>in</direction>\r\n"); action.append("<relatedStateVariable>"); action.append(inVarName); action.append("</relatedStateVariable>\r\n"); action.append("</argument>\r\n"); } } action.append("</argumentList>\r\n"); action.append("</action>\r\n"); // finally the action is only added to the UPNP SSDP if no problems have been detected // with the input parameters type and names. if (!nonPrimitiveInputType && !duplicatedInputVarname) { operationsStateVariables.putAll(operationsInputStateVariables); operationsStateVariables.put(outVarName, actionOutDataType); rtrVal.append(action.toString()); deployedActionNames.add(op.getName()); } } rtrVal.append("</actionList>\r\n"); } else { rtrVal.append("<actionList/>\r\n"); } // now append the operation created state vars rtrVal.append("<serviceStateTable>\r\n"); for (Iterator i = operationsStateVariables.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); String type = (String) operationsStateVariables.get(name); // TODO handle sendevents with mbean notifications ??? // TODO handle defaultValue and allowedValueList values rtrVal.append("<stateVariable sendEvents=\"no\">\r\n"); rtrVal.append("<name>"); rtrVal.append(name); rtrVal.append("</name>\r\n"); rtrVal.append("<dataType>"); rtrVal.append(type); rtrVal.append("</dataType>\r\n"); rtrVal.append("</stateVariable>\r\n"); } if (atts != null && atts.length > 0) { for (int i = 0; i < atts.length; i++) { MBeanAttributeInfo att = atts[i]; if (att.isReadable()) { rtrVal.append("<stateVariable sendEvents=\"no\">\r\n"); rtrVal.append("<name>"); rtrVal.append(att.getName()); rtrVal.append("</name>\r\n"); rtrVal.append("<dataType>"); // TODO check if this works String stateVarType = ServiceStateVariable.getUPNPDataTypeMapping(att.getType()); if (stateVarType == null) stateVarType = ServiceStateVariableTypes.STRING; rtrVal.append(stateVarType); rtrVal.append("</dataType>\r\n"); rtrVal.append("</stateVariable>\r\n"); } } } rtrVal.append("</serviceStateTable>\r\n"); rtrVal.append("</scpd>"); return rtrVal.toString(); }
From source file:com.zabbix.gateway.JMXItemChecker.java
@Override protected String getStringValue(String key) throws Exception { ZabbixItem item = new ZabbixItem(key); if (item.getKeyId().equals("jmx")) { if (2 != item.getArgumentCount()) throw new ZabbixException("required key format: jmx[<object name>,<attribute name>]"); ObjectName objectName = new ObjectName(item.getArgument(1)); String attributeName = item.getArgument(2); String realAttributeName; String fieldNames = ""; // Attribute name and composite data field names are separated by dots. On the other hand the // name may contain a dot too. In this case user needs to escape it with a backslash. Also the // backslash symbols in the name must be escaped. So a real separator is unescaped dot and // separatorIndex() is used to locate it. int sep = HelperFunctionChest.separatorIndex(attributeName); if (-1 != sep) { logger.trace("'{}' contains composite data", attributeName); realAttributeName = attributeName.substring(0, sep); fieldNames = attributeName.substring(sep + 1); } else//from ww w . jav a 2s.c o m realAttributeName = attributeName; // unescape possible dots or backslashes that were escaped by user realAttributeName = HelperFunctionChest.unescapeUserInput(realAttributeName); logger.trace("attributeName:'{}'", realAttributeName); logger.trace("fieldNames:'{}'", fieldNames); return getPrimitiveAttributeValue(mbsc.getAttribute(objectName, realAttributeName), fieldNames); } else if (item.getKeyId().equals("jmx.discovery")) { ObjectName objectName = null; String attributeName = null; if (item.getArgumentCount() >= 1) { objectName = new ObjectName(item.getArgument(1)); } if (item.getArgumentCount() >= 2) { attributeName = item.getArgument(2); } JSONArray counters = new JSONArray(); logger.trace("attributeName = {}, item.getArgumentCount() = " + item.getArgumentCount(), attributeName); for (ObjectName name : mbsc.queryNames(objectName, null)) { logger.trace("discovered object '{}'", name); for (MBeanAttributeInfo attrInfo : mbsc.getMBeanInfo(name).getAttributes()) { logger.trace("discovered attribute '{}'", attrInfo.getName()); if (!attrInfo.isReadable()) { logger.trace("attribute not readable, skipping"); continue; } try { if (null == attributeName || attrInfo.getName().equals(attributeName)) { logger.trace("looking for attributes of primitive types"); String descr = (attrInfo.getName().equals(attrInfo.getDescription()) ? null : attrInfo.getDescription()); findPrimitiveAttributes(counters, name, descr, attrInfo.getName(), mbsc.getAttribute(name, attrInfo.getName())); } } catch (Exception e) { Object[] logInfo = { name, attrInfo.getName(), e }; logger.trace("processing '{},{}' failed", logInfo); } } } JSONObject mapping = new JSONObject(); mapping.put(ItemChecker.JSON_TAG_DATA, counters); return mapping.toString(2); } else throw new ZabbixException("key ID '%s' is not supported", item.getKeyId()); }
From source file:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans) { logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans); JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig(); JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection(); xmlJmxCollection.setName("JSR160-" + serviceName); xmlJmxCollection.setRrd(rrd);//from ww w. j a va 2 s . c o m xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection); xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans()); if (runStandardVmBeans) { ignores.clear(); } else { ignores.addAll(standardVmBeans); } try { for (String domainName : mBeanServerConnection.getDomains()) { // just domains that are relevant for the service if (!ignores.contains(domainName)) { logger.debug("domain: " + domainName); // for all mBeans of the actual domain for (ObjectInstance jmxObjectInstance : mBeanServerConnection .queryMBeans(new ObjectName(domainName + ":*"), null)) { Mbean xmlMbean = xmlObjectFactory.createMbean(); xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString()); String typeAndOthers = StringUtils .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "="); xmlMbean.setName(domainName + "." + typeAndOthers); logger.debug("\t" + jmxObjectInstance.getObjectName()); MBeanInfo jmxMbeanInfo; try { jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName()); } catch (InstanceNotFoundException e) { logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'", jmxObjectInstance.getObjectName(), e.getMessage()); continue; } catch (IntrospectionException e) { logger.error("IntrospectionException skipping MBean '{}' message: '{}'", jmxObjectInstance.getObjectName(), e.getMessage()); continue; } catch (ReflectionException e) { logger.error("ReflectionException skipping MBean '{}' message: '{}'", jmxObjectInstance.getObjectName(), e.getMessage()); continue; } catch (Throwable e) { logger.error( "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'", jmxObjectInstance.getObjectName(), e.getMessage()); continue; } logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName()); for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) { // process just readable mbeans if (jmxBeanAttributeInfo.isReadable()) { // precess writable mbeans if run writable mbeans is set if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) { logger.debug("Check mBean: '{}', attribute: '{}'", jmxObjectInstance.getObjectName().toString(), jmxBeanAttributeInfo.getName()); logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(), jmxBeanAttributeInfo.getType()); // check for CompositeData if ("javax.management.openmbean.CompositeData" .equals(jmxBeanAttributeInfo.getType())) { logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName()); CompAttrib compAttrib = createCompAttrib(mBeanServerConnection, jmxObjectInstance, jmxBeanAttributeInfo); if (compAttrib != null) { logger.debug("xmlMbean got CompAttrib"); xmlMbean.getCompAttrib().add(compAttrib); } } if (numbers.contains(jmxBeanAttributeInfo.getType())) { Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo); logger.debug("Added MBean: '{}' Added attribute: '{}'", xmlMbean.getObjectname(), xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias()); xmlMbean.getAttrib().add(xmlJmxAttribute); } } } } if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) { xmlJmxCollection.getMbeans().getMbean().add(xmlMbean); } else { logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes."); } } } else { logger.debug("ignored: " + domainName); } } } catch (MalformedObjectNameException e) { logger.error("MalformedObjectNameException '{}'", e.getMessage()); } catch (IOException e) { logger.error("IOException '{}'", e.getMessage()); } return xmlJmxDatacollectionConfig; }