File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes JMX in JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JMX in JBoss" Watch "JMX in JBoss" New topic

JMX in JBoss

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Hi, I want to write a piece of code that gets notified whenever any Topic/Queue is added in JBoss App Server at runtime .

What I have known so far is that , there is one MBean in JBoss ,you can create and destroy queues and topics at runtime through the DestinationManager MBean. DestinationManager provides createQueue and createTopic operations for this also . How would I proceed ?
If I want to connect to DestinationManager MBean what are the properties required for setting up the InitialContext ? also what will be the parameter for InitialContext.lookUp(parametreName) ?

I some one has something like this please suggest , it would be great if you have sample codes or docs .
Henry Wong

Joined: Sep 28, 2004
Posts: 20531

You can't connect to the MBean directly from JNDI. Instead you connect to the MBean Server Connector. This is pretty well documented in the JBoss site, but it is something like this...

Once you have the connector, you can get the MBean by it's object name, like so...

Of course, you have to know the particular domain names for the MBean that you want. There may also be a way to query by type -- not sure.

Hope this helps,

[EDIT: disabled smilies]
[ September 08, 2006: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Moving to our JBoss forum...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Thanks Henry .Your answer solved my query.I want share my piece of code
that I have written for test purpose .

package jmx;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

import javax.naming.Context;
import javax.naming.InitialContext;

public class FinalConnectAndInvoke
public static void main(String[] args)
* You can't connect to the MBean directly from JNDI.
* Instead you connect to the MBean Server Connector.
InitialContext ctx = null;

System.out.println(" *** Fetching JNDI Connector *** ");
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming rg.jnp.interfaces");

ctx = new InitialContext(env);
MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
String objectName = "";

// Just Testing whether a method can be invoked successfully
server.invoke(new ObjectName(objectName), "stop",null,null);
System.out.println("stop Method Invoked Successfully ");

// Invoking createQueue method to add a queue named NewQueueByAyan by invoking the
// createQueue method

Object[] param = new Object[1];
String[] signature = new String[1];
signature[0]= "java.lang.String";
server.invoke(new ObjectName(objectName), "createQueue",param,signature);

System.out.println("createQueue Method Invoked Successfully ");
catch(Exception e)
System.out.println("Exception Occurred ...");

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Now I want to do another thing . I want to know the all queues and topics
names programmatically . I have gone throgh the JBoss JMX console and studied
the MBeans like DestinationManager..etc . But I am not getting any methods that returna all the queue/topic name .Any clue ?

If I want to write my own MBean that will be return all the queue and topic names ,what will be the procedure ?

Regards ,
Ayan Dutta
I agree. Here's the link:
subject: JMX in JBoss
It's not a secret anymore!