You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve Cohen <sc...@javactivity.org> on 2008/09/08 22:44:08 UTC

Re: Need help with Tomcat MBean support - SOLVED

Finally figured out how to do what I wanted to do.

Turns out I had no need at all of creating an MBean in my client.  Duh!  
I never understood why I needed to do that but that is what the sample did.

All I needed to do was call the MBeanServerConnection.invoke() method 
with a suitable object name and other params to invoke the operation on 
the MBean I had ALREADY instantiated on my server. 

That's what you get for slavishly following example code instead of 
thinking.

By the way I found this out by staring at the Ant examples on 
http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html.  I finally 
realized that if Ant can invoke an operation, so could a non-Ant 
executable.  From there a simple peek at the jmx ant task source code 
showed me what I needed to do.  Voila!
 
Gotta love open source - once you figure out where to look.

Thank you to all who helped.



Steve Cohen wrote:
> I sent this in over the weekend and didn't get a response so let me 
> try this again a bit differently.
>
> The Sun JDK 5.0 JMX tutorial shows that it is possible and simple to 
> create JMX client and JMX server in separate JVMs and have them talk 
> to each other.
>
> The first article cited by Mr. Hall shows that it is possible and 
> simple to create a JMX server running inside Tomcat and talk to it 
> through tools such as MC4J and JManage.
>
> I need to combine the Server side approach recommended by the article 
> (JMX server within Tomcat webapp) with the Client side approach 
> recommended by Sun in their tutorial.
> So far my client-side app can connect to the MBean server inside of 
> Tomcat and talk to it but it fails to create the MBean needed to 
> interact with the server because of ClassLoader issues.
>
> Questions: 1. Is this even possible?  It would seem to be so since 
> MC4J and JManage know how to do it.
> 2. If so, how do I surmount these ClassLoader issues?
>
> Thank you very much.
>
> Steve Cohen wrote:
>> Okay using approach of first article.  The MBean server is correctly 
>> initialized and everything on the server side looks good.
>>
>> Now we come to the client side.  The first article assumes you are 
>> just going to connect using a tool such as MC4J or JManage 
>> (monitoring tools).
>>
>> That is not my use case.  I want to write a command-line client that 
>> can talk to the MBean (which is inside of Tomcat) and invoke an 
>> operation on the MBean.
>>
>> I use the Client.java sample from the Sun tutorial as a starting point.
>>
>> I am able to connect to the server, and get a list of MBeans, but I 
>> fail when trying to call createMBean().  I am using the simple 
>> two-parameter version of createMBean() and it always fails with
>>
>> javax.management.ReflectionException: The MBean class could not be 
>> loaded by the default loader repository
>>
>> It seems pretty clear that my client needs to use one of the other 
>> versions of createMBean(), one that specifies some other Class Loader 
>> but I have no clue what I should be using for that.
>>
>>
>> H. Hall wrote:
>>> Steve Cohen wrote:
>>>> Let me ask my question a little more directly:
>>>>
>>>> Does the presence of a descriptor cause instantiation of an 
>>>> instance of an MBean
>>>> or do I have to write code to create a server-side instance of my 
>>>> MBean and if so, where should this code reside
>>>> or is there some configuration artifact that causes this 
>>>> instantiation to happen?
>>>>
>>>>
>>>
>>> Why don't you take a look at these two articles:
>>> http://today.java.net/pub/a/today/2005/11/15/using-jmx-to-manage-web-applications.html?page=1 
>>>
>>>
>>> http://marxsoftware.blogspot.com/2008/07/jmx-model-mbeans-with-apache-commons.html 
>>>
>>>
>>> If you use the NetBeans IDE you might be interested in the JMX 
>>> plugin for NB. Here is a link to a tutorial "Getting Started with 
>>> JMX Monitoring in NetBeans IDE 6.0"
>>>
>>> http://www.netbeans.org/kb/60/java/jmx-getstart.html
>>>
>>> cheers,
>>> HH
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> 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
>
>
>


---------------------------------------------------------------------
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