Yes, you can easily write a Java app to access MBeans within JBoss, and you 
don't need JDK 5 to do it.  Here is some simple code that prints out the 
attribute value of a particular mbean:

package foo.bar;
  | import java.util.Hashtable;
  | import javax.management.MBeanServerConnection;
  | import javax.management.ObjectName;
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | public class MBean {
  |     public static void main(String[] args) throws Exception {
  |         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");
  |         ObjectName name = new 
ObjectName("jboss.jca:name=ds/ProductDS,service=ManagedConnectionPool");
  |         Object val = mconn.getAttribute(name, "InUseConnectionCount");
  |         System.out.println(name + "\n\tInUseConnectionCount=" + val);
  |     }
  | }

Note that the MBeanServerConnection is accessed via JNDI, and not via a 
JMXServiceURL.  (My search for a way to use a JMXServiceURL never turned up any 
schemes that worked.)

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3948793#3948793

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3948793


_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to