JMX and JBOSS quetion

i can get the MBean's name attribute name type descrep in JBOSS but i cannot get the Value of MBean's Attribute. Who can tell me how to get it.....

[156 byte] By [Danza] at [2007-11-27 10:19:30]
# 1

my code:

import java.util.Iterator;

import java.util.Properties;

import java.util.Set;

import javax.management.Attribute;

import javax.management.MBeanAttributeInfo;

import javax.management.MBeanInfo;

import javax.management.MBeanOperationInfo;

import javax.management.MBeanParameterInfo;

import javax.management.ObjectInstance;

import javax.management.ObjectName;

import javax.management.modelmbean.ModelMBean;

import javax.naming.InitialContext;

import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

import org.jboss.management.j2ee.MBean;

public class TestJMX {

public static void main(String[] args) throws Exception {

//Get RMIAdaptor Object

Properties pro = new Properties();

pro.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

pro.setProperty("java.naming.provider.url", "jnp://localhost:1099");

pro.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

InitialContext ic = new InitialContext(pro);

RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");

// Get the MBeanInfo for the JNDIView MBean

ObjectName name = new ObjectName("jboss:service=JNDIView");

MBeanInfo info = server.getMBeanInfo(name);

System.out.println("JNDIView Class: " + info.getClassName());

MBeanOperationInfo[] opInfo = info.getOperations();

System.out.println("JNDIView Operations: ");

Set mbSet = server.queryMBeans(null, null); //

for (Iterator it = mbSet.iterator(); it.hasNext();) {

ObjectInstance oi = (ObjectInstance) it.next();

MBeanInfo mbeaninfo = server.getMBeanInfo(oi.getObjectName());

System.out.println(oi.getObjectName() + "-MBeanName" );

System.out.println(" Class: " + mbeaninfo.getClassName());

for(int i = 0; i < mbeaninfo.getAttributes().length; i++){

System.out.println(" Attriber NameF" + mbeaninfo.getAttributes().getName());

System.out.println(" Attriber TypeF" + mbeaninfo.getAttributes().getType());

System.out.println(" Attriber DescriptionF" + mbeaninfo.getAttributes().getDescription());

//System.out.println(" AttriberF" + ((Attribute) mbeaninfo.getAttributes()).getValue());

}

for(int i = 0; i < mbeaninfo.getOperations().length; i++)

System.out.println(" OperationF" + mbeaninfo.getOperations().getName());

//+ value);

}

System.out.println("MBean count = " + server.getMBeanCount());

}

}

Danza at 2007-7-28 16:58:04 > top of Java-index,Core,Monitoring & Management...
# 2

Hi Danz,

The MBeanInfo is just a description of the attributes & methods that the MBean

exposes. It is what we call the 'metadata'.

To get the attribute value, or invoke an operation, you will have to invoke the MBean

itself, either through the MBeanServerConnection or through a proxy.

For getting an attribute value you would need to do (from within your loop):

server.getAttribute(oi.getObjectName(), mbeaninfo.getAttributes()[i].getName());

I also noticed that you forgot the '' in your loop over the MBean attributes - the code

as you showed it will surely not compile.

I have written a short introduction to JMX which contains a bunch of links, including

JMX tutorials:

http://blogs.sun.com/jmxetc/entry/what_is_jmx

In the following post you will also find a snippet of code that prints all the attributes

of MBeans (just call the method displayAll(new ObjectName("*:*")); )

http://blogs.sun.com/jmxetc/entry/a_small_program_that_prints

You might also find other useful JMX related information from my blog, see:

http://blogs.sun.com/jmxetc/page/Toc

Hope this helps,

-- daniel

JMX, SNMP, Java, etc...

http://blogs.sun.com/jmxetc

Message was edited by: dfuchs

Bad Cut&Paste, sorry :-(

dfuchsa at 2007-7-28 16:58:04 > top of Java-index,Core,Monitoring & Management...
# 3

HI! daniel:

At the first. Thanks for your help!

Can i make friend with you ?How to keep touch with you ? OICQ or MSN?

Danz

Danza at 2007-7-28 16:58:04 > top of Java-index,Core,Monitoring & Management...