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.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
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;
try
{
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 = "jboss.mq:service=DestinationManager";
// 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];
param[0]="NewQueueByAyan";
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 ...");
e.printStackTrace();
}
}
}
Regards,
Ayan