On 8/23/07, lightbulb432 <[EMAIL PROTECTED]> wrote: > > > What is the preferred API for accessing MBeans from within servlets or > JSPs? > > MBeanServerConnection jmxServerConnection = JMXConnectorFactory.connect > (new > JMXServiceURL(urlForJMX),null).getMBeanServerConnection(); > jmxServerConnection.getAttribute(new > ObjectName("Application:Name=Server,Type=Server"),"myAttribute");
This code can connect to an MBeanServer which need not be in the same JVM as your Servlet and you may need to provide authorization credentials to get connected. OR > > MBeanServer server = (MBeanServer) > MBeanServerFactory.findMBeanServer(null).get(0); > AttributeList list = server.getAttributes(new > ObjectName("Application:Name=Server,Type=Server"),"myAttribute"); This code looks up MBeanServers in the same JVM as your Servlet. They both have roughly the same amount of code and do the same thing, so I'm > wondering which is the preferred way. Unfortunately, you can't really > abstract away the mechanism of getting the MBeanServer because one uses a > MBeanServer while the other way uses the MBeanServerConnection object from > which to perform other methods. > > The only tradeoff I can see is that the first way requires knowing the JMX > connection URL which may need to be changed if, for example, the JXM port > number is changed. However, the second way may return multiple > MBeanServers, > right? > > In the second way, would you ever expect a List with more than one > MBeanServer to be returned? If so, how would that happen, and how would > your > code deal with it? > > Thanks. > > > > lightbulb432 wrote: > > > > How, from a web application deployed to Tomcat, can you customize the > > behavior of your web application based on attributes specified in an > > MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html > > talks a lot about Ant tasks, but that's not really what I'm looking to > do. > > > > How can you get programmatic access to MBeans? And how do you deploy > > MBeans to Tomcat? > > > > I'm pretty confused here...hopefully someone can clarify. Thanks. > > > > -- > View this message in context: > http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a12297804 > Sent from the Tomcat - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >