Create Object of "ObjectName" Class by giving only Domain Name.

Hie,

I want to create Object of "ObjectName" class without specifying its key value properties, but i want to only specify the domain name.

For eg:

ObjectName on=new ObjectName("jboss.ws4ee:*");herejboss.ws4ee is thedomain name and after colon(:) will come the key value properties.. i dont want to specify that because i want the list of all mbeans coming under this domain i.e. jboss.ws4ee

So anyone can plzzz help me..

Regards.

[492 byte] By [Jay.Jambaa] at [2007-11-27 5:24:54]
# 1

If I understand you correctly, you want to get a list of MBeans (or ObjectNames) from an MBean server belonging to the "jboss.ws4ee" domain?

You can use the query functionality on the MBeanServer to acheive this:

MBeanServer server = ...

ObjectName query = new ObjectName("jboss.ws4ee:*");

//note the *. It will match any property set.

Set<ObjectName> mbeanNames = server.queryNames(query, null);

Hope that helps,

Eske

esorta at 2007-7-12 14:44:37 > top of Java-index,Core,Monitoring & Management...
# 2
Its not letting me to create the Object of ObjectName..i.e. if i write like:ObjectName on=new ObjectName("jboss.ws4ee:*");its giving me an error called "javax.management.InstanceNotFoundException: jboss.ws4ee:* is not registered."
Jay.Jambaa at 2007-7-12 14:44:37 > top of Java-index,Core,Monitoring & Management...
# 3

Hi,

What were you trying to do with that name?

ObjectName on=new ObjectName("jboss.ws4ee:*");

You cannot create an MBean with such an ObjectName. You can only

use it as first argument to queryNames() and queryMBeans();

If you want to get the attributes of all jboss MBeans then you will need to

do something like that:

final ObjectName pattern=new ObjectName("jboss.ws4ee:*");

for (ObjectName o : server.queryNames(pattern,null)) {

System.out.println("MBean: " + o);

for (MBeanAttributeInfo info : server.getMBeanInfo(o).getAttributes()) {

final String attrname = info.getName();

System.out.println("\t"+attrname+"="+server.getAttribute(o,attrname));

}

}

(disclaimer: this code was eyed-compiled)

hope this helps,

-- daniel

JMX, SNMP, Java, etc...

http://blogs.sun.com/jmxetc

dfuchsa at 2007-7-12 14:44:37 > top of Java-index,Core,Monitoring & Management...