You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by lightbulb432 <ve...@hotmail.com> on 2007/08/23 19:10:04 UTC

Re: Use JMX to manage applications

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");

OR

MBeanServer server = (MBeanServer)
MBeanServerFactory.findMBeanServer(null).get(0);
AttributeList list = server.getAttributes(new
ObjectName("Application:Name=Server,Type=Server"),"myAttribute");

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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Use JMX to manage applications

Posted by Vamsavardhana Reddy <c1...@gmail.com>.
On 8/23/07, lightbulb432 <ve...@hotmail.com> 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>