Accessing JBoss 7 MBeans in a deployed application
golovnin May 31, 2012 9:36 AMHi all,
I would like to read properties of the MBean "jboss.as:socket-binding-group=standard-sockets,socket-binding=http" in a ServletContextListener. This works fine in JBoss 7.1.1. But in the latest snapshot of JBoss 7 I get following error:
15:18:19,017 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/test]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class com.acme.MyServletContextListener: java.lang.Error: javax.management.InstanceNotFoundException: JBAS011340: No MBean found with name jboss.as:socket-binding-group=standard-sockets,socket-binding=http
at com.acme.MyServletContextListener.contextInitialized(MyServletContextListener.java:75) [acme.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.16.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.16.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.2.0.Alpha1-SNAPSHOT.jar:7.2.0.Alpha1-SNAPSHOT]
The code used to access the MBean looks like this:
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName http =
new ObjectName("jboss.as:socket-binding-group=standard" +
"-sockets,socket-binding=http");
jbossWebHost =
(String) mBeanServer.getAttribute(http, "boundAddress");
jbossWebPort = (Integer) mBeanServer.getAttribute(http, "boundPort");
} catch (Exception e) {
throw new Error(e);
}
I can find the MBean using JConsole after JBoss 7.2.0.Alpha1-SNAPSHOT is started and the application is deployed. But if I suspend the JBoss server in the first line of the above snippet and look into JConsole, I can not find the MBean.
Why do you changed the behavior? What is the new way to access MBeans like "jboss.as:socket-binding-group=standard-sockets,socket-binding=http" during application start up.
Alternative solution would be to read/parse the JBoss configuration file manually. But I hate this idea.
Best regards,
Andrej Golovnin