Java Code Examples for javax.management.MBeanAttributeInfo#isReadable()
The following examples show how to use
javax.management.MBeanAttributeInfo#isReadable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveJvmServiceImpl.java From glowroot with Apache License 2.0 | 6 votes |
private Set<String> getAttributeNames(MBeanInfo mbeanInfo, ObjectName objectName) throws Exception { List<MBeanServer> mbeanServers = lazyPlatformMBeanServer.findAllMBeanServers(); Set<String> attributeNames = Sets.newHashSet(); for (MBeanAttributeInfo attribute : mbeanInfo.getAttributes()) { if (attribute.isReadable()) { try { Object value = lazyPlatformMBeanServer.getAttribute(objectName, attribute.getName(), mbeanServers); addNumericAttributes(attribute, value, attributeNames); } catch (Exception e) { // log exception at debug level logger.debug(e.getMessage(), e); } } } return attributeNames; }
Example 2
Source File: MXBeanTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 3
Source File: RRDSigarDataStore.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
/** * Initializes a new RRD data base if it's not exist. * * @param mbs is the source of chronological data * @param dataBaseFilePath is the path to the file with the rrd data base * @param step is the data base refresh period * @throws java.io.IOException is thrown when the data base exists but cannot be read */ public RRDSigarDataStore(MBeanServer mbs, String dataBaseFilePath, int step, Logger logger) throws IOException, MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException { super(dataBaseFilePath, step, logger); compositeTypes.put("HeapMemoryUsage-java.lang:type=Memory", "used"); this.mbs = mbs; for (String objectName : OBJECT_NAMES) { Set<ObjectName> realNames = mbs.queryNames(new ObjectName(objectName), null); for (ObjectName realObjectName : realNames) { for (MBeanAttributeInfo attrInfo : mbs.getMBeanInfo(realObjectName).getAttributes()) { if (attrInfo.isReadable()) { String sourceName = attrInfo.getName() + "-" + realObjectName; String dataStoreName = toDataStoreName(sourceName); logger.trace("Adding a " + dataStoreName + " / " + sourceName + " source to rrd"); dataSources.put(dataStoreName, sourceName); } } } } initDatabase(); setName("RRD4J Data Store " + new File(dataBaseFile).getName()); setDaemon(true); start(); }
Example 4
Source File: MetricsProxy.java From cassandra-reaper with Apache License 2.0 | 5 votes |
private List<JmxStat> scrapeBean(ObjectName mbeanName) { List<JmxStat> attributeList = Lists.newArrayList(); try { Map<String, MBeanAttributeInfo> name2AttrInfo = new LinkedHashMap<>(); MBeanInfo info = proxy.getMBeanServerConnection().getMBeanInfo(mbeanName); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { MBeanAttributeInfo attr = attrInfo; if (!attr.isReadable()) { LOG.warn("{}.{} not readable", mbeanName, attr); } else { name2AttrInfo.put(attr.getName(), attr); } } proxy.getMBeanServerConnection().getAttributes(mbeanName, name2AttrInfo.keySet().toArray(new String[0])) .asList() .forEach((attribute) -> { Object value = attribute.getValue(); JmxStat.Builder jmxStatBuilder = JmxStat.builder() .withAttribute(attribute.getName()) .withName(mbeanName.getKeyProperty("name")) .withScope(mbeanName.getKeyProperty("scope")) .withDomain(mbeanName.getDomain()) .withType(mbeanName.getKeyProperty("type")) .withMbeanName(mbeanName.toString()); if (null == value) { attributeList.add(jmxStatBuilder.withValue(0.0).build()); } else if (value instanceof Number) { attributeList.add(jmxStatBuilder.withValue(((Number) value).doubleValue()).build()); } }); } catch (JMException | IOException e) { LOG.error("Fail getting mbeanInfo or grabbing attributes for mbean {} ", mbeanName, e); } return attributeList; }
Example 5
Source File: MXBeanTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 6
Source File: MXBeanTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 7
Source File: MXBeanTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 8
Source File: MXBeanTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 9
Source File: MBeanClientInterceptor.java From spring-analysis-note with MIT License | 5 votes |
@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"); } 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"); } }
Example 10
Source File: MXBeanTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 11
Source File: MXBeanTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 12
Source File: MBeanClientInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException { 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"); } 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"); } }
Example 13
Source File: MXBeanTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 14
Source File: MXBeanTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 15
Source File: MBeanClientInterceptor.java From java-technology-stack with MIT License | 5 votes |
@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"); } 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"); } }
Example 16
Source File: MXBeanTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 17
Source File: MXBeanTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void testMXBean(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); MBeanAttributeInfo[] attrs = mbi.getAttributes(); int nattrs = attrs.length; if (mbi.getAttributes().length != 1) failure("wrong number of attributes: " + attrs); else { MBeanAttributeInfo mbai = attrs[0]; if (mbai.getName().equals("Ints") && mbai.isReadable() && !mbai.isWritable() && mbai.getDescriptor().getFieldValue("openType") .equals(new ArrayType<int[]>(SimpleType.INTEGER, true)) && attrs[0].getType().equals("[I")) success("MBeanAttributeInfo"); else failure("MBeanAttributeInfo: " + mbai); } int[] ints = (int[]) mbs.getAttribute(on, "Ints"); if (equal(ints, new int[] {1, 2, 3}, null)) success("getAttribute"); else failure("getAttribute: " + Arrays.toString(ints)); ExplicitMXBean proxy = JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class); int[] pints = proxy.getInts(); if (equal(pints, new int[] {1, 2, 3}, null)) success("getAttribute through proxy"); else failure("getAttribute through proxy: " + Arrays.toString(pints)); }
Example 18
Source File: MBeanCommand.java From arthas with Apache License 2.0 | 4 votes |
@Override public void run() { if (count >= getNumOfExecutions()) { // stop the timer timer.cancel(); timer.purge(); process.write("Process ends after " + getNumOfExecutions() + " time(s).\n"); process.end(); return; } try { MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objectNames = queryObjectNames(); TableElement table = createTable(); for (ObjectName objectName : objectNames) { MBeanInfo mBeanInfo = platformMBeanServer.getMBeanInfo(objectName); MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String attributeName = attribute.getName(); if (!getAttributeMatcher().matching(attributeName)) { continue; } String value; if (!attribute.isReadable()) { value = RenderUtil.render(new LabelElement("Unavailable").style(Decoration.bold_off.fg(Color.red))); } else { Object attributeObj = platformMBeanServer.getAttribute(objectName, attributeName); value = String.valueOf(attributeObj); } table.row(attributeName, value); } process.write(RenderUtil.render(table, process.width())); process.write("\n"); } } catch (Throwable e) { logger.warn("mbean error", e); } count++; process.times().incrementAndGet(); if (getInterval() <= 0) { stop(); process.end(); } }
Example 19
Source File: JmxWebHandler.java From simplejmx with ISC License | 4 votes |
private void displayAttributes(BufferedWriter writer, boolean textOnly, ObjectName objectName, MBeanInfo mbeanInfo) throws IOException { if (!textOnly) { writer.append("<table cellpadding='3' cellspacing='1' border='3'>\n"); writer.append("<tr><th colspan='3'> Attributes: </th></tr>\n"); writer.append("<tr><th> Name </th><th> Type </th><th> Value </th></tr>\n"); } for (MBeanAttributeInfo attribute : mbeanInfo.getAttributes()) { String name = attribute.getName(); Object value = null; if (attribute.isReadable()) { try { value = mbeanServer.getAttribute(objectName, name); } catch (Exception e) { value = "error getting value"; } } else { value = "not readable"; } String valueString = ClientUtils.valueToString(value); if (textOnly) { writer.append(name + (attribute.isWritable() ? "*" : "") + "=" + valueString + "\n"); continue; } writer.append("<tr><td title='" + makeHtmlSafe(attribute.getDescription()) + "'> " + name + " </td>"); writer.append("<td> " + ClientUtils.displayType(attribute.getType(), value) + " </td>"); if (attribute.isWritable()) { writer.append("\n<form action='/" + COMMAND_ASSIGN_ATTRIBUTE + "/" + makeHtmlSafe(objectName.toString()) + "/" + makeHtmlSafe(name) + "' name='" + makeHtmlSafe(name) + "'>\n"); writer.append("<td>"); writer.append("<input name='" + PARAM_ATTRIBUTE_VALUE + "' value='" + makeHtmlSafe(valueString) + "' />"); writer.append("<input type='submit' value='Set Value' />"); writer.append("</td>"); writer.append("</form>\n"); } else { writer.append("<td> " + ClientUtils.valueToString(value) + " </td>"); } writer.append("</tr>\n"); } if (!textOnly) { writer.append("</table>\n"); } }
Example 20
Source File: Server.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Get MBean attribute result info * @param name The bean name * @param attrInfo The attribute information * @return The data * @exception JMException Thrown if an error occurs */ public static AttrResultInfo getMBeanAttributeResultInfo(String name, MBeanAttributeInfo attrInfo) throws JMException { ClassLoader loader = SecurityActions.getThreadContextClassLoader(); MBeanServer server = getMBeanServer(); ObjectName objName = new ObjectName(name); String attrName = attrInfo.getName(); String attrType = attrInfo.getType(); Object value = null; Throwable throwable = null; if (attrInfo.isReadable()) { try { value = server.getAttribute(objName, attrName); } catch (Throwable t) { throwable = t; } } Class typeClass = null; try { typeClass = Classes.getPrimitiveTypeForName(attrType); if (typeClass == null) typeClass = loader.loadClass(attrType); } catch (ClassNotFoundException cnfe) { // Ignore } PropertyEditor editor = null; if (typeClass != null) editor = PropertyEditorManager.findEditor(typeClass); return new AttrResultInfo(attrName, editor, value, throwable); }