• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to reuse the MBean (JMX)

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry...That really helps !!Thank you once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic