List of usage examples for javax.management MBeanAttributeInfo isReadable
public boolean isReadable()
From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans, Map<String, String> dictionary) { logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary); nameCutter.setDictionary(dictionary); JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig(); JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection(); xmlJmxCollection.setName("JSR160-" + serviceName); xmlJmxCollection.setRrd(rrd);/*from w w w .ja va 2 s . co 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; }
From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans, Map<String, String> dictionary) { logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary); nameCutter.setDictionary(dictionary); JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig(); JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection(); xmlJmxCollection.setName("JSR160-" + serviceName); xmlJmxCollection.setRrd(rrd);//from w w w . j ava 2 s . c om xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection); xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans()); if (runStandardVmBeans) { ignores.clear(); } else { ignores.addAll(standardVmBeans); } try { String[] domains = mBeanServerConnection.getDomains(); logger.info("Found " + domains.length + " domains"); logger.info("domains: " + Arrays.toString(domains)); for (String domainName : domains) { // just domains that are relevant for the service if (!ignores.contains(domainName)) { logger.info("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()); } logger.debug("finish collection!"); return xmlJmxDatacollectionConfig; }
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
@Nullable private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing); MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName); // If no attribute is returned, we know that it is not defined in the // management interface. if (inf == null) { throw new InvalidInvocationException( "Attribute '" + pd.getName() + "' is not exposed on the management interface"); }//from w w w . java2 s .c om if (invocation.getMethod().equals(pd.getReadMethod())) { if (inf.isReadable()) { return this.serverToUse.getAttribute(this.objectName, attributeName); } else { throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable"); } } else if (invocation.getMethod().equals(pd.getWriteMethod())) { if (inf.isWritable()) { this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0])); return null; } else { throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable"); } } else { throw new IllegalStateException( "Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter"); } }
From source file:com.tesora.dve.tools.DVEConfigCLI.java
public void cmd_jmx_get_attributes() throws PEException { checkJMXConnected();/*from w w w . j a va 2 s . co m*/ checkJMXDomain(); checkJMXMBean(); for (final MBeanAttributeInfo attrib : jmxMBeanInfo.getAttributes()) { if (attrib.isReadable()) { println(attrib.getName() + " = " + jmxConnector.getAttribute(jmxMBean, attrib.getName())); } } }