-
1. Re: Accessing Mbean
kconner Dec 12, 2008 5:14 AM (in response to neha2911)The beans are available through the normal mechanisms although they have been reworked recently.
What have you tried and what do you want to achieve? -
2. Re: Accessing Mbean
neha2911 Dec 12, 2008 6:04 AM (in response to neha2911)I am novice in this area .In the JMX console we have various properties for each queue deployed on the server . I want to access the message count property of a particular queue.For this i should be able to interact with Mbaen and extract this particular property. How to do the same? What all API is required ?Could you provide me with a sample code ?
-
3. Re: Accessing Mbean
kconner Dec 12, 2008 8:57 AM (in response to neha2911)Interact in what way though?
If this is within the same VM then you just need to lookup the MBeanServer and then query the attribute.
MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
public Object getAttribute(ObjectName name, String attribute) -
4. Re: Accessing Mbean
neha2911 Dec 15, 2008 4:39 AM (in response to neha2911)I have jboss-soa-p.4.2.0 on my local machine . I want to write java code so that I can obtain the value of MessageCount property of 'helloworlrd' queue that is deployed on the jboss-as that I obtain in my jmx console.
-
5. Re: Accessing Mbean
neha2911 Dec 15, 2008 4:43 AM (in response to neha2911)
MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
public Object getAttribute(ObjectName name, String attribute)
I tried it but i get following errorException in thread "main" java.lang.IllegalStateException: No 'jboss' MBeanServer found! at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:122) at MbeanAccessor.main(MbeanAccessor.java:9)
My line 9 is//Line 9 : MBeanServer mbeanServer = MBeanServerLocator.locateJBoss(); //Line 10 : System.out.println(mbeanServer.getMBeanCount());
-
6. Re: Accessing Mbean
neha2911 Dec 17, 2008 11:42 PM (in response to neha2911)Hi ,
I got the solution .
The code to access a Mbean property is :InitialContext context = new InitialContext(); MBeanServerConnection mbeanServer = (MBeanServerConnection)context.lookup ( "jmx/invoker/RMIAdaptor" ); ObjectName queue = new ObjectName ("jboss.messaging.destination:service=Queue,name=testQueue" ); Integer messageCount = (Integer)server.getAttribute ( queue, "MessageCount" ); System.out.println ( messageCount );
Apart from this one has to set following properties. You can pass them on the command line ("-Djava.naming.provider.url=jnp://localhost:1099"), put them in a jndi.properties file in your classpath, or put them in a Hashtable and pass it when creating the InitialContext.java.naming.factory.initial=org.jboss.security.jndi.JndiLoginInitialContextFactory java.naming.provider.url=jnp://localhost:1099 java.naming.security.principal=admin java.naming.security.credentials=admin
-
7. Re: Accessing Mbean
kconner Dec 19, 2008 7:06 AM (in response to neha2911)Sorry for the delay in getting back to you.
Yes, the code you have is correct for accessing the MBeanServer from outside the VM. The MBeanServerLocator.locateJBoss() invocation is from within the same VM.
Kev