Hi,
I want to get the reference of the MBeanServer of my running JBOSS from my standalone program.
And on the MBeanServer instance I want to invoke getVersionName() of the MBean Server.
But after getting the Server Object Instance Class I can not type case to the org.jboss.system.server.ServerImpl.
Code is given below : Can My Approach is OK ??
Hashtable env = new Hashtable();
String factory = "org.jnp.interfaces.NamingContextFactory";
env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
String url1 = "jnp://localhost:1099";
env.put(Context.PROVIDER_URL, url1);
Context ctx = new InitialContext(env);
MBeanServerConnection mconn = (MBeanServerConnection)ctx.lookup("jmx/invoker/RMIAdaptor");
if(null!=mconn){
ObjectName serverObj = new ObjectName("jboss.system:type=Server");
System.out.println("Version = " + (String)mconn.getAttribute(serverObj, new String("Version")));
ObjectInstance serverObjInst = mconn.getObjectInstance(serverObj);
System.out.println(serverObj + "\n\t Server Object Instance Class Name =" + serverObjInst.getClassName());
if(mconn.isInstanceOf(serverObj,"org.jboss.system.server.ServerImpl")){
System.out.println("-----------------------------");
org.jboss.system.server.ServerImpl serverImpl = (org.jboss.system.server.ServerImpl)mconn;
System.out.println("@@ --- MBean Server Version name = "+serverImpl.getVersionName());
}