This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes How to reuse the MBean (JMX) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How to reuse the MBean (JMX)" Watch "How to reuse the MBean (JMX)" New topic
Author

How to reuse the MBean (JMX)

samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hello Ranchers,
Can anybody out here please tell me how to reuse one MBean inside the other MBean . Is there any way by means of which I can reuse all the features that I have given via MBean1 inside MBean2
Thanks in advance
Samir
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

I think you need to clarify more probably with some code examples.
What is that you need to "reuse"?
After all an MBean is just a java class and if you have an instance you can use it. If you do not have the instance you can still lookup from the MBean server and use it.
So, what is it that you wish to do?


apigee, a better way to API!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40


An MBean in a JMX server container has direct access to the server object -- unlike clients which generally has to connect via a JMX connector (or via JNDI). So, an MBean can call any other MBean in the container, in a fashion that is easier than a client calling the MBean.

But I agree with Nitesh... You should elaborate what you mean by "reuse".

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Thanks a lot Nitesh and Henry for the reply,
Well ...I have a MBean called as "ContextMonitor" out of the box and this is a MBean which is used so as to monitor the different aspects of the web server(Session,ServlerContext etc. ) . I want to access the ServletContext in my MBean for some monitoring stuff. So what I thought is if by some ways I can get the hold over ContextMonitor MBean in my MBean ,then I can access ServlerContext in my MBean. (ContextMonitor has a field called ServlerContext along with getter and setter) .
Along with this , can anyone of you please let me know along with some code snippest whether it is possible to monitor the number of different sessions which are getting created per user login through the JMX. I am using jconsole UI for monitoring stuff. What I need to monitor through JConsole is the number of users who are currently logged in. With each subsequent user login the attribute "userCount" should get incremented.
Any white paper ,link will be greatly appricated.
Thanks in advance
Samir

Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

samir ware wrote:So what I thought is if by some ways I can get the hold over ContextMonitor MBean in my MBean ,then I can access ServlerContext in my MBean. (ContextMonitor has a field called ServlerContext along with getter and setter) .


As told before there are two cases:
1) You are in the same JVM as the ContextMonitor bean. If you know the class that instantiates this bean, you can query the same class to get the bean instance.
2) If you know the MBean server that hosts the ContextMonitor bean then you can query the MBean as a client from the server.

Does this make it clear?

samir ware wrote: Along with this , can anyone of you please let me know along with some code snippest whether it is possible to monitor the number of different sessions which are getting created per user login through the JMX.


Please ask one question in one thread. You can start a new thread for this question.
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
2) If you know the MBean server that hosts the ContextMonitor bean then you can query the MBean as a client from the server.


Can you please let me know how to make this query ? That will be a great help
Thanks
Samir
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

samir ware wrote:
2) If you know the MBean server that hosts the ContextMonitor bean then you can query the MBean as a client from the server.


Can you please let me know how to make this query ? That will be a great help
Thanks
Samir


Well, there is no standard for this... actually, there is, you can use an RMI connector.... but different MBean servers have slightly different RMI connectors (more correctly, same connector, different protocol setup). Furthermore, many application servers don't have the RMI connector loaded by default -- instead you have to rely on JNDI to get to the MBean server, which again, is slightly different in each application server.

However, you said you wanted to access an MBean from your MBean. Will your MBean be in the same MBean server as this other MBean? If it is, then it will be really easy.... And standard (Guaranteed to work) .... Just have your MBean implement the MBeanRegistration interface. The MBean server object will be passed to you during preregistration, and with this server object, you should be able to get to this other MBean.

Henry
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Thanks Henry...That really helps !!Thank you once again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reuse the MBean (JMX)
 
Similar Threads
Servlet access to MBean in JBoss
Start, Stop EJBs from Client
How to reuse the MBean (JMX)
Using the scheduler
MBean service